diff options
author | Bruce Momjian <bruce@momjian.us> | 2003-12-01 21:52:38 +0000 |
---|---|---|
committer | Bruce Momjian <bruce@momjian.us> | 2003-12-01 21:52:38 +0000 |
commit | 04a4821adef38155b7920ba9eb83c4c3c29156f8 (patch) | |
tree | c778c2d286441d98a2453f06f5af9c2b214ffc3e /src/backend/utils/adt/int.c | |
parent | af03663878b257f7fb93a80eec03a8dd070b22b7 (diff) | |
download | postgresql-04a4821adef38155b7920ba9eb83c4c3c29156f8.tar.gz postgresql-04a4821adef38155b7920ba9eb83c4c3c29156f8.zip |
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.
Gavin Sherry
Diffstat (limited to 'src/backend/utils/adt/int.c')
-rw-r--r-- | src/backend/utils/adt/int.c | 38 |
1 files changed, 2 insertions, 36 deletions
diff --git a/src/backend/utils/adt/int.c b/src/backend/utils/adt/int.c index 70e9971dd1f..e23706582e2 100644 --- a/src/backend/utils/adt/int.c +++ b/src/backend/utils/adt/int.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/utils/adt/int.c,v 1.58 2003/11/29 19:51:58 pgsql Exp $ + * $PostgreSQL: pgsql/src/backend/utils/adt/int.c,v 1.59 2003/12/01 21:52:37 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -26,7 +26,7 @@ * intpl, intmi, int4mul, intdiv * * Arithmetic operators: - * intmod, int4fac + * intmod */ #include "postgres.h" @@ -849,40 +849,6 @@ int42mod(PG_FUNCTION_ARGS) PG_RETURN_INT32(arg1 % arg2); } -/* int[24]fac() - * Factorial - */ -Datum -int4fac(PG_FUNCTION_ARGS) -{ - int32 arg1 = PG_GETARG_INT32(0); - int32 result; - - if (arg1 == 0) - result = 1; - else if (arg1 < 0) - result = 0; - else - for (result = 1; arg1 > 0; --arg1) - result *= arg1; - PG_RETURN_INT32(result); -} - -Datum -int2fac(PG_FUNCTION_ARGS) -{ - int16 arg1 = PG_GETARG_INT16(0); - int32 result; - - if (arg1 == 0) - result = 1; - else if (arg1 < 0) - result = 0; - else - for (result = 1; arg1 > 0; --arg1) - result *= arg1; - PG_RETURN_INT32(result); -} /* int[24]abs() * Absolute value |