Re: Issues with factorial operator - Mailing list pgsql-hackers

From Dann Corbit
Subject Re: Issues with factorial operator
Date
Msg-id D425483C2C5C9F49B5B7A41F89441547010006FE@postal.corporate.connx.com
Whole thread Raw
In response to Re: Issues with factorial operator  ("Cui Shijun" <rancpine@gmail.com>)
Responses Re: Issues with factorial operator
List pgsql-hackers
> -----Original Message-----
[snip]
> Hum... I think there is a little improvement: when n is too large,(say
> n>10, 000) we can use Stirling's formula to get the estimated value of
> n!    :-)

Or (rather) the log base 10 of Stirling's formula.  The n! estimator
will overflow for sure, unless we take the log of it.

Rather than all that, why not just figure out what the largest number of
digits we will allow is and then don't allow inputs that will generate
more than that.

The program I gave could be run with the target accuracy as the break
out of the loop and then the test would be:

<type> factorial(<type> n)
{
if (n > CONSTANT_PRECOMPUTED_LIMIT)   return NULL;
else   {   return compute_actual_factorial(n);   }
}


pgsql-hackers by date:

Previous
From: "Cui Shijun"
Date:
Subject: Re: Issues with factorial operator
Next
From: Markus Schiltknecht
Date:
Subject: Re: COPYable logs status