Skip to content

Commit

Permalink
binomial(::BigInt, k) should give BigInt(0) for k < 0
Browse files Browse the repository at this point in the history
  • Loading branch information
jakebolewski committed Jan 5, 2015
1 parent 7d4c3a5 commit b5bd61d
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 1 deletion.
2 changes: 1 addition & 1 deletion base/gmp.jl
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,7 @@ function binomial(n::BigInt, k::UInt)
ccall((:__gmpz_bin_ui, :libgmp), Void, (Ptr{BigInt}, Ptr{BigInt}, Culong), &z, &n, k)
return z
end
binomial(n::BigInt, k::Integer) = k < 0 ? throw(DomainError()) : binomial(n, uint(k))
binomial(n::BigInt, k::Integer) = k < 0 ? BigInt(0) : binomial(n, uint(k))

==(x::BigInt, y::BigInt) = cmp(x,y) == 0
==(x::BigInt, i::Integer) = cmp(x,i) == 0
Expand Down
1 change: 1 addition & 0 deletions test/bigint.jl
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ end
@test lcm(BigInt(48), BigInt(180)) == 720

@test factorial(BigInt(40)) == BigInt("815915283247897734345611269596115894272000000000")
@test binomial(BigInt(1), -1) == BigInt(0)
@test binomial(BigInt(-53), 42) == BigInt("959509335087854414441273718")
@test binomial(BigInt(113), BigInt(42)) == BigInt("18672199984318438125634054194360")

Expand Down

0 comments on commit b5bd61d

Please sign in to comment.