문제

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.

도움이 되었습니까?

해결책

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top