aboutsummaryrefslogtreecommitdiff
path: root/src/parseTools.js
diff options
context:
space:
mode:
authoralon@honor <none@none>2010-09-22 21:15:26 -0700
committeralon@honor <none@none>2010-09-22 21:15:26 -0700
commit17f4f4918767c3159f55c78f3c443067f0297b70 (patch)
tree7c2499ba30c0a1a37329e74675e3d39ddad6bccc /src/parseTools.js
parent283667603bcd9641b7b4183d881c5f311243eb14 (diff)
handle a few minor parsing issues (negative IEEE doubles, []s in constants, aliases - ignored)
Diffstat (limited to 'src/parseTools.js')
-rw-r--r--src/parseTools.js21
1 files changed, 18 insertions, 3 deletions
diff --git a/src/parseTools.js b/src/parseTools.js
index 2a689889..3221a829 100644
--- a/src/parseTools.js
+++ b/src/parseTools.js
@@ -324,11 +324,26 @@ function _HexToInt(stringy) {
return ret;
}
+function _IntToHex(x) {
+ assert(x >= 0 && x <= 15);
+ if (x <= 9) {
+ return String.fromCharCode('0'.charCodeAt(0) + x);
+ } else {
+ return String.fromCharCode('A'.charCodeAt(0) + x - 10);
+ }
+}
+
function IEEEUnHex(stringy) {
- var a = _HexToInt(stringy.substr(2, 8));
- var b = _HexToInt(stringy.substr(10));
+ stringy = stringy.substr(2); // '0x';
+ var top = _HexToInt(stringy[0]);
+ var neg = !!(top & 8);
+ if (neg) {
+ stringy = _IntToHex(top & ~8) + stringy.substr(1);
+ }
+ var a = _HexToInt(stringy.substr(0, 8));
+ var b = _HexToInt(stringy.substr(8));
var e = (a >> ((52 - 32) & 0x7ff)) - 1023;
- return ((((a & 0xfffff | 0x100000) * 1.0) / Math.pow(2,52-32)) * Math.pow(2, e)) + (((b * 1.0) / Math.pow(2, 52)) * Math.pow(2, e));
+ return (((((a & 0xfffff | 0x100000) * 1.0) / Math.pow(2,52-32)) * Math.pow(2, e)) + (((b * 1.0) / Math.pow(2, 52)) * Math.pow(2, e)) * (neg ? -1 : 1)).toString();
}
function parseNumerical(value, type) {