Decimal() instead of float?

Terry Reedy tjreedy at udel.edu
Fri Nov 17 18:24:16 EST 2006


"Michael B. Trausch" <fd0man at gmail.com> wrote in message 
news:1163800304.5107.179.camel at pepper...
> Let's say that I want to work with the latitude 33.6907570.  In Python, 
> that number > can not be stored exactly without the aid of 
> decimal.Decimal().

> >>> 33.6907570
> 33.690756999999998
> >>>

> As you can see, it loses accuracy after the 6th decimal place.

No, it loses accuracy in the 15th decimal place, which is the 17th digit.
This is far more accurate than any measured latitude could be.
If the above is a measurement, it represents anything from 33.69075695
to 33.69075705.  The conversion error would have to be multiplied by some 
number of millions before it would be visible in the 7th decimal place 
(your last).

Any trigonometric calculations will use an *approximate* value of pi and 
polynomial *approximations* of the theoretical functions.

Perhaps you have been given impossible conditions to fulfill.

Terry Jan Reedy






More information about the Python-list mailing list