Re: Numeric version of factorial() - Mailing list pgsql-patches

From Tom Lane
Subject Re: Numeric version of factorial()
Date
Msg-id 3601.1059701864@sss.pgh.pa.us
Whole thread Raw
In response to Numeric version of factorial()  (Gavin Sherry <swm@linuxworld.com.au>)
Responses Re: Numeric version of factorial()  (Gavin Sherry <swm@linuxworld.com.au>)
List pgsql-patches
Gavin Sherry <swm@linuxworld.com.au> writes:
> 2) since we're accepting numeric arguments, the patch tests for floats. If
> a numeric is passed with non-zero decimal portion, an error is raised
> since (from memory) they are undefined.

There is a standard mathematical definition for it (gamma function,
IIRC) but this is probably plenty good enough for our purposes.  I would
suggest though that you reject fractions before you short-circuit for
x <= 1.

> 3) I have not removed factorial([int2|int4|int8]), not their operator
> counterparts since I didn't know what people would want done with these.

We had already decided to nuke the int2 and int4 versions, since they
overflow far too easily.  I'd go with nuking int8 too and providing only
the numeric variant ...

> +     int8_to_numericvar((int64)1, &one);
> +
> +     ret = cmp_var(&fact, &one);

Uh, why not use const_one?

            regards, tom lane

pgsql-patches by date:

Previous
From: Gavin Sherry
Date:
Subject: Numeric version of factorial()
Next
From: Gavin Sherry
Date:
Subject: Re: Numeric version of factorial()