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

Unified Diff: runtime/lib/bigint.dart

Issue 1211473002: Make int.gcd accept zero operands. (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Created 5 years, 6 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 | « no previous file | runtime/lib/integers.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/lib/bigint.dart
diff --git a/runtime/lib/bigint.dart b/runtime/lib/bigint.dart
index 2e659bc76f9b1e8a7962f1db8fe358a39015deb3..3f23ad775596df347ad948095df894d679c1ce1c 100644
--- a/runtime/lib/bigint.dart
+++ b/runtime/lib/bigint.dart
@@ -1558,11 +1558,9 @@ class _Bigint extends _IntegerImplementation implements int {
throw new UnsupportedError("Not coprime");
}
} else {
- if (x_used == 0) {
- throw new ArgumentError.value(0, "first operand", "must not be zero");
- }
- if (y_used == 0) {
- throw new ArgumentError.value(0, "second operand", "must not be zero");
+ if ((x_used == 0) && (y_used == 0)) {
+ throw new ArgumentError.value(0, null,
+ "at least one operand must not be zero");
floitsch 2015/06/24 12:18:13 Wolfram Alpha goes as far as to say that gcd(0, 0)
Lasse Reichstein Nielsen 2015/06/24 12:44:10 It's a usable definition, as long as you can expla
}
if (((x_used == 1) && (x_digits[0] == 1)) ||
((y_used == 1) && (y_digits[0] == 1))) return 1;
@@ -1810,6 +1808,9 @@ class _Bigint extends _IntegerImplementation implements int {
if (other is! int) {
throw new ArgumentError.value(other, "other", "not an integer");
}
+ if (other == 0) {
floitsch 2015/06/24 12:18:13 Are we sure that bigints cannot be 0? (If yes asse
Lasse Reichstein Nielsen 2015/06/24 12:44:10 They can be 0, at least internally. The `other._to
regis 2015/06/24 16:07:16 Correct. At this point, 'other' has not yet been f
+ return this.abs();
+ }
return _binaryGcd(this, other._toBigint(), false);
}
}
« no previous file with comments | « no previous file | runtime/lib/integers.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698