|
8 | 8 | * |
9 | 9 | * |
10 | 10 | * IDENTIFICATION |
11 | | - * $PostgreSQL: pgsql/src/backend/utils/adt/float.c,v 1.142 2007/01/05 22:19:40 momjian Exp $ |
| 11 | + * $PostgreSQL: pgsql/src/backend/utils/adt/float.c,v 1.143 2007/01/06 02:28:38 tgl Exp $ |
12 | 12 | * |
13 | 13 | *------------------------------------------------------------------------- |
14 | 14 | */ |
@@ -1442,24 +1442,27 @@ dpow(PG_FUNCTION_ARGS) |
1442 | 1442 | * pow() sets errno only on some platforms, depending on whether it |
1443 | 1443 | * follows _IEEE_, _POSIX_, _XOPEN_, or _SVID_, so we try to avoid |
1444 | 1444 | * using errno. However, some platform/CPU combinations return |
1445 | | - * errno == EDOM and result == Nan, so we have to check for that and |
1446 | | - * set result properly. For example, Linux on 32-bit x86 hardware |
1447 | | - * returns EDOM/Nan for (-1) ^ 1e19, but (-1) ^ 1e18 returns |
1448 | | - * 1 -- basically a negative base raised to a very high power causes |
1449 | | - * it on some CPUs. |
| 1445 | + * errno == EDOM and result == Nan for negative arg1 and very large arg2 |
| 1446 | + * (they must be using something different from our floor() test to |
| 1447 | + * decide it's invalid). Other platforms return errno == ERANGE and a |
| 1448 | + * large but finite result to signal overflow. |
1450 | 1449 | */ |
1451 | 1450 | errno=0; |
1452 | 1451 | result=pow(arg1,arg2); |
1453 | 1452 | if (errno==EDOM&&isnan(result)) |
1454 | 1453 | { |
1455 | 1454 | if ((fabs(arg1)>1&&arg2 >=0)|| (fabs(arg1)<1&&arg2<0)) |
1456 | | -/* The signif Inf is not significant in this case. */ |
| 1455 | +/* The signof Inf is not significant in this case. */ |
1457 | 1456 | result=get_float8_infinity(); |
1458 | 1457 | elseif (fabs(arg1)!=1) |
1459 | 1458 | result=0; |
1460 | 1459 | else |
1461 | 1460 | result=1; |
1462 | 1461 | } |
| 1462 | +elseif (errno==ERANGE) |
| 1463 | +{ |
| 1464 | +result= (arg1 >=0) ?get_float8_infinity() :-get_float8_infinity(); |
| 1465 | +} |
1463 | 1466 |
|
1464 | 1467 | CHECKFLOATVAL(result,isinf(arg1)||isinf(arg2),arg1==0); |
1465 | 1468 | PG_RETURN_FLOAT8(result); |
|