In case Flash no longer exists; a copy of this site is included in the Flashpoint archive's "ultimate" collection.

Dead Code Preservation :: Archived AS3 works from wonderfl.net

What is the difference between “0” and “-0” ??

ByteArrayにwriteFloatした 0 と -0 の内容が違う値になるのはなんで??

Flashは内部的に0と-0と符号ビットが違う2種類のゼロを扱ってるってこと?
Get Adobe Flash player
by kjkmr 17 Sep 2012

    Talk

    kjkmr at 17 Sep 2012 22:32
    浮動小数点数の一般的な仕様らしい。。 http://ja.wikipedia.org/wiki/%e2%88%920
    Embed
/**
 * Copyright kjkmr ( http://wonderfl.net/user/kjkmr )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/qv2a
 */

package {
    import flash.display.Sprite;
    import flash.text.TextField;
    import flash.utils.ByteArray;
    public class FlashTest extends Sprite {
        public function FlashTest() {
            // write as3 code here..
            var logField:TextField = new TextField();
            logField.width = 300;
            logField.height = 300;
            addChild( logField );
            
            var buffer1:ByteArray = new ByteArray();
            buffer1.writeFloat( 0 );
            buffer1.position = 0;
            logField.text += "buffer1: "+buffer1.readInt()+" (readInt) \n";
            buffer1.position = 0;
            logField.text += "buffer1: "+buffer1.readFloat()+" (readFloat)\n\n";
            
            var buffer2:ByteArray = new ByteArray();
            buffer2.writeFloat( -0 );
            buffer2.position = 0;
            logField.text += "buffer2: "+buffer2.readInt()+" (readInt) \n";
            buffer2.position = 0;
            logField.text += "buffer2: "+buffer2.readFloat()+" (readFloat)\n";
        }
    }
}