Skip to content

Commit

Permalink
Use standard binomial for Integer arguments (#54307)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
barucden committed Apr 29, 2024
1 parent 50e038e commit 10db278
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
1 change: 1 addition & 0 deletions base/intfuncs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)...)

"""
binomial(x::Number, k::Integer)
Expand Down
4 changes: 4 additions & 0 deletions test/intfuncs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -593,6 +593,10 @@ end
x>=0 && @test binomial(x,x-T(2)) == div(x*(x-1), 2)
end
@test @inferred(binomial(one(T),one(T))) isa T

# Arguments of different Integer types do not lead to computation of
# generalized binomial coefficient (issue #54296)
@test @inferred(binomial(Int64(5), T(2))) === Int64(10)
end
for x in ((false,false), (false,true), (true,false), (true,true))
@test binomial(x...) == (x != (false,true))
Expand Down

0 comments on commit 10db278

Please sign in to comment.