Welcome to the Java Programming Forums

The professional, friendly Java community. 21,500 members and growing!

The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.

>> REGISTER NOW TO START POSTING

# Thread: Is it possible to get factorial of negative number

2. ## Re: Is it possible to get factorial of negative number

Technically, no. However, there is something called the Gamma function which is an extension of the factorial function.

See: Gamma function - Wikipedia, the free encyclopedia

3. ## Re: Is it possible to get factorial of negative number

Technically there is.

There is such a thing as .5!

Since (x-1)! = x!/x

(-.5)! = (.5)!/.5 = 2 * (.5)!

However, anything less than -.5 has no factorial as it'd be dividing by 0.

i.e. -1! = 0!/0 = 1/0
-2! = -(1/0) /0

I didn't even know about decimal factorials, but I tried it with my calculator and it found that .5 factorial was valid, so I tried -.5 factorial and it worked too.

4. ## Re: Is it possible to get factorial of negative number

Originally Posted by javapenguin
Technically there is.

There is such a thing as .5!

Since (x-1)! = x!/x

(-.5)! = (.5)!/.5 = 2 * (.5)!

However, anything less than -.5 has no factorial as it'd be dividing by 0.

i.e. -1! = 0!/0 = 1/0
-2! = -(1/0) /0

I didn't even know about decimal factorials, but I tried it with my calculator and it found that .5 factorial was valid, so I tried -.5 factorial and it worked too.
Likely you're calculator is actually computing the gamma function. The gamma function exists for all complex numbers except non-negative integers.

It's been roughly defined as (n-1)!, though the true definition is an improper integral (see the wikipedia article).

The definition of the classical factorial function only exists for positive real numbers, with a special exception that 0! = 1.