Decimal arithmetic, with example code

Paul Boddie paul at boddie.net
Thu Oct 3 06:29:03 EDT 2002


Tim Peters <tim.one at comcast.net> wrote in message news:<mailman.1033584485.32332.python-list at python.org>...
> 
> That's a different issue.  The results of the given expression are
> platform-dependent even if float_res is exactly representable in binary fp.
> For example,
> 
> >>> '%0.2f' % 1.125
>  '1.13'
> >>>
> 
> on Windows but produces '1.12' on most other platforms.  This doesn't have
> to do with representation error (decimal 1.125 is exactly representable in
> binary fp), it has to do with tbe platform sprintf's *decimal* rounding
> policy in "exactly halfway" cases.  That varies across platforms, even with
> identical FP HW.

Well, you're the recognised master of floating point, so I'll bow to
your expertise. In any case, my original point (or perhaps the
intended meaning of my original point) still stands: verifying decimal
arithmetic results using a combination of "unreliable" technologies
(floating point arithmetic and various "uncontrollable" rounding and
presentation techniques) isn't going to convince that many people that
the decimal arithmetic is wrong.

Paul



More information about the Python-list mailing list