Re: Numeric version of factorial()

From: Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us>
To: Gavin Sherry <swm(at)linuxworld(dot)com(dot)au>
Cc: pgsql-patches(at)postgresql(dot)org
Subject: Re: Numeric version of factorial()
Date: 2003-12-01 21:36:06
Message-ID: 200312012136.hB1La6l07096@candle.pha.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-docs pgsql-patches


Patch attached and applied. Thanks.

I adjusted the oid so prevent a duplicate, and adjusted the regression
test to remove comments on now non-existant functions.

I also tested the output and it looks good:

test=> select numeric_fac(10);
numeric_fac
-------------
3628800
(1 row)

test=> select numeric_fac(1);
numeric_fac
-------------
1
(1 row)

test=> select numeric_fac(2);
numeric_fac
-------------
2
(1 row)

test=> select numeric_fac(4);
numeric_fac
-------------
24
(1 row)

test=> select numeric_fac(3);
numeric_fac
-------------
6
(1 row)

I will check the docs now.

---------------------------------------------------------------------------

Gavin Sherry wrote:
> Attached is a patch implementing factorial(), returning numeric. Points to
> note:
>
> 1) arttype is numeric. I thought this was the best way of allowing
> arbitarily large factorials, even though factorial(2^63) is a large
> number. Happy to change to integers if this is overkill.
> 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.
> 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.
> 4) I haven't added any documentation but am happy to once I know if people
> want int or numeric arguments.

> Attached is a revised patch based on your Tom's comments. It removes
> int[248]fac(), modifies regression tests (which referenced int4fac()),
> and implements a much cleaned numeric_fac().

--
Bruce Momjian | http://candle.pha.pa.us
pgman(at)candle(dot)pha(dot)pa(dot)us | (610) 359-1001
+ If your life is a hard drive, | 13 Roberts Road
+ Christ can be your backup. | Newtown Square, Pennsylvania 19073

Attachment Content-Type Size
unknown_filename text/plain 15.3 KB

In response to

Browse pgsql-docs by date

  From Date Subject
Next Message Bruce Momjian 2003-12-01 21:54:28 Re: [PATCHES] Numeric version of factorial()
Previous Message Tom Lane 2003-12-01 17:59:20 Re: PostgreSQL 7.4 Documentation - create_trigger.sgml

Browse pgsql-patches by date

  From Date Subject
Next Message Joe Conway 2003-12-01 21:41:42 Re: export FUNC_MAX_ARGS as a read-only GUC variable
Previous Message Ron Mayer 2003-12-01 21:18:20 Re: ISO 8601 "Time Intervals" of the "format with time-unit