c# - How to get remainder of 2 double using % operator? -
this question has answer here:
- is floating point math broken? 20 answers
i trying remainder of 2 double using % operator
double x = 965.606698735538; double y = 482.803349367769; var mod = x % y;
expected value 0
actual value 482.803349367769
can why behaving strange.
this quirk of binary floating point arithmetic.
the closest (ieee754) double
482.803349367769 482.80334936776898757671006023883819580078125
the closest double
965.606698735538 965.6066987355379751534201204776763916015625
as can see latter not twice former; in fact under twice that. accounts large remainder see.
you need careful when using %
floating point arguments.
Comments
Post a Comment