How about adding rational fraction to Python?

Mark Dickinson dickinsm at gmail.com
Wed Mar 12 11:47:41 EDT 2008


On Mar 12, 7:20 am, Piet van Oostrum <p... at cs.uu.nl> wrote:
> But if the answer is incorrect (in the float calculation) the error is
> limited. IEEE 754 prescribes that the error should be at most 1 LSB, IIRC.
> And then the number of errors is the proper measure.

There are two operations here, both of which can introduce error of
up to 0.5 ulp (ulp = unit in the last place).  Moreover, the second
operation (the multiplication) can magnify the error introduced by
the first (the division).

You're correct that for IEEE 754 binary floating-point arithmetic,
(x/y)*y and x will either be equal or differ by exactly 1ulp (except
perhaps in rarely-occurring corner cases).  But for decimal numbers,
(x/y)*y and x could be as much as 5 ulps apart.

Mark


> --
> Piet van Oostrum <p... at cs.uu.nl>
> URL:http://pietvanoostrum.com[PGP 8DAE142BE17999C4]
> Private email: p... at vanoostrum.org




More information about the Python-list mailing list