Update C comments to mention SQL:2003 handling of power return values.
authorBruce Momjian <bruce@momjian.us>
Fri, 9 May 2008 15:36:06 +0000 (15:36 +0000)
committerBruce Momjian <bruce@momjian.us>
Fri, 9 May 2008 15:36:06 +0000 (15:36 +0000)
src/backend/utils/adt/float.c
src/backend/utils/adt/numeric.c

index f95e934bfd8f6d55d9c27062360fbadd65b4373a..706a436db3809fd75fda7f24e56885238e4c033d 100644 (file)
@@ -1331,7 +1331,8 @@ dpow(PG_FUNCTION_ARGS)
 
        /*
         * The SQL spec requires that we emit a particular SQLSTATE error code for
-        * certain error conditions.
+        * certain error conditions.  Specifically, we don't return a divide-by-zero
+        * error code for 0 ^ -1.
         */
        if ((arg1 == 0 && arg2 < 0) ||
                (arg1 < 0 && floor(arg2) != arg2))
index 80b8c8edf10e05232d283403a8ed3578734dc70c..19820f6c0bc7a8e9375b854c4183a9ef1844cca8 100644 (file)
@@ -1893,8 +1893,9 @@ numeric_power(PG_FUNCTION_ARGS)
        trunc_var(&arg2_trunc, 0);
 
        /*
-        * Return special SQLSTATE error codes for a few conditions mandated by
-        * the standard.
+        * The SQL spec requires that we emit a particular SQLSTATE error code for
+        * certain error conditions.  Specifically, we don't return a divide-by-zero
+        * error code for 0 ^ -1.
         */
        if ((cmp_var(&arg1, &const_zero) == 0 &&
                 cmp_var(&arg2, &const_zero) < 0) ||
@@ -5283,6 +5284,7 @@ power_var_int(NumericVar *base, int exp, NumericVar *result, int rscale)
                        /*
                         *      While 0 ^ 0 can be either 1 or indeterminate (error), we
                         *      treat it as 1 because most programming languages do this.
+                        *      SQL:2003 also requires a return value of 1.
                         *      http://en.wikipedia.org/wiki/Exponentiation#Zero_to_the_zero_power
                         */
                        set_var_from_var(&const_one, result);