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 mark.dickinson
Recipients ajaksu2, alanmcintyre, avalind, dtorp, ilan, jafo, mark.dickinson, phr, rhettinger
Date 2008-03-18.18:38:00
SpamBayes Score 0.283057
Marked as misclassified No
Message-id <>
I'm not opposed to adding factorial somewhere, and it doesn't seem
as though anyone else is actively opposed to factorial either.  The
problem is working out where best to put it.  To my inexperienced
eyes, it feels wrong to add it as an int/long method, though I'm
having trouble figuring out exactly why it feels wrong.  It doesn't
fit well with the stuff in the math module either, as Raymond
has pointed out.

There are other integer -> integer functions that I'd consider just
as fundamental and useful as factorial, for a programming language
that has arbitrary-precision integers.  Examples are the integer
square root (i.e. int(floor(sqrt(n)))), or the number of bits in 
an integer (int(floor(log(n, 2))).  I've needed both
of these much more often than factorial.  If the powers that be
accepted a request to add such functions, would they also naturally
become integer methods?

And supposing that gcd were added some day, shouldn't it be in the
same place as factorial?

As to implementation, I'd probably avoid PrimeSwing on the basis
that the added complexity, and cost for future maintainers, just
isn't worth it.  The usual recursive algorithm
(writing n! as (n*(n-2)*(n-4)*...) * ((n-1)*(n-3)*...), and then
applying similar breakdowns to the subproducts) is probably good
enough, together with some caching of small results.

I can volunteer to try to implement this sometime before the 2.6/3.0
Date User Action Args
2008-03-18 18:38:01mark.dickinsonsetspambayes_score: 0.283057 -> 0.283057
recipients: + mark.dickinson, rhettinger, jafo, phr, dtorp, alanmcintyre, ajaksu2, avalind, ilan
2008-03-18 18:38:01mark.dickinsonsetspambayes_score: 0.283057 -> 0.283057
messageid: <>
2008-03-18 18:38:00mark.dickinsonlinkissue2138 messages
2008-03-18 18:38:00mark.dickinsoncreate