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


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: Is it possible to get factorial of negative number

  1. #1
    Junior Member
    Join Date
    Feb 2011
    Posts
    7
    My Mood
    Bored
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Is it possible to get factorial of negative number

    I was wondering about this.Please help


  2. #2
    Super Moderator helloworld922's Avatar
    Join Date
    Jun 2009
    Posts
    2,896
    Thanks
    23
    Thanked 619 Times in 561 Posts
    Blog Entries
    18

    Default 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. #3
    Banned
    Join Date
    May 2010
    Location
    North Central Illinois
    Posts
    1,631
    My Mood
    Sleepy
    Thanks
    390
    Thanked 112 Times in 110 Posts

    Default 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. #4
    Super Moderator helloworld922's Avatar
    Join Date
    Jun 2009
    Posts
    2,896
    Thanks
    23
    Thanked 619 Times in 561 Posts
    Blog Entries
    18

    Default Re: Is it possible to get factorial of negative number

    Quote Originally Posted by javapenguin View Post
    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.

Similar Threads

  1. [ask] about sorting number.
    By bontet in forum What's Wrong With My Code?
    Replies: 1
    Last Post: October 30th, 2010, 02:07 PM
  2. Need this to end when a negative number is entered
    By ponyexpress in forum What's Wrong With My Code?
    Replies: 1
    Last Post: April 28th, 2010, 09:02 AM
  3. letter to number
    By silverspoon34 in forum Java Theory & Questions
    Replies: 1
    Last Post: November 27th, 2009, 06:01 AM
  4. Evaluating to negative zero
    By helloworld922 in forum Java Theory & Questions
    Replies: 6
    Last Post: June 25th, 2009, 02:34 PM
  5. [SOLVED] How to make a integer negative if it meets a certain criteria?
    By Lizard in forum What's Wrong With My Code?
    Replies: 3
    Last Post: May 14th, 2009, 02:27 PM