Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Aug 12th, 2012  |  syntax: None  |  size: 0.63 KB  |  hits: 12  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Avoiding expensive calculations in Python IRC bot
  2. >>> acos(5e100)
  3. Traceback (most recent call last):
  4.   File "<stdin>", line 1, in <module>
  5. ValueError: math domain error
  6.        
  7. >>> float(10) ** float(100) ** float(100) ** float(1000)
  8. Traceback (most recent call last):
  9.   File "<stdin>", line 1, in <module>
  10. OverflowError: (34, 'Numerical result out of range')
  11. >>> float(5e500) * float(4e1000)
  12. inf
  13.        
  14. import sys
  15.  
  16. def factorial(n):
  17.     fact = 1
  18.     while (n > 0):
  19.         fact = float(fact) * float(n)
  20.         n -= float(1)
  21.         if float(fact) > sys.float_info.max:
  22.             return "Too big"
  23.     return str(fact)
  24.  
  25. print factorial(50e500)