float / double support in Python?

Carlos Ribeiro cribeiro at mail.inet.com.br
Fri Feb 7 01:31:55 CET 2003


On Thursday 06 February 2003 10:22 pm, Brandon Van Every wrote:
> float and double support is very critical to ease-of-use for my 3D graphics
> programming work.  How does Python fare for number crunching?  I'm not so
> much concerned with efficiency, I'm not expecting much, but rather syntax,
> universality of support on different platforms, or other headaches /
> gotchas.  For instance it's not acceptable to represent a float /double as
> a string, it has to be 4 bytes / 8 bytes.  I heard at one point that people
> were considering abolishing floating point support from the language?

1) Python excels at number crunching. Numeric Python, or NumPy, is *the* 
standard library for this, and I think that you don't have any reason to be 
worried about 'balkanization'. It implements primitives for a lot of 
heavy-duty math stuff with matrices, and I bet that you'd be hard-pressed to 
come up with a faster implementation for some of this stuff, even using pure 
C. The only catch is that you may need to include NumPy with your installer, 
but then this is true in a sense or other for any environment you choose - 
there will always be DLLs and stuff like that to include.

2) The standard Python implementation wraps floats in a Python object. This 
gives you automatic memory management and etc., but may cause a performance 
hit. On the other hand, NumPy is highly optimized - you pay the object 
encapsulation price only once for the entire matrix. Depending upon your 
needs, you may also use the standard array library, that efficiently packs 
data in a array. Check out the documentation.

3) There was a lot of discussion a long time ago about changing the semantics 
of the division operator (/). I'm not sure how did it end - I didn't follow 
the group for one year and just joined back two weeks ago. I assume that it 
didn't went further than a few flamewars :-)

BTW, there are good reasons for the division operator to be so controversial. 
You do high speed floating point calculations where absolute precision is not 
critical - a few bits lost by rounding don't make much of a difference most 
of the time. People who run financial calculations have a different 
requirement - precision is an absolute must, and that's why they resort to 
stuff such as BCD, fixed-point binary or even string representations.


Carlos Ribeiro
cribeiro at mail.inet.com.br





More information about the Python-list mailing list