Skip to content

Commit 7021145

Browse files
committed
Revert back-branch changes in power()'s behavior for NaN inputs.
Per discussion, the value of fixing these bugs in the back branches doesn't outweigh the downsides of changing corner-case behavior in a minor release. Hence, revert commits 217d8f3 and 4d864de in the v10 branch and the corresponding commits in 9.3-9.6. Discussion: https://postgr.es/m/75DB81BEEA95B445AE6D576A0A5C9E936A73E741@BPXM05GP.gisp.nec.co.jp
1 parent 8109a3c commit 7021145

File tree

6 files changed

+1
-170
lines changed

6 files changed

+1
-170
lines changed

src/backend/utils/adt/float.c

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1391,25 +1391,6 @@ dpow(PG_FUNCTION_ARGS)
13911391
float8 arg2 = PG_GETARG_FLOAT8(1);
13921392
float8 result;
13931393

1394-
/*
1395-
* The POSIX spec says that NaN ^ 0 = 1, and 1 ^ NaN = 1, while all other
1396-
* cases with NaN inputs yield NaN (with no error). Many older platforms
1397-
* get one or more of these cases wrong, so deal with them via explicit
1398-
* logic rather than trusting pow(3).
1399-
*/
1400-
if (isnan(arg1))
1401-
{
1402-
if (isnan(arg2) || arg2 != 0.0)
1403-
PG_RETURN_FLOAT8(get_float8_nan());
1404-
PG_RETURN_FLOAT8(1.0);
1405-
}
1406-
if (isnan(arg2))
1407-
{
1408-
if (arg1 != 1.0)
1409-
PG_RETURN_FLOAT8(get_float8_nan());
1410-
PG_RETURN_FLOAT8(1.0);
1411-
}
1412-
14131394
/*
14141395
* The SQL spec requires that we emit a particular SQLSTATE error code for
14151396
* certain error conditions. Specifically, we don't return a
@@ -1428,7 +1409,7 @@ dpow(PG_FUNCTION_ARGS)
14281409
* pow() sets errno only on some platforms, depending on whether it
14291410
* follows _IEEE_, _POSIX_, _XOPEN_, or _SVID_, so we try to avoid using
14301411
* errno. However, some platform/CPU combinations return errno == EDOM
1431-
* and result == NaN for negative arg1 and very large arg2 (they must be
1412+
* and result == Nan for negative arg1 and very large arg2 (they must be
14321413
* using something different from our floor() test to decide it's
14331414
* invalid). Other platforms (HPPA) return errno == ERANGE and a large
14341415
* (HUGE_VAL) but finite result to signal overflow.

src/test/regress/expected/float8-exp-three-digits-win32.out

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -340,42 +340,6 @@ SELECT power(float8 '144', float8 '0.5');
340340
12
341341
(1 row)
342342

343-
SELECT power(float8 'NaN', float8 '0.5');
344-
power
345-
-------
346-
NaN
347-
(1 row)
348-
349-
SELECT power(float8 '144', float8 'NaN');
350-
power
351-
-------
352-
NaN
353-
(1 row)
354-
355-
SELECT power(float8 'NaN', float8 'NaN');
356-
power
357-
-------
358-
NaN
359-
(1 row)
360-
361-
SELECT power(float8 '-1', float8 'NaN');
362-
power
363-
-------
364-
NaN
365-
(1 row)
366-
367-
SELECT power(float8 '1', float8 'NaN');
368-
power
369-
-------
370-
1
371-
(1 row)
372-
373-
SELECT power(float8 'NaN', float8 '0');
374-
power
375-
-------
376-
1
377-
(1 row)
378-
379343
-- take exp of ln(f.f1)
380344
SELECT '' AS three, f.f1, exp(ln(f.f1)) AS exp_ln_f1
381345
FROM FLOAT8_TBL f

src/test/regress/expected/float8-small-is-zero.out

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -344,42 +344,6 @@ SELECT power(float8 '144', float8 '0.5');
344344
12
345345
(1 row)
346346

347-
SELECT power(float8 'NaN', float8 '0.5');
348-
power
349-
-------
350-
NaN
351-
(1 row)
352-
353-
SELECT power(float8 '144', float8 'NaN');
354-
power
355-
-------
356-
NaN
357-
(1 row)
358-
359-
SELECT power(float8 'NaN', float8 'NaN');
360-
power
361-
-------
362-
NaN
363-
(1 row)
364-
365-
SELECT power(float8 '-1', float8 'NaN');
366-
power
367-
-------
368-
NaN
369-
(1 row)
370-
371-
SELECT power(float8 '1', float8 'NaN');
372-
power
373-
-------
374-
1
375-
(1 row)
376-
377-
SELECT power(float8 'NaN', float8 '0');
378-
power
379-
-------
380-
1
381-
(1 row)
382-
383347
-- take exp of ln(f.f1)
384348
SELECT '' AS three, f.f1, exp(ln(f.f1)) AS exp_ln_f1
385349
FROM FLOAT8_TBL f

src/test/regress/expected/float8-small-is-zero_1.out

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -344,42 +344,6 @@ SELECT power(float8 '144', float8 '0.5');
344344
12
345345
(1 row)
346346

347-
SELECT power(float8 'NaN', float8 '0.5');
348-
power
349-
-------
350-
NaN
351-
(1 row)
352-
353-
SELECT power(float8 '144', float8 'NaN');
354-
power
355-
-------
356-
NaN
357-
(1 row)
358-
359-
SELECT power(float8 'NaN', float8 'NaN');
360-
power
361-
-------
362-
NaN
363-
(1 row)
364-
365-
SELECT power(float8 '-1', float8 'NaN');
366-
power
367-
-------
368-
NaN
369-
(1 row)
370-
371-
SELECT power(float8 '1', float8 'NaN');
372-
power
373-
-------
374-
1
375-
(1 row)
376-
377-
SELECT power(float8 'NaN', float8 '0');
378-
power
379-
-------
380-
1
381-
(1 row)
382-
383347
-- take exp of ln(f.f1)
384348
SELECT '' AS three, f.f1, exp(ln(f.f1)) AS exp_ln_f1
385349
FROM FLOAT8_TBL f

src/test/regress/expected/float8.out

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -340,42 +340,6 @@ SELECT power(float8 '144', float8 '0.5');
340340
12
341341
(1 row)
342342

343-
SELECT power(float8 'NaN', float8 '0.5');
344-
power
345-
-------
346-
NaN
347-
(1 row)
348-
349-
SELECT power(float8 '144', float8 'NaN');
350-
power
351-
-------
352-
NaN
353-
(1 row)
354-
355-
SELECT power(float8 'NaN', float8 'NaN');
356-
power
357-
-------
358-
NaN
359-
(1 row)
360-
361-
SELECT power(float8 '-1', float8 'NaN');
362-
power
363-
-------
364-
NaN
365-
(1 row)
366-
367-
SELECT power(float8 '1', float8 'NaN');
368-
power
369-
-------
370-
1
371-
(1 row)
372-
373-
SELECT power(float8 'NaN', float8 '0');
374-
power
375-
-------
376-
1
377-
(1 row)
378-
379343
-- take exp of ln(f.f1)
380344
SELECT '' AS three, f.f1, exp(ln(f.f1)) AS exp_ln_f1
381345
FROM FLOAT8_TBL f

src/test/regress/sql/float8.sql

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -108,12 +108,6 @@ SELECT '' AS three, f.f1, |/f.f1 AS sqrt_f1
108108

109109
-- power
110110
SELECT power(float8 '144', float8 '0.5');
111-
SELECT power(float8 'NaN', float8 '0.5');
112-
SELECT power(float8 '144', float8 'NaN');
113-
SELECT power(float8 'NaN', float8 'NaN');
114-
SELECT power(float8 '-1', float8 'NaN');
115-
SELECT power(float8 '1', float8 'NaN');
116-
SELECT power(float8 'NaN', float8 '0');
117111

118112
-- take exp of ln(f.f1)
119113
SELECT '' AS three, f.f1, exp(ln(f.f1)) AS exp_ln_f1

0 commit comments

Comments
 (0)