1
0
mirror of https://github.com/postgres/postgres.git synced 2025-06-27 23:21:58 +03:00

Disallow factorial of negative numbers

The previous implementation returned 1 for all negative numbers, which
is not sensible under any definition.

Discussion: https://www.postgresql.org/message-id/flat/6ce1df0e-86a3-e544-743a-f357ff663f68%402ndquadrant.com
This commit is contained in:
Peter Eisentraut
2020-06-18 08:41:31 +02:00
parent 9d402c73ad
commit 0a40563ead
2 changed files with 6 additions and 10 deletions

View File

@ -2946,6 +2946,10 @@ numeric_fac(PG_FUNCTION_ARGS)
NumericVar fact;
NumericVar result;
if (num < 0)
ereport(ERROR,
(errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
errmsg("factorial of a negative number is undefined")));
if (num <= 1)
{
res = make_result(&const_one);