On Fri, Sep 17, 2021 at 11:12:45AM +0300, Serhiy Storchaka wrote: > 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.
Yes, good point, the things you mention (monotonicity especially) would be an problem. But I don't think it would be a big problem unless the caller was mixing calls to gamma with int and float arguments. If you stick to one or the other, it wouldn't matter. Or if we had automatic simple type dispatch, we could define: def factorial(n: int) -> int: # current integer-only implementation def factorial(x: float) -> float: return x*gamma(x) and nobody would care that the two factorial functions had different performance and precision characteristics. -- Steve _______________________________________________ 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/TLZJIL6S54ELCRVGAFLCNSXWQRDJS2NB/ Code of Conduct: http://python.org/psf/codeofconduct/