少数点以下のゆらぎ・・・

by keno42 forked from Math.random()*10+1 で整数はでるのか? (diff: 28)
♥0 | Line 43 | Modified 2009-12-22 23:03:40 | MIT License
play

ActionScript3 source code

/**
 * Copyright keno42 ( http://wonderfl.net/user/keno42 )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/FNB7
 */

// forked from bkzen's Math.random()*10+1 で整数はでるのか?
package  
{
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.text.TextField;
	
	public class TestAS extends Sprite
	{
		private var txt: TextField;
		private var totalCount: uint = 0;
		private var overCount: uint = 0;
		
		public function TestAS() 
		{
			if (stage) init();
			else addEventListener(Event.ADDED_TO_STAGE, init);
		}
		
		private function init(e: Event = null): void 
		{
			removeEventListener(Event.ADDED_TO_STAGE, init);
			//
			addChild(txt = new TextField());
			txt.width = stage.stageWidth;
			txt.height = stage.stageHeight;
                        var i:int, j:Number, temp:Number, temp2:Number, temp3:int;
                        for( i = 0; i < 10; i++ ){
                            temp = i / 10.0;
                            temp2 = temp * 10.0;
                            temp3 = temp2;
    			    txt.appendText(temp2+ " == "+temp3+": " + (temp2 == temp3) + "\n");
                        }
                        
                        for( i = 0; i < 10; i++ ){
                            temp = 0.1 * i;
                            temp2 = temp * 10.0;
                            temp3 = temp2;
    			    txt.appendText(temp2+ " == "+temp3+": " + (temp2 == temp3) + "\n");
                        }
                        
                        for( i = 0; i < 10; i++ ){
                            temp = 0.1 * i;
                            temp2 = temp * 10 + 1.0;
                            temp3 = temp2;
    			    txt.appendText(temp2+ " == "+temp3+": " + (temp2 == temp3) + "\n");
                        }
		}
		
	}

}