丸め誤差

by mtok forked from flash on 2009-11-27 (diff: 17)
♥0 | Line 34 | Modified 2009-11-28 20:01:59 | MIT License
play

ActionScript3 source code

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

<?xml version="1.0" encoding="utf-8"?>
<!-- forked from mtok's flash on 2009-11-27 -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" applicationComplete="appCompHandler()">
    <mx:Script>
    <![CDATA[
    import mx.events.FlexEvent;
    private function appCompHandler():void{
        println("1.01 - 1 = " + (1.01 - 1.0));
        
        //引いてから足してみる。
        println("(1.01 - 1) + 1 = " + ((1.01 - 1.0) + 1));
        
        //いったん変数に入れてみる。
        var n:Number = 1.01 - 1;
        println("n = 1.0.1 - 1 = " + n);
        n = n + 1;
        println("n + 1 = " + n);
    }
    
    private function print(str:String):void{
        taOutput.text = taOutput.text.concat(str);    
    }
    private function println(str:String):void{
        print(str);
        print("\n");    
    }
    
    //removeChildだと名前が被る。
    private function deleteChild(node:XML):XML{
        var p:XML;
        
        if(node != null){
            if( (p = node.parent()) ){
                delete p.children()[node.childIndex()];
            }
        }
        return node;
    }
    ]]>
    </mx:Script>
    <mx:TextArea width="100%" height="100%" id="taOutput" ></mx:TextArea>
</mx:Application>

Forked