julia
julia copied to clipboard
`Base.binomial` returns `Float64` for `Integer` inputs of different types.
The docs say
binomial(n::Integer, k::Integer)
The binomial coefficient \binom{n}{k}, being the coefficient of the kth term in the polynomial
expansion of (1+x)^n.
which isn't strictly true. When n and k have different integer types, the generalized binomial coefficient is returned, i.e. from binomial(x::Number, k::Integer).
julia> binomial(4, 2)
6
julia> binomial(Int32(4), 2)
6.0
julia> binomial(Int32(4), Int32(2))
6
Add
binomial(n::Integer, k::Integer) = binomial(promote(n, k)...)
? Then
julia> binomial(Int32(4), Int64(2))
6 # typeof(6) == Int64
A PR is welcome