diff options
-rw-r--r-- | functions.py | 15 |
1 files changed, 5 insertions, 10 deletions
diff --git a/functions.py b/functions.py index 8a737ff..7bc5779 100644 --- a/functions.py +++ b/functions.py @@ -226,9 +226,9 @@ def exp(x): return math.exp(float(x)) exp.__doc__ = _('exp(x), return the natural exponent of x. Given by e^x') -def factorial(n): - if type(n) not in (types.IntType, types.LongType): - raise ValueError(_('Factorial only defined for integers')) +def fac(n): + if type(n) not in (types.IntType, types.LongType) or n < 0: + raise ValueError(_('Factorial only defined for non-negative integers')) if n == 0: return 1 @@ -240,14 +240,9 @@ def factorial(n): n -= 1 return res -factorial.__doc__ = _( -'factorial(n), return the factorial of n. \ -Given by n * (n - 1) * (n - 2) * ...') - -def fac(x): - return factorial(x) fac.__doc__ = _( -'fac(x), return the factorial of x. Given by x * (x - 1) * (x - 2) * ...') +'fac(n), returns the factorial of n. \ +Given by n * (n - 1) * (n - 2) * ...') def factorize(x): if not is_int(x): |