Skip to content
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

Merged
merged 1 commit into from
Apr 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)...)
Copy link
Member

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.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in #56679


"""
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