Skip to content

Commit 3be772c

Browse files
committed
Change exp() behavior to generate error on underflow rather
than silently returning zero on some machines. Correct float8 regress test to agree. Also fix pow() overflow/underflow check to work correctly on HPUX.
1 parent 594bee4 commit 3be772c

File tree

2 files changed

+5
-12
lines changed

2 files changed

+5
-12
lines changed

src/backend/utils/adt/float.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/backend/utils/adt/float.c,v 1.33 1998/09/01 04:32:32 momjian Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/utils/adt/float.c,v 1.33.2.1 1998/11/29 01:58:59 tgl Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -1041,7 +1041,7 @@ dpow(float64 arg1, float64 arg2)
10411041
#endif
10421042
*result = (float64data) pow(tmp1, tmp2);
10431043
#ifndef finite
1044-
if (errno == ERANGE)
1044+
if (errno != 0) /* on some machines both EDOM & ERANGE can occur */
10451045
#else
10461046
if (!finite(*result))
10471047
#endif
@@ -1074,7 +1074,8 @@ dexp(float64 arg1)
10741074
#ifndef finite
10751075
if (errno == ERANGE)
10761076
#else
1077-
if (!finite(*result))
1077+
/* infinity implies overflow, zero implies underflow */
1078+
if (!finite(*result) || *result == 0.0)
10781079
#endif
10791080
elog(ERROR, "exp() result is out of range");
10801081

src/test/regress/expected/float8.out

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -195,15 +195,7 @@ ERROR: can't take log of zero
195195
QUERY: SELECT '' AS bad, (; (f.f1)) from FLOAT8_TBL f where f.f1 < '0.0' ;
196196
ERROR: can't take log of a negative number
197197
QUERY: SELECT '' AS bad, : (f.f1) from FLOAT8_TBL f;
198-
bad| ?column?
199-
---+--------------------
200-
| 1
201-
|7.39912306090513e-16
202-
| 0
203-
| 0
204-
| 1
205-
(5 rows)
206-
198+
ERROR: exp() result is out of range
207199
QUERY: SELECT '' AS bad, f.f1 / '0.0' from FLOAT8_TBL f;
208200
ERROR: float8div: divide by zero error
209201
QUERY: SELECT '' AS five, FLOAT8_TBL.*;

0 commit comments

Comments
 (0)