473,385 Members | 1,720 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

float64 print digits

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
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?

Thank you very much in advance,

Ulrich
Mar 2 '07 #1
2 6186
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
Mar 2 '07 #2
On 2007-03-02, Ulrich Dorda <ul**********@cern.chwrote:
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
You're already using 64 bit floats (which have about 15
significant digits).
>z=zeros(3,float64)
z[0]
0.0
>type(z[0])
<type 'numpy.float64'>
>z[0]=1.23456789123456789123456789
type(z[0])
<type 'numpy.float64'>
>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?

--
Grant Edwards grante Yow! What a
at COINCIDENCE! I'm an
visi.com authorized "SNOOTS OF THE
STARS" dealer!!
Mar 2 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Rim | last post by:
Hi, >>> print '%x' % 54 36 >>> print '%b' % 54 Traceback (most recent call last): File "<stdin>", line 1, in ? ValueError: unsupported format character 'b' (0x62) at index 1 >>>
12
by: neutrino | last post by:
Greetings to the Python gurus, I have a binary file and wish to see the "raw" content of it. So I open it in binary mode, and read one byte at a time to a variable, which will be of the string...
4
by: ai lian | last post by:
When I use printf to print a large double number, the result is not the same as the original input number. For example: double num=899999999999.894400; printf("%lf\n",num); The output is:...
3
by: janice3 | last post by:
In my homework i need to write a function that inputs and integer between 1 and 32767 and prints it as a series of digits, each pair of which is separated by two spaces. for example 3412 should print...
14
by: mosi | last post by:
Problem: how to get binary from integer and vice versa? The simplest way I know is: a = 0100 a 64 but: a = 100 (I want binary number) does not work that way.
13
by: ramif | last post by:
Is there a way to print extended ASCII in C?? I tried to code something, but it only displays strange symbols. here is my code: main() { char chr = 177; //stores the extended ASCII...
5
by: dmitrey | last post by:
hi all, could you inform how to print binary number? I.e. something like print '%b' % my_number it would be nice would it print exactly 8 binary digits (0-1, with possible start from 0) ...
0
by: castironpi | last post by:
On May 7, 3:31 pm, Mensanator <mensana...@aol.comwrote: ) for a in range( 10 ) ] ) 00000000 00000001 00000010 00000011 00000100 00000101 00000110
45
by: hank | last post by:
I have this code here, it converts decimal numbers to binary. There is one problem. The output is printed 'in reverse' and I have no clue at all how to solve this problem. Output of program: ...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.