|
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.111 2008/05/0819:25:38 momjian Exp $ |
| 17 | + * $PostgreSQL: pgsql/src/backend/utils/adt/numeric.c,v 1.112 2008/05/0822:17:54 momjian Exp $ |
18 | 18 | * |
19 | 19 | *------------------------------------------------------------------------- |
20 | 20 | */ |
@@ -5170,21 +5170,6 @@ 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 | | - |
5188 | 5173 | /* If exp can be represented as an integer, use power_var_int */ |
5189 | 5174 | if (exp->ndigits==0||exp->ndigits <=exp->weight+1) |
5190 | 5175 | { |
@@ -5217,6 +5202,17 @@ power_var(NumericVar *base, NumericVar *exp, NumericVar *result) |
5217 | 5202 | free_var(&x); |
5218 | 5203 | } |
5219 | 5204 |
|
| 5205 | +/* |
| 5206 | + *This avoids log(0) for cases of 0 raised to a non-integer. |
| 5207 | + *0 ^ 0 handled by power_var_int(). |
| 5208 | + */ |
| 5209 | +if (cmp_var(base,&const_zero)==0) |
| 5210 | +{ |
| 5211 | +set_var_from_var(&const_zero,result); |
| 5212 | +result->dscale=NUMERIC_MIN_SIG_DIGITS;/* no need to round */ |
| 5213 | +return; |
| 5214 | +} |
| 5215 | + |
5220 | 5216 | init_var(&ln_base); |
5221 | 5217 | init_var(&ln_num); |
5222 | 5218 |
|
@@ -5284,6 +5280,11 @@ power_var_int(NumericVar *base, int exp, NumericVar *result, int rscale) |
5284 | 5280 | switch (exp) |
5285 | 5281 | { |
5286 | 5282 | case0: |
| 5283 | +/* |
| 5284 | + *While 0 ^ 0 can be either 1 or indeterminate (error), we |
| 5285 | + *treat it as 1 because most programming languages do this. |
| 5286 | + *http://en.wikipedia.org/wiki/Exponentiation#Zero_to_the_zero_power |
| 5287 | + */ |
5287 | 5288 | set_var_from_var(&const_one,result); |
5288 | 5289 | result->dscale=rscale;/* no need to round */ |
5289 | 5290 | return; |
|