Decimal() instead of float?

Michael B. Trausch fd0man at gmail.com
Fri Nov 17 15:10:51 EST 2006


On Wed, 2006-11-15 at 12:48 +0100, Fredrik Lundh wrote:

> Steve Holden wrote:
> 
> >> It /would/ be nice to see Decimal() become the default.  I cannot 
> >> imagine why in an otherwise "human enough" language, math wouldn't be 
> >> included in that without going out of one's way to do it.  :-)
> >>
> > Speed has a lot to do with it. Have you timed some decimal operations 
> > against their floating-point counterparts? It might be possible to build 
> > a version of Python that used decimal instead of floating-point but it 
> > certainly wouldn't be trivial: consider the use of C language libraries 
> > that know nothing of Python's decimal representation.
> 
> judging from the various decimal FAQ:s, I think it's a bit naive to 
> think that using Decimal instead of float would somehow make everything 
> "just work":
> 
> http://www2.hursley.ibm.com/decimal/decifaq.html
> http://effbot.org/pylib/decimal.htm#decimal-faq
> 
> (btw, the OP mentioned in private mail that he wanted to store 
> geographical coordinates in decimal because floats kept messing things 
> up, but given that a 64-bit float can hold enough decimal digits to 
> represent a geographical coordinate with sub-millimeter precision on a 
> global scale, I'm not sure I buy that argument.  I suspect he was just 
> tricked by the usual repr(1.15) != "1.15" issue.  and seriously, under-
> standing the various aspects of floats and decimals is utterly trivial 
> compared to all the nearly-magical things you need to understand to be 
> able to do geographical calculations at a sub-millimeter scale.  heck, 
> even sub-kilometer stuff is pretty hard to get right ;-)


I don't have (so far as I know) a 64-bit float available to me.

Some of the lat/long pairs that I have used seem to come out fine, but
some do not.  Because the mathmatics used with them involve complex
equations when determining distance and the like, any error gets
massively compounded before a final result is evident.  Thus, the
numbers must be exact.  That's why I originally asked if Decimal() can
be used instead.  Since it cannot, that's fine, I will just use
Decimal(), assuming that it supports everything that I will need to do
with the numbers.  If not, then I guess I will have to look at something
that uses GMP.

    -- Mike

--
Michael B. Trausch
                    fd0man at gmail.com
Phone: (404) 592-5746
   Jabber IM: fd0man at livejournal.com

Demand Freedom!  Use open and free protocols, standards, and software!
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20061117/a27c3be8/attachment.html>


More information about the Python-list mailing list