What is the difference between “0” and “-0” ??
ByteArrayにwriteFloatした 0 と -0 の内容が違う値になるのはなんで??
Flashは内部的に0と-0と符号ビットが違う2種類のゼロを扱ってるってこと?
/**
* 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";
}
}
}