float64 print digits
Peter Otten
__peter__ at web.de
Fri Mar 2 12:15:10 CET 2007
Ulrich Dorda wrote:
[Warning: I'm no expert and don't have numpy installed]
> I need a pytho nscript to read numbers(with loads of digits) from a
> file, do some basic math on it and write the result out to another file.
>
> My problem: I don't get python to use more digits:
>
> In order to try this I type:
>
> The normal precision one:
> >>> from numpy import *
> >>> x=1.23456789123456789123456789
> >>> print "%35.25e" %x
> 1.2345678912345679000000000e+000
>
>
> Now I try to use float64 to get more digits
>
> >>> z=zeros(3,float64)
> >>> z[0]
> 0.0
> >>> type(z[0])
> <type 'numpy.float64'>
> >>> z[0]=1.23456789123456789123456789
The right side of the assignment is a float, so the extra digits would
already be lost before you get a chance to convert to float64. But then
Python's float is a C double and should already use 64 bits...
> >>> type(z[0])
> <type 'numpy.float64'>
> >>> print "%35.25e" %z[0]
> 1.2345678912345679000000000e+000
>
> This cuts the digits just like the 32bit case.
>
> Can anyone please help me get more digits?
gmpy?
Peter
More information about the Python-list
mailing list