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

Unified Diff: runtime/lib/integers.dart

Issue 1211473002: Make int.gcd accept zero operands. (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Address comment. Created 5 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 | « runtime/lib/bigint.dart ('k') | sdk/lib/_internal/js_runtime/lib/js_number.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/lib/integers.dart
diff --git a/runtime/lib/integers.dart b/runtime/lib/integers.dart
index 90c3cddce053d69f6ece17f83b23fefd2af74f31..63f868bfdd23568c7431f4facfea3f895f1124d5 100644
--- a/runtime/lib/integers.dart
+++ b/runtime/lib/integers.dart
@@ -390,19 +390,15 @@ class _IntegerImplementation extends _Num {
return _binaryGcd(m, t, true);
}
- // Returns gcd of abs(this) and abs(other), with this != 0 and other !=0.
+ // Returns gcd of abs(this) and abs(other).
int gcd(int other) {
if (other is! int) {
throw new ArgumentError.value(other, "other", "not an integer");
}
- if (this == 0) {
- throw new ArgumentError.value(this, "this", "must not be zero");
- }
- if (other == 0) {
- throw new ArgumentError.value(this, "other", "must not be zero");
- }
int x = this.abs();
int y = other.abs();
+ if (x == 0) return y;
+ if (y == 0) return x;
if ((x == 1) || (y == 1)) return 1;
if (other is _Bigint) {
return _toBigint().gcd(other);
« no previous file with comments | « runtime/lib/bigint.dart ('k') | sdk/lib/_internal/js_runtime/lib/js_number.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698