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

Commit ada6fd6

Browse files
committed
For float4/8, remove errno checks for pow() and exp() because only some
platforms set errno, and we already have a check macro that detects under/overflow, so there is no reason for platform-specific code anymore.
1 parent 74a4019 commit ada6fd6

File tree

1 file changed

+11
-15
lines changed

1 file changed

+11
-15
lines changed

src/backend/utils/adt/float.c

Lines changed: 11 additions & 15 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.135 2007/01/02 22:19:42 momjian Exp $
11+
* $PostgreSQL: pgsql/src/backend/utils/adt/float.c,v 1.136 2007/01/03 04:21:47 momjian Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -1439,15 +1439,11 @@ dpow(PG_FUNCTION_ARGS)
14391439
errmsg("invalid argument for power function")));
14401440

14411441
/*
1442-
* We must check both for errno getting set and for a NaN result, in order
1443-
* to deal with the vagaries of different platforms...
1442+
* 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.
14441445
*/
1445-
errno = 0;
14461446
result = pow(arg1, arg2);
1447-
if (errno != 0 && !isinf(result))
1448-
ereport(ERROR,
1449-
(errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
1450-
errmsg("result is out of range")));
14511447

14521448
CHECKFLOATVAL(result, isinf(arg1) || isinf(arg2), arg1 == 0);
14531449
PG_RETURN_FLOAT8(result);
@@ -1464,15 +1460,11 @@ dexp(PG_FUNCTION_ARGS)
14641460
float8 result;
14651461

14661462
/*
1467-
* We must check both for errno getting set and for a NaN result, in order
1468-
* to deal with the vagaries of different platforms.
1463+
* 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.
14691466
*/
1470-
errno = 0;
14711467
result = exp(arg1);
1472-
if (errno != 0 && !isinf(result))
1473-
ereport(ERROR,
1474-
(errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
1475-
errmsg("result is out of range")));
14761468

14771469
CHECKFLOATVAL(result, isinf(arg1), false);
14781470
PG_RETURN_FLOAT8(result);
@@ -1547,6 +1539,10 @@ dacos(PG_FUNCTION_ARGS)
15471539
float8 arg1 = PG_GETARG_FLOAT8(0);
15481540
float8 result;
15491541

1542+
/*
1543+
* We use errno here because the trigonometric functions are cyclic
1544+
* and hard to check for underflow.
1545+
*/
15501546
errno = 0;
15511547
result = acos(arg1);
15521548
if (errno != 0)

0 commit comments

Comments
 (0)