Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b2965b9

Browse files
committed
Put back ERANGE test in dpow(). There are platforms that need this,
like my HPPA ...
1 parent 561b4ba commit b2965b9

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

src/backend/utils/adt/float.c

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* 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 $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -1442,24 +1442,27 @@ dpow(PG_FUNCTION_ARGS)
14421442
* pow() sets errno only on some platforms, depending on whether it
14431443
* follows _IEEE_, _POSIX_, _XOPEN_, or _SVID_, so we try to avoid
14441444
* 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.
14501449
*/
14511450
errno = 0;
14521451
result = pow(arg1, arg2);
14531452
if (errno == EDOM && isnan(result))
14541453
{
14551454
if ((fabs(arg1) > 1 && arg2 >= 0) || (fabs(arg1) < 1 && arg2 < 0))
1456-
/* The sign if Inf is not significant in this case. */
1455+
/* The sign of Inf is not significant in this case. */
14571456
result = get_float8_infinity();
14581457
else if (fabs(arg1) != 1)
14591458
result = 0;
14601459
else
14611460
result = 1;
14621461
}
1462+
else if (errno == ERANGE)
1463+
{
1464+
result = (arg1 >= 0) ? get_float8_infinity() : -get_float8_infinity();
1465+
}
14631466

14641467
CHECKFLOATVAL(result, isinf(arg1) || isinf(arg2), arg1 == 0);
14651468
PG_RETURN_FLOAT8(result);

0 commit comments

Comments
 (0)