DescriptionAddressing 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 #
Messages
Total messages: 12 (0 generated)
|