array precision

Michael Hudson mwh at python.net
Thu Feb 7 06:54:03 EST 2002


bldrake1 at yahoo.com (Barry Drake) writes:

> Maybe I'm missing something, but here is what I get:

Well, I'm missing your point.

> Python 2.1.1 (#20, Jul 26 2001, 11:38:51) [MSC 32 bit (Intel)] on
> win32
> Type "copyright", "credits" or "license" for more information.
> IDLE 0.8 -- press F1 for help
> >>> import math
> >>> n = 10
> >>> nf = 10.0
> >>> a = 1.0
> >>> b = 0.5
> >>> a/n
> 0.10000000000000001
> >>> b + a/n
> 0.59999999999999998
> >>> a/nf
> 0.10000000000000001
> >>> b + a/nf
> 0.59999999999999998
> >>> 
> 
> Python does double precision floats only (see Python Essential
> Reference 2nd ed. by David Beazley, p.23).

But you can have arrays (as in, objects of type array.ArrayType) that
store C single floats.  Which was Jason's point.

> Python implements IEEE 754: 17 digits of precision with exponent in
> -308 to 308.

Oh No It Doesn't.  Python uses (for the objects of type
types.FloatType) whatever the C compiler that compiled it called
"double".  This may be IEEE 754 doubles on the platforms you've used,
but there's certainly no guarantee of that (e.g. Crays, IBM boxes (I
think)).

>          float     double
> python   64 bits   64 bits
> C        32 bits   64 bits

"python double" is meaningless.

> BTW, you might want to check out the Numeric module in the NumPy
> distribution at http://numpy.sourceforge.net.

That lets you store floats or doubles too.

Cheers,
M.

-- 
  I'm about to search Google for contract assassins to go to Iomega
  and HP's programming groups and kill everyone there with some kind
  of electrically charged rusty barbed thing.
                -- http://bofhcam.org/journal/journal.html, 2002-01-08



More information about the Python-list mailing list