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

Issue 475463005: Implement math.gcd in dart. (Closed)

Created:
6 years, 4 months ago by srawlins
Modified:
6 years, 3 months ago
CC:
reviews_dartlang.org
Visibility:
Public.

Description

Addressing Issue 5991, where functions are requested for: * greatest common denominator * modulo inverse * modulo exponentiation In addition, I implemented functions for least common multiple and extended gcd, as they are so closely related. These functions are respectively named gcd(), invert(), modexp(), lcm(), gcdext(), provided in the math package, and tested in the math package. When passed arguments larger than 2^53, a javascript implementation of dart will yield unpredictable results, as is true with all of the dart:int methods. Some of the function names are arbitrary, as they go by different names in different languages: * For modular multiplicative inverse, I chose "invert." It goes by "invert" in GMP [1], "modInverse" in Java and Go, "invmod" in Julia, "PowerMod" in Mathematica, and "pow" in Python. * For modular exponentiation, I chose "powmod." It goes by "powm" in GMP, "exp" in Go, "modPow" in Java, "powermod" in Julia and Mathematica, and "pow" in Python (optional arg). * For extended gcd, I chose "gcdext." It goes by "gcdext" in GMP, "gcd" in Go (optional return args), "gcdx" in Julia, and "ExtendedGCD" in Mathematica. BUG= https://code.google.com/p/dart/issues/detail?id=5991 [1] https://gmplib.org/ R=lrn@google.com Committed: https://code.google.com/p/dart/source/detail?r=39769

Patch Set 1 #

Patch Set 2 : mint and bigint tests #

Total comments: 12

Patch Set 3 : Move gcd to pkg/math; move tests; fix implementation; split bigint tests #

Total comments: 10

Patch Set 4 : Adding lcm, gcdext, invert, and expmod, with tests #

Total comments: 27

Patch Set 5 : Addressing lrn@'s comments; adding negative bignum tests #

Total comments: 4

Patch Set 6 : Tweaks #

Unified diffs Side-by-side diffs Delta from patch set Stats (+551 lines, -1 line) Patch
M pkg/math/lib/math.dart View 1 2 3 4 5 1 chunk +148 lines, -1 line 0 comments Download
A pkg/math/test/bigint_test.dart View 1 2 3 4 1 chunk +141 lines, -0 lines 0 comments Download
A pkg/math/test/gcd_test.dart View 1 2 3 1 chunk +70 lines, -0 lines 0 comments Download
A pkg/math/test/gcdext_test.dart View 1 2 3 1 chunk +38 lines, -0 lines 0 comments Download
A pkg/math/test/invert_test.dart View 1 2 3 1 chunk +32 lines, -0 lines 0 comments Download
A pkg/math/test/lcm_test.dart View 1 2 3 1 chunk +70 lines, -0 lines 0 comments Download
A pkg/math/test/powmod_test.dart View 1 2 3 4 5 1 chunk +51 lines, -0 lines 0 comments Download
M pkg/pkg.status View 1 2 3 4 1 chunk +1 line, -0 lines 0 comments Download

Messages

Total messages: 12 (0 generated)
srawlins
Hi floitsch@, would this one go to you? I'd love general input, like: should I ...
6 years, 4 months ago (2014-08-14 00:57:54 UTC) #1
floitsch
6 years, 4 months ago (2014-08-14 09:20:13 UTC) #2
Lasse Reichstein Nielsen
https://codereview.chromium.org/475463005/diff/20001/sdk/lib/math/math.dart File sdk/lib/math/math.dart (right): https://codereview.chromium.org/475463005/diff/20001/sdk/lib/math/math.dart#newcode260 sdk/lib/math/math.dart:260: int gcd(int a, int b) { Adding an uncapitalized ...
6 years, 4 months ago (2014-08-19 08:31:31 UTC) #3
srawlins
Sorry, I was burned by tests/lib/lib.status, which contains "math/math_test: RuntimeError", which means that testGcd() was ...
6 years, 4 months ago (2014-08-19 22:35:23 UTC) #4
srawlins
Thanks for all the comments, lrn@. Now that I've got the structure more correct, I ...
6 years, 4 months ago (2014-08-20 01:06:27 UTC) #5
Lasse Reichstein Nielsen
Looks good, but move tests to package as well. https://codereview.chromium.org/475463005/diff/40001/pkg/math/lib/math.dart File pkg/math/lib/math.dart (right): https://codereview.chromium.org/475463005/diff/40001/pkg/math/lib/math.dart#newcode10 pkg/math/lib/math.dart:10: ...
6 years, 4 months ago (2014-08-20 12:17:03 UTC) #6
srawlins
Addressed feedback. Added functions for: * least common multiple * extended greatest common denominator * ...
6 years, 4 months ago (2014-08-25 05:43:54 UTC) #7
Lasse Reichstein Nielsen
Update pubspec.yaml version (to 1.0.0 - might as well get there some day). LGTM with ...
6 years, 3 months ago (2014-08-26 07:44:27 UTC) #8
srawlins
Hi lrn@, thanks for the review! I've addressed it all, I believe. I gained commit ...
6 years, 3 months ago (2014-08-29 06:43:25 UTC) #9
Lasse Reichstein Nielsen
LGTM with tiny comments, please do commit after fixing. https://codereview.chromium.org/475463005/diff/60001/pkg/math/lib/math.dart File pkg/math/lib/math.dart (right): https://codereview.chromium.org/475463005/diff/60001/pkg/math/lib/math.dart#newcode86 pkg/math/lib/math.dart:86: ...
6 years, 3 months ago (2014-08-29 07:14:43 UTC) #10
srawlins
https://codereview.chromium.org/475463005/diff/60001/pkg/math/lib/math.dart File pkg/math/lib/math.dart (right): https://codereview.chromium.org/475463005/diff/60001/pkg/math/lib/math.dart#newcode143 pkg/math/lib/math.dart:143: base = (base * base) % mod; On 2014/08/29 ...
6 years, 3 months ago (2014-09-02 19:49:23 UTC) #11
srawlins
6 years, 3 months ago (2014-09-02 19:49:59 UTC) #12
Message was sent while issue was closed.
Committed patchset #6 (id:100001) manually as 39769 (presubmit successful).

Powered by Google App Engine
This is Rietveld 408576698