17.09.21 05:23, Steven D'Aprano пише:
>>>> factorial(23) == better_factorial(23)
> False
> 
> The problem is that since floats only have about 17 significant figures 
> or so, once you get to 23! the gamma function doesn't have enough 
> precision to give an exact answer. Of course that's easily fixable. 
> (Only call gamma if the input argument is a float.)

It is not even easily fixable.

First, the resulting function which uses different algorithms for
integers and non-integers can be non-monotonic.

Second, factorial() supports large arguments for which gamma() raises an
overflow error.

Third, it will have non-uniform computational complexity. The time of
calculating gamma() is virtually constant, but the time of calculating
factorial() grows with increasing argument.

_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/CW7DINDWDML373EC3OYNME4KEEC7XU2S/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to