Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKunal Arora <kunalarora.135@gmail.com>2014-03-19 08:49:56 (GMT)
committer Kunal Arora <kunalarora.135@gmail.com>2014-03-19 08:49:56 (GMT)
commit75ca46b19a80ec6d8b42f81f61187f7c7452f29b (patch)
treed4cdb74211254a8bd8ab892966f20d10bda8233e
parent7b53180d699627c887ae20361e0d40c8e32d895a (diff)
solves ticket #3531 and gives error for factorial of negative integersfactorial
-rw-r--r--functions.py15
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):