This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author belopolsky
Recipients belopolsky, mark.dickinson, rhettinger, stutzbach
Date 2010-05-11.22:33:29
SpamBayes Score 2.0543552e-05
Marked as misclassified No
Message-id <1273617211.59.0.766982968625.issue8692@psf.upfronthosting.co.za>
In-reply-to
Content
I also started to wonder if a tighter upper limit for an acceptable argument can be found.

In discussion of issue2138 I saw the following exchange:

"""
> Should there be some upper limit on the argument math.factorial would
take?

I'd say not.  Any such limit would be artificial, and an arbitrary
choice.  Just let the natural time and space requirements be the
limiting factor.
""" - msg62541 - Mark Dickinson -

Still, the original and proposed implementations bail out if n is larger than system LONG_MAX.  This is not a limitation because because the result for LONG_MAX! would exceed the number of digits that python long integer can hold.

It seems to me that the value of n for which number of digits will exceed sys.maxsize can be estimated fairly accurately using Stirling formula.  Only two values are relevant in practice - one for sys.maxsize = 2**63-1 and the other for sys.maxsize = 2**31-1.  These values can be hardcoded and factorial can quickly report the case when n! will exceed maxsize digits instead of hanging until memory is exhausted.
History
Date User Action Args
2010-05-11 22:33:31belopolskysetrecipients: + belopolsky, rhettinger, mark.dickinson, stutzbach
2010-05-11 22:33:31belopolskysetmessageid: <1273617211.59.0.766982968625.issue8692@psf.upfronthosting.co.za>
2010-05-11 22:33:29belopolskylinkissue8692 messages
2010-05-11 22:33:29belopolskycreate