[Issue 13371] std.math.factorial
via Digitalmars-d-bugs
digitalmars-d-bugs at puremagic.com
Wed Aug 27 01:04:40 PDT 2014
https://issues.dlang.org/show_bug.cgi?id=13371
--- Comment #2 from Don <clugdbug at yahoo.com.au> ---
(In reply to hsteoh from comment #1)
> auto factorial(T)(in T n) {
> import std.mathspecial : gamma;
> return gamma(n+1);
> }
Exactly! And I seriously doubt that factorial is commonly used. It's a widely
used _example_, but it's hard to come up with applications for it. Eg even for
calculating permutations and combinations, using factorial is not a good
method.
And for BigInt, iterated multiplication isn't a good way of caclulating
factorials. You need to group multiple factors together, so that the multiplies
are of similar length.
And finally, your code reports factorial(2) == 3, which isn't a good start,
--
More information about the Digitalmars-d-bugs
mailing list