8
8
*
9
9
*
10
10
* 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 $
12
12
*
13
13
*-------------------------------------------------------------------------
14
14
*/
@@ -1440,11 +1440,19 @@ dpow(PG_FUNCTION_ARGS)
1440
1440
1441
1441
/*
1442
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 .
1443
+ * follows _IEEE_, _POSIX_, _XOPEN_, or _SVID_, and some return Nan ,
1444
+ * so we check and set result properly .
1445
1445
*/
1446
+ errno = 0 ;
1446
1447
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
+
1448
1456
CHECKFLOATVAL (result , isinf (arg1 ) || isinf (arg2 ), arg1 == 0 );
1449
1457
PG_RETURN_FLOAT8 (result );
1450
1458
}
@@ -1461,10 +1469,19 @@ dexp(PG_FUNCTION_ARGS)
1461
1469
1462
1470
/*
1463
1471
* 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 .
1466
1474
*/
1475
+ errno = 0 ;
1467
1476
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
+
1468
1485
1469
1486
CHECKFLOATVAL (result , isinf (arg1 ), false);
1470
1487
PG_RETURN_FLOAT8 (result );
0 commit comments