Skip to content

Commit 4440b0f

Browse files
authored
binomial should throw OverflowError instead of InexactError (#25498)
1 parent a3496f2 commit 4440b0f

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

base/intfuncs.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -900,7 +900,7 @@ function binomial(n::T, k::T) where T<:Integer
900900
rr = 2
901901
while rr <= k
902902
xt = div(widemul(x, nn), rr)
903-
x = xt
903+
x = xt % T
904904
x == xt || throw(OverflowError("binomial($n0, $k0) overflows"))
905905
rr += 1
906906
nn += 1

test/combinatorics.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
@test binomial(Int32(34), Int32(15)) == binomial(BigInt(34), BigInt(15)) == 1855967520
1414
@test binomial(Int64(67), Int64(29)) == binomial(BigInt(67), BigInt(29)) == 7886597962249166160
1515
@test binomial(Int128(131), Int128(62)) == binomial(BigInt(131), BigInt(62)) == 157311720980559117816198361912717812000
16-
@test_throws InexactError binomial(Int64(67), Int64(30))
16+
@test_throws OverflowError binomial(Int64(67), Int64(30))
1717
end
1818

1919
@testset "permutations" begin

0 commit comments

Comments
 (0)