-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
inconsistent sign of gcd #4810
Comments
It makes more sense to me for a gcd to be positive. |
For variety, Python's |
I'd also prefer having |
If the gcd is the greatest common divisor, and the divisors are defined as positive integers, then it seems like the gcd should always be positive. |
Note that the same inconsistency occurs for |
If we make |
I just checked that this means that construction of julia> big(2)//big(-3)
2//-3 That should produce |
Since |
Agreed. Just pointing out the issue. |
If anything, the fact that the difference between built-in integers and bigints was causing broken rational behavior demonstrates the fragility of relying on this rather subtle and non-obvious behavior. FWIW, the |
Wow, I forgot about the |
By the way, the old behavior was also causing a bug in |
What we were thinking was "crap, how the hell are we going to deal with numeric conversion and promotion?" – because we hadn't yet figured out how to do all of it with dispatch. The |
…tions-1 Update �gcd and �lcm doc. (Cf. issue JuliaLang#4810)
gcd(-7, 37)
returns-1
, butgcd(big(-7), big(37))
(via GMP) returns1
.In the
gcd(a,b)
implementation in intfuncs.jl, there is an explicit rule that the gcd return value has the same sign asa
. If there is a good reason for this rule(??), we should modify theBigInt
call to implement the same rule (since GMP seems to always return a positive result).The text was updated successfully, but these errors were encountered: