Make factorial(0) return 1, as per spec.
This commit is contained in:
parent
ad0787b2bd
commit
ab786f6299
|
@ -8,7 +8,7 @@
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
* IDENTIFICATION
|
* 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 arg1 = PG_GETARG_INT32(0);
|
||||||
int32 result;
|
int32 result;
|
||||||
|
|
||||||
if (arg1 < 1)
|
if (arg1 == 0)
|
||||||
|
result = 1;
|
||||||
|
else if (arg1 < 1)
|
||||||
result = 0;
|
result = 0;
|
||||||
else
|
else
|
||||||
for (result = 1; arg1 > 0; --arg1)
|
for (result = 1; arg1 > 0; --arg1)
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
* Portions Copyright (c) 1994, Regents of the University of California
|
* Portions Copyright (c) 1994, Regents of the University of California
|
||||||
*
|
*
|
||||||
* IDENTIFICATION
|
* 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 result;
|
||||||
int64 i;
|
int64 i;
|
||||||
|
|
||||||
if (arg1 < 1)
|
if (arg1 == 0)
|
||||||
|
result = 1;
|
||||||
|
else if (arg1 < 1)
|
||||||
result = 0;
|
result = 0;
|
||||||
else
|
else
|
||||||
for (i = arg1, result = 1; i > 0; --i)
|
for (i = arg1, result = 1; i > 0; --i)
|
||||||
|
|
Loading…
Reference in New Issue