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?

12th Sep 2018, 6:46 PM
H2727
H2727 - avatar
3 Réponses
+ 2
floating point arithmetic is not precise in general, so every floating point modulus function will have its downsides.
12th Sep 2018, 7:09 PM
Bebida Roja
Bebida Roja - avatar
+ 1
fmod is not precise.
12th Sep 2018, 7:07 PM
Bebida Roja
Bebida Roja - avatar
0
So how can I calculate the remainder?
12th Sep 2018, 7:08 PM
H2727
H2727 - avatar