mirror of https://github.com/postgres/postgres
Make factorial(0) return 1, as per spec.
This commit is contained in:
parent
ad0787b2bd
commit
ab786f6299
|
@ -8,7 +8,7 @@
|
|||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/utils/adt/int.c,v 1.47 2001/06/07 00:09:29 momjian Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/utils/adt/int.c,v 1.48 2002/02/23 01:01:30 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
|
@ -784,7 +784,9 @@ int4fac(PG_FUNCTION_ARGS)
|
|||
int32 arg1 = PG_GETARG_INT32(0);
|
||||
int32 result;
|
||||
|
||||
if (arg1 < 1)
|
||||
if (arg1 == 0)
|
||||
result = 1;
|
||||
else if (arg1 < 1)
|
||||
result = 0;
|
||||
else
|
||||
for (result = 1; arg1 > 0; --arg1)
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
* Portions Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/utils/adt/int8.c,v 1.36 2001/11/24 19:57:06 tgl Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/utils/adt/int8.c,v 1.37 2002/02/23 01:01:30 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
|
@ -515,7 +515,9 @@ int8fac(PG_FUNCTION_ARGS)
|
|||
int64 result;
|
||||
int64 i;
|
||||
|
||||
if (arg1 < 1)
|
||||
if (arg1 == 0)
|
||||
result = 1;
|
||||
else if (arg1 < 1)
|
||||
result = 0;
|
||||
else
|
||||
for (i = arg1, result = 1; i > 0; --i)
|
||||
|
|
Loading…
Reference in New Issue