bug in modulus?

Andrew Koenig ark at acm.org
Tue May 2 11:39:59 EDT 2006


"Christophe" <chris.cavalaria at free.fr> wrote in message 
news:4450928c$0$21107$626a54ce at news.free.fr...
> jantod at gmail.com a écrit :

> Floating point numbers just don't have the required precision to represent 
> 2.0 - 1e-050. For your specific problem, if you really want the result to 
> be < 2.0, the the best you can do is admit that floating point operations 
> have errors and return 0.0 when the modulus operation equals 2.0.

I disagree.  For any two floating-point numbers a and b, with b != 0, it is 
always possible to represent the exact value of a mod b as a floating-point 
number--at least on every floating-point system I have ever encountered. 
The implementation is not even that difficult.





More information about the Python-list mailing list