5 ms·
> It works for int, float, BigInteger Actually it is incorrect for floats. For non integer types, the factorial is given by the gamma function [1]. So, the fa
by kanak 16y ago
> It works for int, float, BigInteger
Actually it is incorrect for floats.
For non integer types, the factorial is given by the gamma function [1]. So, the factorial of 3.5 is Gamma(2.5) which is 3.3325 [2] not 6 as your function suggests.
[1] http://en.wikipedia.org/wiki/Gamma_function http://en.wikipedia.org/wiki/Gamma_function
[2] http://www.wolframalpha.com/input/?i=gamma%283.5%29 http://www.wolframalpha.com/input/?i=gamma%283.5%29
- sesqu 16y agoYes but no. For non-integers, the factorial isn't defined. Just because the gamma function is an analytic continuation (read: generalization) of the factorial doesn't mean you can go ahead and return anything other than an error code in those cases.