| OLD | NEW |
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 // Copyright 2009 The Go Authors. All rights reserved. | 5 // Copyright 2009 The Go Authors. All rights reserved. |
| 6 // Use of this source code is governed by a BSD-style | 6 // Use of this source code is governed by a BSD-style |
| 7 // license that can be found in the LICENSE file. | 7 // license that can be found in the LICENSE file. |
| 8 | 8 |
| 9 /* | 9 /* |
| 10 * Copyright (c) 2003-2005 Tom Wu | 10 * Copyright (c) 2003-2005 Tom Wu |
| (...skipping 932 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 943 int pow(int exponent) { | 943 int pow(int exponent) { |
| 944 throw "Bigint.pow not implemented"; | 944 throw "Bigint.pow not implemented"; |
| 945 } | 945 } |
| 946 | 946 |
| 947 // Overriden operators and methods. | 947 // Overriden operators and methods. |
| 948 | 948 |
| 949 // The following operators override operators of _IntegerImplementation for | 949 // The following operators override operators of _IntegerImplementation for |
| 950 // efficiency, but are not necessary for correctness. They shortcut native | 950 // efficiency, but are not necessary for correctness. They shortcut native |
| 951 // calls that would return null because the receiver is _Bigint. | 951 // calls that would return null because the receiver is _Bigint. |
| 952 num operator +(num other) { | 952 num operator +(num other) { |
| 953 return other._toBigint()._addFromInteger(this); | 953 return other._toBigintOrDouble()._addFromInteger(this); |
| 954 } | 954 } |
| 955 num operator -(num other) { | 955 num operator -(num other) { |
| 956 return other._toBigint()._subFromInteger(this); | 956 return other._toBigintOrDouble()._subFromInteger(this); |
| 957 } | 957 } |
| 958 num operator *(num other) { | 958 num operator *(num other) { |
| 959 return other._toBigint()._mulFromInteger(this); | 959 return other._toBigintOrDouble()._mulFromInteger(this); |
| 960 } | 960 } |
| 961 num operator ~/(num other) { | 961 num operator ~/(num other) { |
| 962 if ((other is int) && (other == 0)) { | 962 if ((other is int) && (other == 0)) { |
| 963 throw const IntegerDivisionByZeroException(); | 963 throw const IntegerDivisionByZeroException(); |
| 964 } | 964 } |
| 965 return other._toBigint()._truncDivFromInteger(this); | 965 return other._toBigintOrDouble()._truncDivFromInteger(this); |
| 966 } | 966 } |
| 967 num operator /(num other) { | |
| 968 return this.toDouble() / other.toDouble(); | |
| 969 } | |
| 970 // TODO(regis): Investigate strange behavior with % double.INFINITY. | |
| 971 /* | |
| 972 num operator %(num other) { | 967 num operator %(num other) { |
| 973 if ((other is int) && (other == 0)) { | 968 if ((other is int) && (other == 0)) { |
| 974 throw const IntegerDivisionByZeroException(); | 969 throw const IntegerDivisionByZeroException(); |
| 975 } | 970 } |
| 976 return other._toBigint()._moduloFromInteger(this); | 971 return other._toBigintOrDouble()._moduloFromInteger(this); |
| 977 } | 972 } |
| 978 */ | |
| 979 int operator &(int other) { | 973 int operator &(int other) { |
| 980 return other._toBigint()._bitAndFromInteger(this); | 974 return other._toBigintOrDouble()._bitAndFromInteger(this); |
| 981 } | 975 } |
| 982 int operator |(int other) { | 976 int operator |(int other) { |
| 983 return other._toBigint()._bitOrFromInteger(this); | 977 return other._toBigintOrDouble()._bitOrFromInteger(this); |
| 984 } | 978 } |
| 985 int operator ^(int other) { | 979 int operator ^(int other) { |
| 986 return other._toBigint()._bitXorFromInteger(this); | 980 return other._toBigintOrDouble()._bitXorFromInteger(this); |
| 987 } | 981 } |
| 988 int operator >>(int other) { | 982 int operator >>(int other) { |
| 989 return other._toBigint()._shrFromInt(this); | 983 return other._toBigintOrDouble()._shrFromInt(this); |
| 990 } | 984 } |
| 991 int operator <<(int other) { | 985 int operator <<(int other) { |
| 992 return other._toBigint()._shlFromInt(this); | 986 return other._toBigintOrDouble()._shlFromInt(this); |
| 993 } | 987 } |
| 994 // End of operator shortcuts. | 988 // End of operator shortcuts. |
| 995 | 989 |
| 996 int operator -() { | 990 int operator -() { |
| 997 if (_used == 0) { | 991 if (_used == 0) { |
| 998 return this; | 992 return this; |
| 999 } | 993 } |
| 1000 var r = new _Bigint(); | 994 var r = new _Bigint(); |
| 1001 _copyTo(r); | 995 _copyTo(r); |
| 1002 r._neg = !_neg; | 996 r._neg = !_neg; |
| (...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1197 _reduce(r); | 1191 _reduce(r); |
| 1198 } | 1192 } |
| 1199 | 1193 |
| 1200 // r = x*y/R mod _m ; x, y != r | 1194 // r = x*y/R mod _m ; x, y != r |
| 1201 void _mulTo(_Bigint x, _Bigint y, _Bigint r) { | 1195 void _mulTo(_Bigint x, _Bigint y, _Bigint r) { |
| 1202 x._mulTo(y, r); | 1196 x._mulTo(y, r); |
| 1203 _reduce(r); | 1197 _reduce(r); |
| 1204 } | 1198 } |
| 1205 } | 1199 } |
| 1206 | 1200 |
| OLD | NEW |