fmod and %

Terry Reedy tjreedy at udel.edu
Wed Apr 21 14:21:28 EDT 2004


"Zunbeltz Izaola" <zunbeltz at wm.lc.ehu.es.XXX> wrote in message
news:cthbrlllkmc.fsf at lcpxdf.wm.lc.ehu.es...
>
> Hi,
>
> I have a problem with % operation. It returns a incorrect value in
> this case:
>
> >>> -2.77555756156e-17%1
> 1.0
>
> where the returned value should be -2.77555756156e-17.

Wrong.  As per the docs, x % positive number is defined as being positive
and <= that positive number.  So above should be about 1.0 - 2.8e17, which,
for 32 bit machines, is 1.0, which is exactly what you got

>>> 1 - 2.8e-17
1.0.

as with
>>> 1 - 5.5e-17
1.0

whereas
>>> 1 - 5.6e-17
0.99999999999999989

> >>> -0.32768000000000003%1
> 0.67232000000000003

And this is 1.0 - .32768

Terry J. Reedy







More information about the Python-list mailing list