1

In Python, 1e400 evaluates to inf, but 10**400 prints out just fine. Theoretically, 1e(x) is supposed to be 10**x, but why and when does this break down?

In a related vein, 1e5 == 10**5 evaluates to True, while 1e40 == 10**40 evaluates to False. Then while int(1e22) shows a 1 with 22 zeros, int(1e23) shows 99999999999999991611392. Meanwhile, 10**100000 is still printing out just fine. (Although ten to the million is freezing up my computer, it still isn't giving me an overflow error.)

What's behind this inaccuracy? Is 1e() inferior to 10**()?

Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
ichthyophile
  • 107
  • 8
  • 1
    I think OP is right that this not a duplicate of the 'Is floating point math broken' post, since this requires knowledge of float literals and Python formatting. This question is probably a better duplicate of [Python why is 10e26 != 10**26 ? (Floating point inaccuracy?)](https://stackoverflow.com/questions/54353247/python-why-is-10e26-1026-floating-point-inaccuracy) – kcsquared Feb 27 '22 at 11:35

1 Answers1

3

You are using different types

print (type(1e5))    # float
print (type(10**5))  # int

Int can get arbitrarily big in python .. float ... not so much.

Patrick Artner
  • 50,409
  • 9
  • 43
  • 69