0
a problem with fmod() c++
Hi everyone! I need to calculate the remainder of a number when divided by 0.001 for a code. fmod(x,0.001) works perfectly when the remainder is not 0 (like the number 2.1503) but when the remainder is zero (like the number 3.73 or an integer like 3) it returns 0.001. Why is that? And how can I prevent it?
3 Réponses
+ 2
floating point arithmetic is not precise in general, so every floating point modulus function will have its downsides.
+ 1
fmod is not precise.
0
So how can I calculate the remainder?