-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Use standard binomial
for Integer arguments
#54307
Conversation
Before this commit, `binomial(Int64(10), Int32(5))` meant the generalized binomial coefficient due to the arguments being of different types, which was in contradiction with the documentation. Fixes JuliaLang#54296
Thanks, I just noticed this. Actually, before the introduction of the generalized binomial coefficient in 1.10 (#48124), the lack of promotion meant that different integer types simply gave an error: julia1.9> binomial(Int32(5), 3)
ERROR: MethodError: no method matching binomial(::Int32, ::Int64) so apparently this has always been broken (going back to Julia 1.0 and earlier). |
@@ -1205,6 +1205,7 @@ Base.@assume_effects :terminates_locally function binomial(n::T, k::T) where T<: | |||
end | |||
copysign(x, sgn) | |||
end | |||
binomial(n::Integer, k::Integer) = binomial(promote(n, k)...) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nitpick: I would have moved this general definition up, to attach it to the docstring.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in #56679
Slight tweak to #54307: attach the `binomial(n::Integer, k::Integer)` method to the corresponding docstring, rather than the narrower `binomial(n::T, k::T) where {T<:Integer}` method.
Before this commit,
binomial(Int64(10), Int32(5))
meant the generalized binomial coefficient due to the arguments being of different types, which was in contradiction with the documentation.Fixes #54296