You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
gcd(x, y) fails if y is negative and if x or y is a BigNumber. The gcd(x, y) function internally calls the mod(x, y) function. Unfortunately, the mod(x, y) function has been set to fail when a BigNumber is involved, if the divisor y is negative.
Potential solution would be for gcd(x, y) to internally call mod(x, abs(y)) instead.
To Reproduce
const{ BigNumber, gcd }=require('mathjs');gcd(-2,BigNumber(12));// 2 -- No issuegcd(BigNumber(12),-2);// Uncaught Error: Cannot calculate mod for a negative divisor
The text was updated successfully, but these errors were encountered:
Good point. We recently improved the number implementation of the function mod (used by gcd) to support negative divisors, but haven't adjusted the BigNumber and Fraction implementations. It shouldn't be hard to adjust this and copy the number implementation of mod to BigNumber and Fraction.
Anyone interested in picking this up? Help would be welcome.
josdejong
changed the title
gcd(x, y) fails if y is negative and if x or y is a BigNumber
Implement support for negative divisor in the BigNumber and Fraction implementation of function modNov 1, 2023
Describe the bug
gcd(x, y)
fails ify
is negative and ifx
ory
is a BigNumber. Thegcd(x, y)
function internally calls themod(x, y)
function. Unfortunately, themod(x, y)
function has been set to fail when a BigNumber is involved, if the divisory
is negative.Potential solution would be for
gcd(x, y)
to internally callmod(x, abs(y))
instead.To Reproduce
The text was updated successfully, but these errors were encountered: