473,396 Members | 2,070 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,396 software developers and data experts.

why does math.pow yields OverflowError (while python itself cancalculate that large number)

What is the reason math.pow yields OverflowError while python itself
can
calculate these large numbers. e.g:
>>import math
math.pow(100, 154)
1e+308
>>math.pow(100, 155)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
OverflowError: math range error
>>eval(('100*'* 155)[:-1])
10000000000000000000000000000000000000000000000000 000000000
00000000000000000000000000000000000000000000000000 000000000
00000000000000000000000000000000000000000000000000 000000000
00000000000000000000000000000000000000000000000000 000000000
00000000000000000000000000000000000000000000000000 000000000
0000000000000000L
>>>
Oct 23 '08 #1
5 4377
On Oct 23, 8:21*pm, Tzury Bar Yochay <Afro.Syst...@gmail.comwrote:
What is the reason math.pow yields OverflowError while python itself
can
calculate these large numbers. e.g:
>import math
math.pow(100, 154)
1e+308
>math.pow(100, 155)

Traceback (most recent call last):
* File "<stdin>", line 1, in <module>
OverflowError: math range error>>eval(('100*'* 155)[:-1])

10000000000000000000000000000000000000000000000000 000000000
00000000000000000000000000000000000000000000000000 000000000
00000000000000000000000000000000000000000000000000 000000000
00000000000000000000000000000000000000000000000000 000000000
00000000000000000000000000000000000000000000000000 000000000
0000000000000000L
Because math.pow returns a float; 100 ** 155 won't fit in a float.
Oct 23 '08 #2
Because math.pow returns a float; 100 ** 155 won't fit in a float.

Sure that is the reason.
May I rephrase, my question:
Why not returning another type as long as we can calculate it?
After all, math module is likely to be used on large numbers as well.
Oct 23 '08 #3
Tzury Bar Yochay wrote:
>Because math.pow returns a float; 100 ** 155 won't fit in a float.

Sure that is the reason.
May I rephrase, my question:
Why not returning another type as long as we can calculate it?
After all, math module is likely to be used on large numbers as well.
Because it's very complicated to get it right. The math module is a thin
wrapper around the platform math library. It took Mark and me very long
to get cmath and math right for floats (C doubles). Arbitrary precision
and arbitrary length numbers are a different story. You have to use 3rd
party tools for those. The standard library aims to solve common
problems, not special problems.

Christian

Oct 23 '08 #4
On Oct 23, 9:24*pm, Tzury Bar Yochay <Afro.Syst...@gmail.comwrote:
Because math.pow returns a float; 100 ** 155 won't fit in a float.

Sure that is the reason.
May I rephrase, my question:
Why not returning another type as long as we can calculate it?
After all, math module is likely to be used on large numbers as well.
The math module is intended to replicate the functionality found in
math.h in the C Standard Library; that's it, no more, no less. There
are other libraries if you want more-than-float precision.
Oct 23 '08 #5
On Thu, 23 Oct 2008 02:21:36 -0700, Tzury Bar Yochay wrote:
>>>eval(('100*'* 155)[:-1])
10000000000000000000000000000000000000000000000000 000000000
00000000000000000000000000000000000000000000000000 000000000
00000000000000000000000000000000000000000000000000 000000000
00000000000000000000000000000000000000000000000000 000000000
00000000000000000000000000000000000000000000000000 000000000
0000000000000000L
>>>>
This can be written more straigth forward as ``100**155`` or
``pow(100, 155)``. No need for `eval()`\ing a string.

Ciao,
Marc 'BlackJack' Rintsch

Oct 23 '08 #6

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

Similar topics

3
by: Paolo Alexis Falcone | last post by:
Whenever I try to access a table with many rows using PgSQL's fetchall(), this happens: >>> from pyPgSQL import PgSQL >>> db = PgSQL.connect("192.168.0.8:5432:whitegold","dondon","dondon") >>>...
11
by: Thomas Guettler | last post by:
Hi, Simple excerise: You have a sorted list of integers: l= and you should fill all gaps: result ==
18
by: kk | last post by:
I read this mailing list fairly often, and I am always amazed at what I learn (even not related to Python). I am relatively new to Python. I make my living developing mostly in Java. Python was a...
2
by: Luke | last post by:
Hi, I'm getting an OverflowError which doesn't make sense to me. Is this a python bug? Traceback (most recent call last): File "/home/demoau/lib/py/omniORB/__init__.py", line 717, in...
89
by: Radioactive Man | last post by:
In python 2.3 (IDLE 1.0.3) running under windows 95, I get the following types of errors whenever I do simple arithmetic: 1st example: >>> 12.10 + 8.30 20.399999999999999 >>> 1.1 - 0.2...
6
by: ng_mr | last post by:
No, not a question about "banker's rounding" or whatever it's called. I want to round a double to the nearest 100th, so I perform the following: // original is a double double result =...
113
by: John Nagle | last post by:
The major complaint I have about Python is that the packages which connect it to other software components all seem to have serious problems. As long as you don't need to talk to anything outside...
1
by: khgoh | last post by:
Hi, Need help for the error "OverflowError: long int too large to convert to int" while reading a zip file content. Python version: Python 2.4.1 (#1, Sep 13 2005, 00:39:20) on linux2 Code...
0
by: gdetre | last post by:
Dear all, I'm trying to get a large, machine-generated regular expression (many thousands of characters) to work in Python on a Mac (running Leopard), and I keep banging my head against this...
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: 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...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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...
0
jinu1996
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...
0
tracyyun
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 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.