
Untitled
By: a guest on
Aug 12th, 2012 | syntax:
None | size: 0.63 KB | hits: 12 | expires: Never
Avoiding expensive calculations in Python IRC bot
>>> acos(5e100)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: math domain error
>>> float(10) ** float(100) ** float(100) ** float(1000)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
OverflowError: (34, 'Numerical result out of range')
>>> float(5e500) * float(4e1000)
inf
import sys
def factorial(n):
fact = 1
while (n > 0):
fact = float(fact) * float(n)
n -= float(1)
if float(fact) > sys.float_info.max:
return "Too big"
return str(fact)
print factorial(50e500)