You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This is probably a limitation due to GMP, but in that case
Probably binomial(n::BigInt, k::Integer) = k < 0 ? BigInt(0) : binomial(n, UInt(min(k, n-k))) will cover more cases,
Limitations are not currently documented.
Please advise on how to proceed — if at all — thanks!
The text was updated successfully, but these errors were encountered:
originalsouth
changed the title
Binomial for BigInt does not work with BigInt > typemax(UInt64) + 1
Binomial for BigInt does not work with BigInt > typemax(UInt64) + 1 for k
Jan 1, 2023
Your solution seems like a good start. the limitation is due to GMP so unless we want to make a pure Julia binomial (which I kind of doubt) it's probably all we are going to want to do.
originalsouth
changed the title
Binomial for BigInt does not work with BigInt > typemax(UInt64) + 1 for k
Binomial for BigInt does not work with k > typemax(UInt64)
Jan 2, 2023
This limitation is also due to the limited storage of computers as they exist today. I.e., the smallest (?) case not covered by the improvement @originalsouth proposes is this: binomial(big(2)^65, big(2)^64). An extremely generous (bad lower bound for this value is $2^{2^{64}}$. Storing the actual value would require more storage than any computer currently in existence has (I am too lazy to check if it also exceeds the total amount of memory available when adding all compute storage ever built, but let's just say that slightly larger inputs will easily get there).
So in this sense, the patch by @originalsouth is the best possible. And this also explain why the GMP authors "limited" the API in this way: there is just no point in offering a more general API.
versioninfo()
How you installed Julia
See https://aur.archlinux.org/packages/julia-bin
A minimal working example (MWE), also known as a minimum reproducible example
Culprit
base/gmp.jl:685
:This is probably a limitation due to GMP, but in that case
binomial(n::BigInt, k::Integer) = k < 0 ? BigInt(0) : binomial(n, UInt(min(k, n-k)))
will cover more cases,Please advise on how to proceed — if at all — thanks!
The text was updated successfully, but these errors were encountered: