* 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
* 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