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 2330
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*******@gmai l.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*******@gmai l.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,1000 0)
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
184467440736999 99744.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.i nvalidwrote:
brad <byte8b...@gmai l.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,1000 0)
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))
999999999999999 91611392L
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,1000 0)
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(1 0, 23))
999999999999999 91611392L
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
717897987691852 578422784L
>>3**50 # right
717897987691852 588770249L 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 binary numbers.
To demonstrate my problem, try this code:
----
var binNumber = Math.pow(2,61);
|
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. i don't really
understand what is expected, or really what the question means. could
anyone explain what the question's after please?
any help much appreciated.
thanks, ben.
Prove an upper bound on the number of machine instructions required to
|
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 column. Once the
array elements are split, what is the best way to sort them? Thank you.
//populate data object with data from xml file.
//Data is a comma delimited list of values
var jsData = new Array();
jsData = {lib: "#field...
|
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 class structure:\
Top level Objects:
Companies
Employees
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
| |
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
| |
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |