Computation with huge numbers: BigInt, BigFloat etc

I am trying to compute the number binomial(100,50)/2^100, among others.

The following code gives an explicit rational value of type Rational{BigInt} for that number.

julia> using Combinatorics 
julia> binomial(big(100),50) // big(2)^100
12611418068195524166851562157//158456325028528675187087900672

Unfortunately, trying to convert this value to Float64 using the float function gives an error.

julia> julia> float(binomial(big(100),50) // big(2)^100)
Error showing value of type BigFloat:
ERROR: AssertionError: length(int) == 1
[...]

Why? I would expect float to be able to handle such an argument.

julia> float(Rational{BigInt})
BigFloat

julia> BigFloat(binomial(big(100),50) // big(2)^100)
Error showing value of type BigFloat:
ERROR: AssertionError: length(int) == 1

I finally succeeded to obtain an approximate value with

julia> convert(Float64, binomial(big(100),50) // big(2)^100)
0.07958923738717877

Still I am puzzled by the errors I obtained. How can I obtain a value of type BigFloat for my number? This seems to be the correct type for these kind of computations.

I can’t reproduce your problem:

julia> float(binomial(big(100),50) // big(2)^100)
7.95892373871787614981270502421704614029315404247333213573478705171737601631321e-02

Can you try it in a fresh Julia session?

4 Likes

Indeed, something went wrong with my session. Thanks.