[issue8692] Use divide-and-conquer for faster factorials

Alexander Belopolsky report at bugs.python.org
Wed May 12 02:14:19 CEST 2010


Alexander Belopolsky <belopolsky at users.sourceforge.net> added the comment:

On Tue, May 11, 2010 at 7:42 PM, Daniel Stutzbach
<report at bugs.python.org> wrote:
..
> Isn't that adding an extra check in every case to speed up a
> you-can't-seriously-expect-that-to-work corner case?
>

The check is cheap - just a machine integer comparison, so I would not
even take that cost into account.   In my view math.factorial() is
primarily of interest in educational settings where it is quite likely
that someone would be curious enough to pass sys.maxsize to it.

The main value in setting a theoretically justified limit is that
overflow exception can carry a meaningful message, e.g. "factorial
result would have too many digits", rather than an unhelpful "Python
int too large to convert to C long".

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue8692>
_______________________________________


More information about the Python-bugs-list mailing list