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

Side by Side 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: 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 unified diff | Download patch
« no previous file with comments | « no previous file | runtime/lib/integers.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 1793 matching lines...) Expand 10 before | Expand all | Expand 10 after
1804 if (m == 1) return 0; 1804 if (m == 1) return 0;
1805 m = m._toBigint(); 1805 m = m._toBigint();
1806 var t = this; 1806 var t = this;
1807 if (t._neg || (t._absCompare(m) >= 0)) { 1807 if (t._neg || (t._absCompare(m) >= 0)) {
1808 t %= m; 1808 t %= m;
1809 t = t._toBigint(); 1809 t = t._toBigint();
1810 } 1810 }
1811 return _binaryGcd(m, t, true); 1811 return _binaryGcd(m, t, true);
1812 } 1812 }
1813 1813
1814 // Returns gcd of abs(this) and abs(other), with this != 0 and other !=0. 1814 // Returns gcd of abs(this) and abs(other).
1815 int gcd(int other) { 1815 int gcd(int other) {
1816 if (other is! int) { 1816 if (other is! int) {
1817 throw new ArgumentError.value(other, "other", "not an integer"); 1817 throw new ArgumentError.value(other, "other", "not an integer");
1818 } 1818 }
1819 if (other == 0) {
1820 return this.abs();
1821 }
1819 return _binaryGcd(this, other._toBigint(), false); 1822 return _binaryGcd(this, other._toBigint(), false);
1820 } 1823 }
1821 } 1824 }
1822 1825
1823 // Interface for modular reduction. 1826 // Interface for modular reduction.
1824 class _Reduction { 1827 class _Reduction {
1825 // Return the number of digits used by r_digits. 1828 // Return the number of digits used by r_digits.
1826 int _convert(_Bigint x, Uint32List r_digits); 1829 int _convert(_Bigint x, Uint32List r_digits);
1827 int _mul(Uint32List x_digits, int x_used, 1830 int _mul(Uint32List x_digits, int x_used,
1828 Uint32List y_digits, int y_used, Uint32List r_digits); 1831 Uint32List y_digits, int y_used, Uint32List r_digits);
(...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after
2087 2090
2088 int _mul(Uint32List x_digits, int x_used, 2091 int _mul(Uint32List x_digits, int x_used,
2089 Uint32List y_digits, int y_used, 2092 Uint32List y_digits, int y_used,
2090 Uint32List r_digits) { 2093 Uint32List r_digits) {
2091 var r_used = _Bigint._mulDigits(x_digits, x_used, 2094 var r_used = _Bigint._mulDigits(x_digits, x_used,
2092 y_digits, y_used, 2095 y_digits, y_used,
2093 r_digits); 2096 r_digits);
2094 return _reduce(r_digits, r_used); 2097 return _reduce(r_digits, r_used);
2095 } 2098 }
2096 } 2099 }
OLDNEW
« 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