Adjust power() error messages to be more descriptive.
authorBruce Momjian <bruce@momjian.us>
Fri, 9 May 2008 21:31:23 +0000 (21:31 +0000)
committerBruce Momjian <bruce@momjian.us>
Fri, 9 May 2008 21:31:23 +0000 (21:31 +0000)
src/backend/utils/adt/float.c
src/backend/utils/adt/numeric.c

index 3df08cc6a3463da536704f7cb48ddb7ce4484de1..d19f9edb827b53f53daed8dd5d88b9b756c79368 100644 (file)
@@ -8,7 +8,7 @@
  *
  *
  * IDENTIFICATION
- *   $PostgreSQL: pgsql/src/backend/utils/adt/float.c,v 1.156 2008/05/09 15:36:06 momjian Exp $
+ *   $PostgreSQL: pgsql/src/backend/utils/adt/float.c,v 1.157 2008/05/09 21:31:23 momjian Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -1334,11 +1334,14 @@ dpow(PG_FUNCTION_ARGS)
     * 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))
+   if (arg1 == 0 && arg2 < 0)
        ereport(ERROR,
                (errcode(ERRCODE_INVALID_ARGUMENT_FOR_POWER_FUNCTION),
-                errmsg("invalid argument for power function")));
+                errmsg("zero raised to a negative power is undefined")));
+   if (arg1 < 0 && floor(arg2) != arg2)
+       ereport(ERROR,
+               (errcode(ERRCODE_INVALID_ARGUMENT_FOR_POWER_FUNCTION),
+                errmsg("a negative number raised to a non-integer power yields a complex result")));
 
    /*
     * pow() sets errno only on some platforms, depending on whether it
index b4022a7ccf18cee1207ddcd1e7300e26c9b5e0b6..c88469fdece6164f98ec61eca74a659589304df6 100644 (file)
@@ -14,7 +14,7 @@
  * Copyright (c) 1998-2008, PostgreSQL Global Development Group
  *
  * IDENTIFICATION
- *   $PostgreSQL: pgsql/src/backend/utils/adt/numeric.c,v 1.113 2008/05/09 15:36:06 momjian Exp $
+ *   $PostgreSQL: pgsql/src/backend/utils/adt/numeric.c,v 1.114 2008/05/09 21:31:23 momjian Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -1897,13 +1897,17 @@ numeric_power(PG_FUNCTION_ARGS)
     * 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) ||
-       (cmp_var(&arg1, &const_zero) < 0 &&
-        cmp_var(&arg2, &arg2_trunc) != 0))
+   if (cmp_var(&arg1, &const_zero) == 0 &&
+       cmp_var(&arg2, &const_zero) < 0)
        ereport(ERROR,
                (errcode(ERRCODE_INVALID_ARGUMENT_FOR_POWER_FUNCTION),
-                errmsg("invalid argument for power function")));
+                errmsg("zero raised to a negative power is undefined")));
+
+   if (cmp_var(&arg1, &const_zero) < 0 &&
+       cmp_var(&arg2, &arg2_trunc) != 0)
+       ereport(ERROR,
+               (errcode(ERRCODE_INVALID_ARGUMENT_FOR_POWER_FUNCTION),
+                errmsg("a negative number raised to a non-integer power yields a complex result")));
 
    /*
     * Call power_var() to compute and return the result; note it handles