[Issue 13371] std.math.factorial

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Wed Aug 27 02:04:58 PDT 2014


https://issues.dlang.org/show_bug.cgi?id=13371

--- Comment #4 from bearophile_hugs at eml.cc ---
(In reply to Don from comment #2)

> Exactly! And I seriously doubt that factorial is commonly used.

I don't agree. I am using it. It's a basic common algorithm. Asking people to
rewrite it in every little script of project is unwise. Python standard library
shows it's a good idea to put it in. Other languages like Julia have it in the
std lib.


> Eg even for calculating permutations and combinations, using factorial is
> not a good method.

This is not important.


> And for BigInt, iterated multiplication isn't a good way of caclulating
> factorials.

Right, for BigInt you can add a different specialization later for bigints.


> You need to group multiple factors together, so that the
> multiplies are of similar length.

There are good algorithms to compute large factorials quickly. But having a
basic common algorithm is right.


> And finally, your code reports factorial(2) == 3, which isn't a good start,

I haven't tested it, it's just example code to show what I meant.

--


More information about the Digitalmars-d-bugs mailing list