# array precision

Barry Drake bldrake1 at yahoo.com
Wed Feb 6 10:23:53 EST 2002

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

Python 2.1.1 (#20, Jul 26 2001, 11:38:51) [MSC 32 bit (Intel)] on
win32
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).  Python implements IEEE
754: 17 digits of precision with exponent in -308 to 308.

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

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

Barry Drake

"Jason Orendorff" <jason at jorendorff.com> wrote in message news:<mailman.1012956250.23108.python-list at python.org>...
> Hugo Martires writes:
> > suposing that n=10 we get: myArray[0] = 0.600000023 ("something
> > like this")
> >
> > but if i do: myArray[i] + (1.0/n) it give's me 0.6
> >
> > what's the problem of the array, and how can i solve this ?
>
> It's only half of the normal precision.  From the documentation:
>
>     The following type codes are defined:
>         Type code   C Type             Minimum size in bytes
>         'f'         floating point     4
>         'd'         floating point     8
>
> Try using 'd' instead of 'f'.
>
> ## Jason Orendorff    http://www.jorendorff.com/

```