diff options
author | alon@honor <none@none> | 2010-09-22 21:15:26 -0700 |
---|---|---|
committer | alon@honor <none@none> | 2010-09-22 21:15:26 -0700 |
commit | 17f4f4918767c3159f55c78f3c443067f0297b70 (patch) | |
tree | 7c2499ba30c0a1a37329e74675e3d39ddad6bccc /src/parseTools.js | |
parent | 283667603bcd9641b7b4183d881c5f311243eb14 (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.js | 21 |
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) { |