TIL:When n + 1 == n in python?

shaikhul

Shaikhul Islam

Posted on February 15, 2019

TIL:When n + 1 == n in python?

Today I was looking to python docs for doctest and found following

if n+1 == n:  # catch a value like 1e300
    raise OverflowError("n too large")

Immediately I opened the shell and try it:

>>> from math import exp
>>> n = exp(300)
>>> n
1.9424263952412558e+130
>>> n + 1 == n
True

TIL n+1 == n! and how to guard against a ridiculously large number

💖 💪 🙅 🚩
shaikhul
Shaikhul Islam

Posted on February 15, 2019

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related

TIL:When n + 1 == n in python?
python TIL:When n + 1 == n in python?

February 15, 2019