##### OverflowError: math range error
 OverflowError: math range error Nick_helps Unladen Swallow Posts: 2 Threads: 1 Joined: Jul 2018 Reputation: Jul-26-2018, 08:45 PM (This post was last modified: Jul-26-2018, 08:46 PM by Nick_helps.) Hi, I am very new to Python, but have good php knowledge. I need to save and print a big number. How can I do that? Here is my code ```import math from decimal import Decimal print(Decimal(math.pow(2, 1024)))```I m getting "OverflowError: math range error" Thanks, Nick Reply Vysero Wafer-Thin Wafer Posts: 85 Threads: 12 Joined: May 2018 Reputation: Jul-26-2018, 08:51 PM 709.78271 is the largest value I can compute the exp of on my machine, I think the numpy module has the ability to handle large numbers Reply Nick_helps Unladen Swallow Posts: 2 Threads: 1 Joined: Jul 2018 Reputation: Jul-26-2018, 08:52 PM (This post was last modified: Jul-26-2018, 09:18 PM by Nick_helps.) Got it. Converted `math.pow(2, 1024)` to `2**1024` and it worked. (Jul-26-2018, 08:51 PM)Vysero Wrote: 709.78271 is the largest value I can compute the exp of on my machine, I think the numpy module has the ability to handle large numbers Thanks fro the reply. How can I go about it using numpy module. I searched, but only found examples related to arrays. Reply casevh Not Blown Up Yet Posts: 52 Threads: 0 Joined: Oct 2016 Reputation: Jul-27-2018, 03:19 AM If you are working with integers, you'll find that Python includes arbitrary precision integers. You generally want to avoid working with floats (what the math module generally does.) The following are useful for working with integers: ```>>> b=100 >>> a+b 12445 >>> a-b 12245 >>> a*b 1234500 >>> a/b # Floating point division in Python 3; varies in Python 2 123.45 >>> a//b # Integer division; in both Python 2 and 3 123 >>> a % b # Remainder 45 >>> divmod(a,b) # Returns both Integer division and Remainder (123, 45) >>> 2 ** 5 # Exponentiation 32```While numpy is useful for many purposes, working with large numbers isn't its strong suit. Depending on what you want to do, you may want to use mpmath or gmpy2. Disclaimer: I maintain gmpy2 when I have time. Reply wavic So-and-so of the Yard Posts: 2,955 Threads: 48 Joined: Sep 2016 Reputation: Jul-29-2018, 11:29 AM Python can work with arbitrary big numbers. I don't know how it's doing that but I have used it to work with integers with few million digits. Try gmpy2 for faster processing. "As they say in Mexico 'dosvidaniya'. That makes two vidaniyas." https://freedns.afraid.org Reply

 Possibly Related Threads… Thread Author Replies Views Last Post Index out of range error standenman 0 125 May-22-2023, 10:35 PM Last Post: standenman [split] Getting Index Error - list index out of range krishna 2 2,082 Jan-09-2021, 08:29 AM Last Post: buran Cycle through Numpy range within another range(?) Zero01 0 1,713 Jul-31-2020, 02:37 PM Last Post: Zero01 Unable to understand reason for error IndexError: tuple index out of range rajat2504 4 53,147 Dec-09-2016, 11:04 AM Last Post: Kebap

Forum Jump:

### User Panel Messages

##### Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020