How to calculate factorial of double variable (e.g. 3.2!)

How to calculate factorial of double variable (e.g. 3.2!)?

I tried to write the following function but it gave me wrong answer!

1
2
3
4
5
6
7
8
9
10
void factNumber(double number, double &result)
{
    double counter = number;
    result = 1.0;
    while(counter>1)
    {
        result *= counter;
        --counter;
    }
}

it gave me 8.448000 for 3.2! while the calculator gave me 7.7567
Last edited on
The formula n!=n*(n-1)*(n-2)*...*1 only applies when n is a natural number.

http://en.wikipedia.org/wiki/Gamma_function
Last edited on
Topic archived. No new replies allowed.