You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
math.factorial doc should mention integer return type #69921
At minimum, shouldn't the first sentence be "Return x factorial as an int."? I haven't tested on all Python versions, but math.factorial on 2.7 and 3.2 definitely return int (or long in Python 2 when necessary).
I agree. In testing, I discovered this bug
>>> factorial(decimal.Decimal(5.2))
120
I don't know if this is a glitch in factorial or Decimal.
I also noticed
>>> fac(fractions.Fraction(4, 1))
Traceback (most recent call last):
File "<pyshell#10>", line 1, in <module>
fac(fractions.Fraction(4, 1))
TypeError: an integer is required (got type Fraction)
Perhaps this is due to no __int__ method.
Yep, that's definitely wrong. If we want to behave the same way as for float, we should accept only integral Decimal values. (Though I'm not much of a fan of the float behaviour: I would have preferred math.factorial not to accept floats at all.)
mine0901 commented on Dec 2, 2015
mine0901mannequin
Mannequin
More actions
States that math.factorial(x) returns x factorial as an integer.
New changeset 4612671 by Cheryl Sabella (Akshay Sharma) in branch 'master': bpo-25735: math.factorial doc should mention integer return type (GH-6420) 4612671
Activity
JohnYeung commentedon Nov 25, 2015
The math module docs state
Except when explicitly noted otherwise, all return values are floats.
But math.factorial isn't what I would call explicit about returning int:
At minimum, shouldn't the first sentence be "Return x factorial as an int."? I haven't tested on all Python versions, but math.factorial on 2.7 and 3.2 definitely return int (or long in Python 2 when necessary).
terryjreedy commentedon Nov 27, 2015
mdickinson commentedon Nov 28, 2015
[Terry]
>>> factorial(decimal.Decimal(5.2)) 120Yep, that's definitely wrong. If we want to behave the same way as for float, we should accept only integral Decimal values. (Though I'm not much of a fan of the float behaviour: I would have preferred math.factorial not to accept floats at all.)
mine0901 commentedon Dec 2, 2015
States that math.factorial(x) returns x factorial as an integer.
csabella commentedon Mar 15, 2018
Should the documentation patch for this be converted to a PR or does this need to change to a bug issue to address Mark's concerns?
Thanks!
mdickinson commentedon Mar 15, 2018
I think so, yes. How about we open a new issue for the factorial(Decimal(...)) behaviour, and keep this one focused on the original reported issue?
csabella commentedon Mar 15, 2018
Sounds good. Thanks, Mark.
@mine0901, would you like to open a Github pull request for your patch? Thanks!
mdickinson commentedon Mar 15, 2018
I opened bpo-33083, and copied the nosy list from this issue across.
csabella commentedon May 31, 2019
New changeset 4612671 by Cheryl Sabella (Akshay Sharma) in branch 'master':
bpo-25735: math.factorial doc should mention integer return type (GH-6420)
4612671
csabella commentedon May 31, 2019
@John.Yeung, thank you for the report. @mine0901, thanks for the initial patch and @akshaysharma, thank you for the PR.
miss-islington commentedon May 31, 2019
New changeset fc3b843 by Miss Islington (bot) in branch '3.7':
bpo-25735: math.factorial doc should mention integer return type (GH-6420)
fc3b843