|
@@ -159,7 +159,7 @@ class Input {
|
|
|
var sig = ((bytes[1] & 0x7F) << 16) | (bytes[2] << 8) | bytes[3];
|
|
|
if (sig == 0 && exp == -127)
|
|
|
return 0.0;
|
|
|
- return sign*(1 + Math.pow(2, -23)*sig)*Math.pow(2, exp);
|
|
|
+ return sign*(1 + Math.pow(2, -23)*sig) * Math.pow(2, exp);
|
|
|
#end
|
|
|
}
|
|
|
|
|
@@ -171,9 +171,28 @@ class Input {
|
|
|
#elseif php
|
|
|
var a = untyped __call__('unpack', 'd', readString(8));
|
|
|
return a[1];
|
|
|
- #else
|
|
|
- throw "Not implemented";
|
|
|
+ #elseif (flash || js)
|
|
|
+ var bytes = [];
|
|
|
+ bytes.push(readByte());
|
|
|
+ bytes.push(readByte());
|
|
|
+ bytes.push(readByte());
|
|
|
+ bytes.push(readByte());
|
|
|
+ bytes.push(readByte());
|
|
|
+ bytes.push(readByte());
|
|
|
+ bytes.push(readByte());
|
|
|
+ bytes.push(readByte());
|
|
|
+ if (bigEndian)
|
|
|
+ bytes.reverse();
|
|
|
+
|
|
|
+ var sign = 1 - ((bytes[0] >> 7) << 1); // sign = bit 0
|
|
|
+ var exp = (((bytes[0] << 4) & 0x7FF) | (bytes[1] >> 4)) - 1023; // exponent = bits 1..11
|
|
|
+ var sig = getDoubleSig(bytes);
|
|
|
+ if (sig == 0 && exp == -1023)
|
|
|
return 0.0;
|
|
|
+ return sign * (1.0 + Math.pow(2, -52) * sig) * Math.pow(2, exp);
|
|
|
+ #else
|
|
|
+ throw "not implemented";
|
|
|
+ return 0.0;
|
|
|
#end
|
|
|
}
|
|
|
|
|
@@ -278,4 +297,25 @@ class Input {
|
|
|
static var _double_of_bytes = cpp.Lib.load("std","double_of_bytes",2);
|
|
|
#end
|
|
|
|
|
|
-}
|
|
|
+#if flash
|
|
|
+ function getDoubleSig(bytes:Array<Int>) : Int
|
|
|
+ {
|
|
|
+ return untyped
|
|
|
+ {
|
|
|
+ Std.int(((((bytes[1]&0xF) << 16) | (bytes[2] << 8) | bytes[3] ) * Math.pow(2, 32))) +
|
|
|
+ Std.int(((bytes[4] >> 7) * Math.pow(2,31))) +
|
|
|
+ Std.int((((bytes[4]&0x7F) << 24) | (bytes[5] << 16) | (bytes[6] << 8) | bytes[7]));
|
|
|
+ };
|
|
|
+ }
|
|
|
+#elseif js
|
|
|
+ function getDoubleSig(bytes:Array<Int>) : Int
|
|
|
+ {
|
|
|
+ return untyped
|
|
|
+ {
|
|
|
+ Std.parseInt(((((bytes[1]&0xF) << 16) | (bytes[2] << 8) | bytes[3] ) * Math.pow(2, 32)).toString()) +
|
|
|
+ Std.parseInt(((bytes[4] >> 7) * Math.pow(2,31)).toString()) +
|
|
|
+ Std.parseInt((((bytes[4]&0x7F) << 24) | (bytes[5] << 16) | (bytes[6] << 8) | bytes[7]).toString());
|
|
|
+ };
|
|
|
+ }
|
|
|
+#end
|
|
|
+}
|