Possible Duplicate:
How to make a modulo operation in objective-c / cocoa touch?
Can somebody explain to me why here the value of “myModValue” is 1.73472e-18
but when x would be 0.1 or 0.4 it’s correctly 0?
Is there a better way to get the modulo-value of two doubles?
double x = 0.3;
double y = 0.1;
double myModValue = fmod(x, y);
Thanks Michael
EDIT:
Tried the above code hardcoded (so not with the values of my project-variables) and the result is 0.1
I don’t know why…
Floating point numbers are not precisely accurate due to rounding errors, the value 1.73472e-18 is essentially 0 in floating point terms. This is why you shouldn’t compare floats with ==.
See also this answer.