Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(90)

Unified Diff: pkg/fixnum/lib/src/int64.dart

Issue 20803006: Don't throw exception for non-integer args to fixnum int32,int64 op == (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « pkg/fixnum/lib/src/int32.dart ('k') | pkg/fixnum/test/int_32_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..a1791055f8e20e68e4983383a27b619e3937e086 100644
--- a/pkg/fixnum/lib/src/int64.dart
+++ b/pkg/fixnum/lib/src/int64.dart
@@ -240,18 +240,17 @@ 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. Throws
+ // [ArgumentError] for non-integer arguments.
+ int64 _promote(val) {
+ if (val is int64) {
+ return val;
+ } else if (val is int) {
+ return new int64.fromInt(val);
+ } else if (val is int32) {
+ return val.toInt64();
+ }
+ throw new ArgumentError(val);
}
int64 operator +(other) {
@@ -266,7 +265,6 @@ class int64 implements intx {
int64 operator -(other) {
int64 o = _promote(other);
-
int sum0 = _l - o._l;
int sum1 = _m - o._m + _shiftRight(sum0, _BITS);
int sum2 = _h - o._h + _shiftRight(sum1, _BITS);
@@ -286,6 +284,7 @@ class int64 implements intx {
int64 operator *(other) {
int64 o = _promote(other);
+
// Grab 13-bit chunks.
int a0 = _l & 0x1fff;
int a1 = (_l >> 13) | ((_m & 0xf) << 9);
@@ -515,11 +514,18 @@ class int64 implements intx {
* given object. The argument may be an [int] or an [intx].
*/
bool operator ==(other) {
- if (other == null) {
- return false;
+ int64 o;
+ if (other is int64) {
+ o = other;
+ } else if (other is int) {
+ o = new int64.fromInt(other);
+ } else if (other is int32) {
+ o = other.toInt64();
}
- int64 o = _promote(other);
- return _l == o._l && _m == o._m && _h == o._h;
+ if (o != null) {
+ return _l == o._l && _m == o._m && _h == o._h;
+ }
+ return false;
}
int compareTo(Comparable other) {
@@ -944,7 +950,7 @@ class int64 implements intx {
_h = b2;
}
- int64 _divModByShift(int64 a, int bpower, bool negative, bool aIsCopy,
+ static int64 _divModByShift(int64 a, int bpower, bool negative, bool aIsCopy,
bool aIsNegative, bool computeRemainder) {
int64 c = a >> bpower;
if (negative) {
@@ -997,7 +1003,7 @@ class int64 implements intx {
return -1;
}
- int64 _divMod(int64 a, int64 b, bool computeRemainder) {
+ static int64 _divMod(int64 a, int64 b, bool computeRemainder) {
if (b.isZero) {
throw new IntegerDivisionByZeroException();
}
« no previous file with comments | « pkg/fixnum/lib/src/int32.dart ('k') | pkg/fixnum/test/int_32_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698