|
14 | 14 | * Copyright (c) 1998-2008, PostgreSQL Global Development Group
|
15 | 15 | *
|
16 | 16 | * IDENTIFICATION
|
17 |
| - * $PostgreSQL: pgsql/src/backend/utils/adt/numeric.c,v 1.110 2008/04/21 00:26:45 tgl Exp $ |
| 17 | + * $PostgreSQL: pgsql/src/backend/utils/adt/numeric.c,v 1.111 2008/05/08 19:25:38 momjian Exp $ |
18 | 18 | *
|
19 | 19 | *-------------------------------------------------------------------------
|
20 | 20 | */
|
@@ -5170,6 +5170,21 @@ power_var(NumericVar *base, NumericVar *exp, NumericVar *result)
|
5170 | 5170 | intlocal_rscale;
|
5171 | 5171 | doubleval;
|
5172 | 5172 |
|
| 5173 | +/* |
| 5174 | + *This avoids log(0) for cases of 0 raised to a non-integer. |
| 5175 | + *Also, while 0 ^ 0 can be either 1 or indeterminate (error), we |
| 5176 | + *treat it as one because most programming languages do this. |
| 5177 | + *http://en.wikipedia.org/wiki/Exponentiation#Zero_to_the_zero_power |
| 5178 | + */ |
| 5179 | +if (cmp_var(base,&const_zero)==0) |
| 5180 | +{ |
| 5181 | +if (cmp_var(exp,&const_zero)==0) |
| 5182 | +set_var_from_var(&const_one,result); |
| 5183 | +else |
| 5184 | +set_var_from_var(&const_zero,result); |
| 5185 | +return; |
| 5186 | +} |
| 5187 | + |
5173 | 5188 | /* If exp can be represented as an integer, use power_var_int */
|
5174 | 5189 | if (exp->ndigits==0||exp->ndigits <=exp->weight+1)
|
5175 | 5190 | {
|
@@ -5266,15 +5281,9 @@ power_var_int(NumericVar *base, int exp, NumericVar *result, int rscale)
|
5266 | 5281 | NumericVarbase_prod;
|
5267 | 5282 | intlocal_rscale;
|
5268 | 5283 |
|
5269 |
| -/* Detect some special cases, particularly 0^0. */ |
5270 |
| - |
5271 | 5284 | switch (exp)
|
5272 | 5285 | {
|
5273 | 5286 | case0:
|
5274 |
| -if (base->ndigits==0) |
5275 |
| -ereport(ERROR, |
5276 |
| -(errcode(ERRCODE_FLOATING_POINT_EXCEPTION), |
5277 |
| -errmsg("zero raised to zero is undefined"))); |
5278 | 5287 | set_var_from_var(&const_one,result);
|
5279 | 5288 | result->dscale=rscale;/* no need to round */
|
5280 | 5289 | return;
|
|