Skip to content

Commit ab786f6

Browse files
committed
Make factorial(0) return 1, as per spec.
1 parent ad0787b commit ab786f6

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

src/backend/utils/adt/int.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/utils/adt/int.c,v 1.47 2001/06/07 00:09:29 momjian Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/utils/adt/int.c,v 1.48 2002/02/23 01:01:30 momjian Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -784,7 +784,9 @@ int4fac(PG_FUNCTION_ARGS)
784784
int32 arg1 = PG_GETARG_INT32(0);
785785
int32 result;
786786

787-
if (arg1 < 1)
787+
if (arg1 == 0)
788+
result = 1;
789+
else if (arg1 < 1)
788790
result = 0;
789791
else
790792
for (result = 1; arg1 > 0; --arg1)

src/backend/utils/adt/int8.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1994, Regents of the University of California
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/backend/utils/adt/int8.c,v 1.36 2001/11/24 19:57:06 tgl Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/utils/adt/int8.c,v 1.37 2002/02/23 01:01:30 momjian Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -515,7 +515,9 @@ int8fac(PG_FUNCTION_ARGS)
515515
int64 result;
516516
int64 i;
517517

518-
if (arg1 < 1)
518+
if (arg1 == 0)
519+
result = 1;
520+
else if (arg1 < 1)
519521
result = 0;
520522
else
521523
for (i = arg1, result = 1; i > 0; --i)

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy