88 *
99 *
1010 * IDENTIFICATION
11- * $PostgreSQL: pgsql/src/backend/utils/adt/float.c,v 1.136 2007/01/0304:21:47 momjian Exp $
11+ * $PostgreSQL: pgsql/src/backend/utils/adt/float.c,v 1.137 2007/01/0314: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- * wedon't consult it andjust do our check below .
1443+ * follows _IEEE_, _POSIX_, _XOPEN_, or _SVID_,and some return Nan ,
1444+ *so wecheck andset result properly .
14451445 */
1446+ errno = 0 ;
14461447result = 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+
14481456CHECKFLOATVAL (result ,isinf (arg1 )|| isinf (arg2 ),arg1 == 0 );
14491457PG_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- * wedon't consult it andjust do our check below .
1472+ * follows _IEEE_, _POSIX_, _XOPEN_, or _SVID_,and some return Nan ,
1473+ *so wecheck andset result properly .
14661474 */
1475+ errno = 0 ;
14671476result = 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
14691486CHECKFLOATVAL (result ,isinf (arg1 ), false);
14701487PG_RETURN_FLOAT8 (result );