Skip to content
Snippets Groups Projects
Commit ab786f62 authored by Bruce Momjian's avatar Bruce Momjian
Browse files

Make factorial(0) return 1, as per spec.

parent ad0787b2
No related branches found
No related tags found
No related merge requests found
...@@ -8,7 +8,7 @@ ...@@ -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) ...@@ -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 @@ ...@@ -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) ...@@ -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)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment