How about adding rational fraction to Python?

Mark Dickinson dickinsm at gmail.com
Tue Mar 4 15:39:42 CET 2008


On Mar 4, 8:46 am, NickC <ncogh... at gmail.com> wrote:
> The increased number of inaccurate answers with Decimal (31% vs 10%)
> is probably due to the fact that it is actually more precise than
> float

I suspect it has more to do with the fact that 10 is bigger than 2,
though I'm not sure I could precisely articulate the reasons why
this matters.  (A bigger base means a bigger 'wobble', the wobble
being the variation in the relationship between an error of 1ulp and
a relative error of base**-precision.)

Rerunning your example after a

getcontext().prec = 16

(i.e. with precision comparable to that of float) gives

>>> check_accuracy(Decimal)
310176

Mark



More information about the Python-list mailing list