summaryrefslogtreecommitdiff
path: root/js/src
diff options
context:
space:
mode:
authorJose <jose@zeroc.com>2015-03-05 17:40:59 +0100
committerJose <jose@zeroc.com>2015-03-05 17:40:59 +0100
commitbe6ef787a0ce3a19c2777307b34840be8536ebaf (patch)
tree0dcbd1f0d876087f1654057d7689899c17e94920 /js/src
parent- Added ice36.rb. (diff)
downloadice-be6ef787a0ce3a19c2777307b34840be8536ebaf.tar.bz2
ice-be6ef787a0ce3a19c2777307b34840be8536ebaf.tar.xz
ice-be6ef787a0ce3a19c2777307b34840be8536ebaf.zip
Fixed Ice.Long.toNumber to handle negative numbers added number test.
Diffstat (limited to 'js/src')
-rw-r--r--js/src/Ice/Long.js36
1 files changed, 24 insertions, 12 deletions
diff --git a/js/src/Ice/Long.js b/js/src/Ice/Long.js
index 8d80641760f..14b6eba7e07 100644
--- a/js/src/Ice/Long.js
+++ b/js/src/Ice/Long.js
@@ -17,6 +17,15 @@ var Ice = require("../Ice/Class").Ice;
var Long = Ice.Class({
__init__: function(high, low)
{
+ if(low < 0 || low > Long.MAX_UINT32)
+ {
+ throw new RangeError("Low word must be between 0 and 0xFFFFFFFF");
+ }
+ if(high < 0 || high > Long.MAX_UINT32)
+ {
+ throw new RangeError("High word must be between 0 and 0xFFFFFFFF");
+ }
+
this.high = high;
this.low = low;
},
@@ -42,24 +51,22 @@ var Long = Ice.Class({
},
toNumber: function()
{
+
if((this.high & Long.SIGN_MASK) !== 0)
{
- var low = ~this.low;
- var high = ~this.high;
- if(low < 0xFFFFFFFF)
+ if(this.high === Long.MAX_UINT32 && this.low !== 0)
{
- low += 1;
+ return -(~this.low + 1);
}
- else
+
+ var high = ~this.high + 1;
+
+ if(high > Long.HIGH_MAX)
{
- low = 0;
- high += 1;
- if(high > Long.HIGH_MAX)
- {
- return Number.NEGATIVE_INFINITY;
- }
+ return Number.NEGATIVE_INFINITY;
}
- return -1 * (high * Long.HIGH_MASK) + low;
+
+ return -1 * (high * Long.HIGH_MASK) + this.low;
}
else
{
@@ -73,6 +80,11 @@ var Long = Ice.Class({
});
//
+// 2^32
+//
+Long.MAX_UINT32 = 0xFFFFFFFF;
+
+//
// (high & SIGN_MASK) != 0 denotes a negative number;
// that is, the most significant bit is set.
//