Skip to content

Commit 6e3e600

Browse files
committed
Update C comments to mention SQL:2003 handling of power return values.
1 parent c5f42ce commit 6e3e600

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

src/backend/utils/adt/float.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/utils/adt/float.c,v 1.155 2008/04/21 00:26:45 tgl Exp $
11+
* $PostgreSQL: pgsql/src/backend/utils/adt/float.c,v 1.156 2008/05/09 15:36:06 momjian Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -1331,7 +1331,8 @@ dpow(PG_FUNCTION_ARGS)
13311331

13321332
/*
13331333
* The SQL spec requires that we emit a particular SQLSTATE error code for
1334-
* certain error conditions.
1334+
* certain error conditions. Specifically, we don't return a divide-by-zero
1335+
* error code for 0 ^ -1.
13351336
*/
13361337
if ((arg1 == 0 && arg2 < 0) ||
13371338
(arg1 < 0 && floor(arg2) != arg2))

src/backend/utils/adt/numeric.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* Copyright (c) 1998-2008, PostgreSQL Global Development Group
1515
*
1616
* IDENTIFICATION
17-
* $PostgreSQL: pgsql/src/backend/utils/adt/numeric.c,v 1.112 2008/05/08 22:17:54 momjian Exp $
17+
* $PostgreSQL: pgsql/src/backend/utils/adt/numeric.c,v 1.113 2008/05/09 15:36:06 momjian Exp $
1818
*
1919
*-------------------------------------------------------------------------
2020
*/
@@ -1893,8 +1893,9 @@ numeric_power(PG_FUNCTION_ARGS)
18931893
trunc_var(&arg2_trunc, 0);
18941894

18951895
/*
1896-
* Return special SQLSTATE error codes for a few conditions mandated by
1897-
* the standard.
1896+
* The SQL spec requires that we emit a particular SQLSTATE error code for
1897+
* certain error conditions. Specifically, we don't return a divide-by-zero
1898+
* error code for 0 ^ -1.
18981899
*/
18991900
if ((cmp_var(&arg1, &const_zero) == 0 &&
19001901
cmp_var(&arg2, &const_zero) < 0) ||
@@ -5283,6 +5284,7 @@ power_var_int(NumericVar *base, int exp, NumericVar *result, int rscale)
52835284
/*
52845285
* While 0 ^ 0 can be either 1 or indeterminate (error), we
52855286
* treat it as 1 because most programming languages do this.
5287+
* SQL:2003 also requires a return value of 1.
52865288
* http://en.wikipedia.org/wiki/Exponentiation#Zero_to_the_zero_power
52875289
*/
52885290
set_var_from_var(&const_one, result);

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