a little math problem

Jeff Epler jepler at unpythonic.net
Fri Apr 16 16:27:33 EDT 2004


25.2 isn't a multiple of .2.  In fact, (126 * .2) appears not to be
(126 * .2) % .2 != 0).  Floating-point sucks.  I'm really sorry about that.

I'm also sorry about getting my answer wrong.  I had it in my head that
divmod() took integer arguments, not floating-point ones.

Perhaps you should use the Decimal package
(http://cvs.sourceforge.net/viewcvs.py/python/python/nondist/sandbox/decimal/),
rational numbers, or scaled integers.  The two problems with any such
approach is that you can't use literal syntax for nonintegers anymore,
and it's slower than floating-point.

Jeff




More information about the Python-list mailing list