1

I'm having an overflow issue, but I'm not sure why since integers are supposed to be unlimited in pytho. The issue is happening at the last line. OverflowError: (34, 'Result too large').

temperature_planet = 200
temperature_atmosphere = 250

epsilon = 0.25
dt = 60*10
heat_capacity = 1E5
insolation = 1370
sigma = 5.67E-8
planet_radius = 6.4E6
while True:
        temperature_planet += dt*(circle*insolation + sphere* epsilon*sigma* temperature_atmosphere**4 - sphere*sigma*temperature_planet**4)/heat_capacity

If I tried initializing temperature_planet with decimal.Decimal I get:
TypeError: unsupported operand type(s) for *: 'float' and 'decimal.Decimal'

2 Answers2

0

It's because you are compiling with python2 instead of with python3.

Check this other question: Maximum and Minimum values for ints

Yunhao Lin
  • 91
  • 9
0

You are working with various floats... epsilon, heat_capacity, sigma, and planet_radius....

Your expression,

dt*(circle*insolation + sphere* epsilon*sigma* temperature_atmosphere**4 - sphere*sigma*temperature_planet**4)/heat_capacity

will always be a float. Why do you expect otherwise?

juanpa.arrivillaga
  • 88,713
  • 10
  • 131
  • 172
  • Is there a way to make my float unbounded?, I tried doing decimal.Decimal(200) when initializing temperature_planet. the issue with that was I couldn't run the function * on a decimal for some reason – user3718247 Dec 20 '20 at 03:39
  • @user3718247 no, `float` objects will **always** be fixed length. You can work with `decimal.Decimal` objects, but they aren't infinite length, just arbitrarily large (and you have to decide on the size beforehand, I believe). What are you actually trying to accomplish? – juanpa.arrivillaga Dec 20 '20 at 03:41
  • I'm trying to save the result for the equation in a variable so I can display it on a scatter chart – user3718247 Dec 20 '20 at 03:42
  • @user3718247 you absolutely can multiply `decimal.Decimal` objects with `*`. If you are actually encountering an error, you should post that error. "For some reason" isn't helpful – juanpa.arrivillaga Dec 20 '20 at 03:42
  • TypeError: unsupported operand type(s) for *: 'float' and 'decimal.Decimal' – user3718247 Dec 20 '20 at 03:44
  • @user3718247 **because you keep using `float` objects** – juanpa.arrivillaga Dec 20 '20 at 03:44
  • @user3718247 but don't post the error in a comment, edit your original question with what you are doing and the exact error. Always post the full error message including the stack trace – juanpa.arrivillaga Dec 20 '20 at 03:45
  • I just initialize all the constants as decimal.Decimal(). That worked. Thanks so much! – user3718247 Dec 20 '20 at 03:48