Chromium Code Reviews| Index: pkg/fixnum/lib/src/int64.dart |
| diff --git a/pkg/fixnum/lib/src/int64.dart b/pkg/fixnum/lib/src/int64.dart |
| index 81607de9b37a26316efefabbe4c1fe2878bd2404..c754b96cc8fe2cf5698a5f9911db0244f6e1ee86 100644 |
| --- a/pkg/fixnum/lib/src/int64.dart |
| +++ b/pkg/fixnum/lib/src/int64.dart |
| @@ -240,22 +240,24 @@ class int64 implements intx { |
| _h = (top >> 12) & _MASK_2; |
| } |
| - int64 _promote(other) { |
| - if (other == null) { |
| - throw new ArgumentError(null); |
| - } else if (other is intx) { |
| - other = other.toInt64(); |
| - } else if (other is int) { |
| - other = new int64.fromInt(other); |
| - } |
| - if (other is !int64) { |
| - throw new Exception("Can't promote $other to int64"); |
| - } |
| - return other; |
| + // Returns the [int64] representation of the specified value or null for |
| + // incompatible types. |
| + int64 _promote(val) { |
|
justinfagnani
2013/07/26 23:44:40
Same as the int32 comment here, all but == throws
Chris Bracken
2013/07/27 01:07:11
Done.
|
| + if (val is int64) { |
| + return val; |
| + } else if (val is int) { |
| + return new int64.fromInt(val); |
| + } else if (val is int32) { |
| + return val.toInt64(); |
| + } |
| + return null; |
| } |
| int64 operator +(other) { |
| int64 o = _promote(other); |
| + if (o == null) { |
| + throw new ArgumentError(other); |
| + } |
| int sum0 = _l + o._l; |
| int sum1 = _m + o._m + _shiftRight(sum0, _BITS); |
| int sum2 = _h + o._h + _shiftRight(sum1, _BITS); |
| @@ -266,7 +268,9 @@ class int64 implements intx { |
| int64 operator -(other) { |
| int64 o = _promote(other); |
| - |
| + if (o == null) { |
| + throw new ArgumentError(other); |
| + } |
| int sum0 = _l - o._l; |
| int sum1 = _m - o._m + _shiftRight(sum0, _BITS); |
| int sum2 = _h - o._h + _shiftRight(sum1, _BITS); |
| @@ -286,6 +290,9 @@ class int64 implements intx { |
| int64 operator *(other) { |
| int64 o = _promote(other); |
| + if (o == null) { |
| + throw new ArgumentError(other); |
| + } |
| // Grab 13-bit chunks. |
| int a0 = _l & 0x1fff; |
| int a1 = (_l >> 13) | ((_m & 0xf) << 9); |
| @@ -375,6 +382,9 @@ class int64 implements intx { |
| return ZERO; |
| } |
| int64 o = _promote(other).abs(); |
| + if (o == null) { |
| + throw new ArgumentError(other); |
| + } |
| _divMod(this, o, true); |
| return _remainder < 0 ? (_remainder + o) : _remainder; |
| } |
| @@ -387,12 +397,18 @@ class int64 implements intx { |
| throw new IntegerDivisionByZeroException(); |
| } |
| int64 o = _promote(other).abs(); |
| + if (o == null) { |
| + throw new ArgumentError(other); |
| + } |
| _divMod(this, o, true); |
| return _remainder; |
| } |
| int64 operator &(other) { |
| int64 o = _promote(other); |
| + if (o == null) { |
| + throw new ArgumentError(other); |
| + } |
| int a0 = _l & o._l; |
| int a1 = _m & o._m; |
| int a2 = _h & o._h; |
| @@ -401,6 +417,9 @@ class int64 implements intx { |
| int64 operator |(other) { |
| int64 o = _promote(other); |
| + if (o == null) { |
| + throw new ArgumentError(other); |
| + } |
| int a0 = _l | o._l; |
| int a1 = _m | o._m; |
| int a2 = _h | o._h; |
| @@ -409,6 +428,9 @@ class int64 implements intx { |
| int64 operator ^(other) { |
| int64 o = _promote(other); |
| + if (o == null) { |
| + throw new ArgumentError(other); |
| + } |
| int a0 = _l ^ o._l; |
| int a1 = _m ^ o._m; |
| int a2 = _h ^ o._h; |
| @@ -515,15 +537,18 @@ class int64 implements intx { |
| * given object. The argument may be an [int] or an [intx]. |
| */ |
| bool operator ==(other) { |
| - if (other == null) { |
| + int64 o = _promote(other); |
| + if (o == null) { |
| return false; |
| } |
| - int64 o = _promote(other); |
| return _l == o._l && _m == o._m && _h == o._h; |
| } |
| int compareTo(Comparable other) { |
| int64 o = _promote(other); |
| + if (o == null) { |
| + throw new ArgumentError(other); |
| + } |
| int signa = _h >> (_BITS2 - 1); |
| int signb = o._h >> (_BITS2 - 1); |
| if (signa != signb) { |