float64 print digits

U

Ulrich Dorda

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: 1.2345678912345679000000000e+000


Now I try to use float64 to get more digits
>>> z=zeros(3,float64)
>>> z[0] 0.0
>>> type(z[0])
>>> z[0]=1.23456789123456789123456789
>>> type(z[0])
>>> 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?

Thank you very much in advance,

Ulrich
 
P

Peter Otten

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:1.2345678912345679000000000e+000


Now I try to use float64 to get more digits
z=zeros(3,float64)
z[0] 0.0
type(z[0])
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])
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
 
G

Grant Edwards

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:
1.2345678912345679000000000e+000


Now I try to use float64 to get more digits

You're already using 64 bit floats (which have about 15
significant digits).
z=zeros(3,float64)
z[0] 0.0
type(z[0])
z[0]=1.23456789123456789123456789
type(z[0])
print "%35.25e" %z[0]
1.2345678912345679000000000e+000

This cuts the digits just like the 32bit case.

What 32-bit case? A 32-bit float only has 7-8 significant
digits.
Can anyone please help me get more digits?

Use the decimal module?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,754
Messages
2,569,527
Members
45,000
Latest member
MurrayKeync

Latest Threads

Top