How does one make the math module spit out actual values without using
engineer or scientific notation?
I get this from <code>print math.pow(2,64)</code>:
1.84467440737e+19
I want this:
18,446,744,073,709,551,616
I'm lazy... I don't want to convert it manually :) 8 2312
On Thu, 26 Jul 2007 15:54:11 -0400, brad wrote:
How does one make the math module spit out actual values without using
engineer or scientific notation?
I get this from <code>print math.pow(2,64)</code>: 1.84467440737e+19
I want this:
18,446,744,073,709,551,616
I'm lazy... I don't want to convert it manually :)
Explicitly converting it to `int` works for me. (Without the 3-digit-
block notation, of course.)
Stargaming wrote:
Explicitly converting it to `int` works for me. (Without the 3-digit-
block notation, of course.)
Thank you!
brad <by*******@gmail.comwrites:
18,446,744,073,709,551,616
I'm lazy... I don't want to convert it manually :)
print 2**64
Paul Rubin wrote:
print 2**64
Ah yes, that works too... thanks. I've settled on doing it this way:
print int(math.pow(2,64))
I like the added parenthesis :)
brad <by*******@gmail.comwrites:
Ah yes, that works too... thanks. I've settled on doing it this way:
print int(math.pow(2,64))
I like the added parenthesis :)
I was surprised to find that gives an exact (integer, not
floating-point) answer. Still, I think it's better to say 2**64
which also works for (e.g.) 2**10000 where math.pow(2,10000)
raises an exception.
Stargaming wrote:
On Thu, 26 Jul 2007 15:54:11 -0400, brad wrote:
>How does one make the math module spit out actual values without using engineer or scientific notation?
I get this from <code>print math.pow(2,64)</code>: 1.84467440737e+19
I want this: 18,446,744,073,709,551,616
I'm lazy... I don't want to convert it manually :)
Explicitly converting it to `int` works for me. (Without the 3-digit-
block notation, of course.)
It's got nothing to do with the math module. Any floating point number,
whether produced by the math module or not, can be converted to a
printable representation using the % operator with a format string:
>>x = 1.84467440737e+19 x
1.84467440737e+19
>>print '%25.3f' % x
18446744073699999744.000
>>print '%12.5e' % x
1.84467e+19
>>print '%12.5g' % x
1.8447e+19
See http://docs.python.org/lib/typesseq-strings.html for all he details.
Gary Herron
On Jul 26, 3:59 pm, Paul Rubin <http://phr...@NOSPAM.invalidwrote:
brad <byte8b...@gmail.comwrites:
Ah yes, that works too... thanks. I've settled on doing it this way:
print int(math.pow(2,64))
I like the added parenthesis :)
I was surprised to find that gives an exact (integer, not
floating-point) answer. Still, I think it's better to say 2**64
which also works for (e.g.) 2**10000 where math.pow(2,10000)
raises an exception.
It *is* binary floating point. Powers of 2 are exactly
representable. Of course, it doesn't give an exact answer in general.
>>int(math.pow(10, 23))
99999999999999991611392L
Dan Bishop <da*****@yahoo.comwrites:
I was surprised to find that gives an exact (integer, not
floating-point) answer. Still, I think it's better to say 2**64
which also works for (e.g.) 2**10000 where math.pow(2,10000)
raises an exception.
It *is* binary floating point. Powers of 2 are exactly
representable. Of course, it doesn't give an exact answer in general.
>int(math.pow(10, 23))
99999999999999991611392L
Oh yikes, good point. math.pow(2,64) is really not appropriate for
what the OP wanted, I'd say. If you want integer exponentiation, then
write it that way. Don't do a floating point exponentiation that just
happens to not lose precision for the specific example.
>>int(math.pow(3,50)) # wrong
717897987691852578422784L
>>3**50 # right
717897987691852588770249L This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: J.Sperlhofer |
last post by:
Good morning, Javascript-Professionals.
I'm looking for an possibility to show a (calculated) 64bit-Number
without exponential notation. I don't want to see exponational notation
within my...
|
by: ben |
last post by:
hello,
i'm following an algorithm book and am stuck on an early excersise in
it, not because of the c programming side of it or even the algorithm
side of it, i don't think, but because of maths....
|
by: yeti349 |
last post by:
Hi, I'm using the following code to retrieve data from an xml file and
populate a javascript array. The data is then displayed in html table
form. I would like to then be able to sort by each...
|
by: RSH |
last post by:
I am still trying to grasp the use of real world Objects and how to
conceptualize them using a business scenerio.
What I have below is an outline that I am wrestling with trying to figure
out a...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
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...
|
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...
|
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,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
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: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
| |