[Python-ideas] Python Numbers as Human Concept Decimal System
Mark Dickinson
dickinsm at gmail.com
Sat Mar 8 15:15:59 CET 2014
On Sat, Mar 8, 2014 at 12:01 PM, Antoine Pitrou <solipsis at pitrou.net> wrote:
> > problems of working with base 10 slide rules. For binary, the largest
> > ratio between differences is 2 rather than 10.
>
> Well, can you explain what difference it does in practice?
>
Probably not much that the average user would care about, but there are a
whole host of 'nice' properties that work in binary floating-point but not
in decimal. For example, in binary, assuming IEEE 754, round-to-nearest,
etc., you're guaranteed that for any two representable floats x and y, the
"average" (x+y)/2 lies in the interval [x, y] (even strictly between x and
y provided that x and y are at least 2 ulps apart), so a naively written
floating-point bisection search will converge. In decimal that's not true:
you can lose a whole digit of precision when adding x and y and end up with
a result that's outside [x, y].
>>> from decimal import *
>>> getcontext().prec = 3
>>> x = Decimal('0.516')
>>> y = Decimal('0.518')
>>> (x + y) / 2
Decimal('0.515') # ouch!
Then if you're doing numerical analysis and error computations, the
"wobble" (the variation in scale of the ratio between the mathematical
relative error and the error expressed in ulps) is 2 for binary, 10 for
decimal. That makes for weaker error bounds and faster-growing errors for
operations done in decimal floating-point rather than binary. (And it's
even worse for hexadecimal floating-point, which is why IEEE 754 is a big
improvement over IBM's hex float format.)
Binary is just better for serious numerical work. :-)
Mark
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20140308/1b03b50c/attachment.html>
More information about the Python-ideas
mailing list