3

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
phipsgabler
  • 20,535
  • 4
  • 40
  • 60
Julia Learner
  • 2,754
  • 15
  • 35

1 Answers1

4

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.

Bogumił Kamiński
  • 66,844
  • 3
  • 80
  • 107