Does the julia round function contain an error for large numbers?

Viewed 508

The julia round function seems to work OK up to factorial(75), but breaks at factorial 76. Is this a bug in the round function?

julia>round(factorial(big(75)), sigdigits=2)
2.5e+109

julia>round(factorial(big(76)), sigdigits=2)
1.900000000000000000000000000000000000000000000000000000000000000000000000000006e+111
1 Answers

You have to increase the precision of BigFloat compuations to get the right result e.g. like this:

julia> setprecision(1000) do
       round(factorial(big(76)), sigdigits=2)
       end
1.9e+111

The source of the problem is that when rounding Julia represents {base}^{number of digits to round} as an appropriate float. In this case it is BigFloat(10)^-110 which under default precision is not precise enough for the required number of digits.

Related