|
Posted by Tim Roberts on 11/30/07 06:00
bummerland@gmail.com wrote:
>
>I have a problem with the function fmod.
>
>Why is fmod(5.7, 0.1) = 0.1 ?? Why is it not 0?
Because floating point arithmetic is not exact. The number "5.7" cannot be
represented exactly in binary. So, it's quite likely that you are really
computing something like fmod(5.69999999999999, 0.1), and that result would
be 0.09999999999999, which will print as 0.1.
It's not the function that is broken, I am afraid. It is your
expectations.
--
Tim Roberts, timr@probo.com
Providenza & Boekelheide, Inc.
Navigation:
[Reply to this message]
|