Decimal() instead of float?

Fredrik Lundh fredrik at pythonware.com
Wed Nov 15 06:48:27 EST 2006


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 ;-)

</F>




More information about the Python-list mailing list