10^16 + 1 happens to evaluate to 10^16 because the +1 is too small for the 64-bit floating point representation that is being used. This is a case of round-off error.
Since 10^16 is even you actually get the correct result from mod
.
Domanda
In Octave
> mod(10^15 + 1, 2)
ans = 1
as expected, but
> mod(10^16 + 1, 2)
ans = 0
Same goes for larger numbers.
I was under the assumption that if the numbers were too large the first operand would have been evaluated as Inf
which would give NaN
as a result. Why is something different happening here? Octave function reference for mod doesn't mention anything.
Soluzione
10^16 + 1 happens to evaluate to 10^16 because the +1 is too small for the 64-bit floating point representation that is being used. This is a case of round-off error.
Since 10^16 is even you actually get the correct result from mod
.