Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 990fea8

Browse files
committed
Attempt to return proper overflow/underflow messages for platforms that
only return Nan and set errno for pow/exp overflow/underflow.
1 parent ada6fd6 commit 990fea8

File tree

1 file changed

+23
-6
lines changed

1 file changed

+23
-6
lines changed

src/backend/utils/adt/float.c

Lines changed: 23 additions & 6 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.136 2007/01/03 04:21:47 momjian Exp $
11+
* $PostgreSQL: pgsql/src/backend/utils/adt/float.c,v 1.137 2007/01/03 14:35:24 momjian Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -1440,11 +1440,19 @@ dpow(PG_FUNCTION_ARGS)
14401440

14411441
/*
14421442
* pow() sets errno only on some platforms, depending on whether it
1443-
* follows _IEEE_, _POSIX_, _XOPEN_, or _SVID_, so, for consistency,
1444-
* we don't consult it and just do our check below.
1443+
* follows _IEEE_, _POSIX_, _XOPEN_, or _SVID_, and some return Nan,
1444+
* so we check and set result properly.
14451445
*/
1446+
errno = 0;
14461447
result = pow(arg1, arg2);
1447-
1448+
if (errno == ERANGE && isnan(result))
1449+
{
1450+
if ((fabs(arg1) > 1 && arg2 >= 0) || (fabs(arg1) < 1 && arg2 < 0))
1451+
result = (arg1 >= 0) ? get_float8_infinity() : -get_float8_infinity();
1452+
else
1453+
result = 0;
1454+
}
1455+
14481456
CHECKFLOATVAL(result, isinf(arg1) || isinf(arg2), arg1 == 0);
14491457
PG_RETURN_FLOAT8(result);
14501458
}
@@ -1461,10 +1469,19 @@ dexp(PG_FUNCTION_ARGS)
14611469

14621470
/*
14631471
* exp() sets errno only on some platforms, depending on whether it
1464-
* follows _IEEE_, _POSIX_, _XOPEN_, or _SVID_, so, for consistency,
1465-
* we don't consult it and just do our check below.
1472+
* follows _IEEE_, _POSIX_, _XOPEN_, or _SVID_, and some return Nan,
1473+
* so we check and set result properly.
14661474
*/
1475+
errno = 0;
14671476
result = exp(arg1);
1477+
if (errno == ERANGE && isnan(result))
1478+
{
1479+
if (arg1 >= 0)
1480+
result = get_float8_infinity();
1481+
else
1482+
result = 0;
1483+
}
1484+
14681485

14691486
CHECKFLOATVAL(result, isinf(arg1), false);
14701487
PG_RETURN_FLOAT8(result);

0 commit comments

Comments
 (0)