Commit 79c3b610 authored by Alex Henrie's avatar Alex Henrie Committed by Alexandre Julliard

msvcrt: Set ERANGE in exp functions on finite input and infinite output.

parent cfb1f130
...@@ -209,8 +209,10 @@ float CDECL MSVCRT_coshf( float x ) ...@@ -209,8 +209,10 @@ float CDECL MSVCRT_coshf( float x )
*/ */
float CDECL MSVCRT_expf( float x ) float CDECL MSVCRT_expf( float x )
{ {
if (!finitef(x)) *MSVCRT__errno() = MSVCRT_EDOM; float ret = expf(x);
return expf(x); if (isnanf(x)) *MSVCRT__errno() = MSVCRT_EDOM;
else if (finitef(x) && !finitef(ret)) *MSVCRT__errno() = MSVCRT_ERANGE;
return ret;
} }
/********************************************************************* /*********************************************************************
...@@ -404,8 +406,10 @@ double CDECL MSVCRT_cosh( double x ) ...@@ -404,8 +406,10 @@ double CDECL MSVCRT_cosh( double x )
*/ */
double CDECL MSVCRT_exp( double x ) double CDECL MSVCRT_exp( double x )
{ {
double ret = exp(x);
if (isnan(x)) *MSVCRT__errno() = MSVCRT_EDOM; if (isnan(x)) *MSVCRT__errno() = MSVCRT_EDOM;
return exp(x); else if (isfinite(x) && !isfinite(ret)) *MSVCRT__errno() = MSVCRT_ERANGE;
return ret;
} }
/********************************************************************* /*********************************************************************
...@@ -984,7 +988,7 @@ double CDECL MSVCRT_ldexp(double num, MSVCRT_long exp) ...@@ -984,7 +988,7 @@ double CDECL MSVCRT_ldexp(double num, MSVCRT_long exp)
{ {
double z = ldexp(num,exp); double z = ldexp(num,exp);
if (!isfinite(z)) if (isfinite(num) && !isfinite(z))
*MSVCRT__errno() = MSVCRT_ERANGE; *MSVCRT__errno() = MSVCRT_ERANGE;
else if (z == 0 && signbit(z)) else if (z == 0 && signbit(z))
z = 0.0; /* Convert -0 -> +0 */ z = 0.0; /* Convert -0 -> +0 */
...@@ -2385,10 +2389,12 @@ LDOUBLE CDECL MSVCR120_cbrtl(LDOUBLE x) ...@@ -2385,10 +2389,12 @@ LDOUBLE CDECL MSVCR120_cbrtl(LDOUBLE x)
double CDECL MSVCR120_exp2(double x) double CDECL MSVCR120_exp2(double x)
{ {
#ifdef HAVE_EXP2 #ifdef HAVE_EXP2
return exp2(x); double ret = exp2(x);
#else #else
return pow(2, x); double ret = pow(2, x);
#endif #endif
if (isfinite(x) && !isfinite(ret)) *MSVCRT__errno() = MSVCRT_ERANGE;
return ret;
} }
/********************************************************************* /*********************************************************************
...@@ -2397,7 +2403,9 @@ double CDECL MSVCR120_exp2(double x) ...@@ -2397,7 +2403,9 @@ double CDECL MSVCR120_exp2(double x)
float CDECL MSVCR120_exp2f(float x) float CDECL MSVCR120_exp2f(float x)
{ {
#ifdef HAVE_EXP2F #ifdef HAVE_EXP2F
return exp2f(x); float ret = exp2f(x);
if (finitef(x) && !finitef(ret)) *MSVCRT__errno() = MSVCRT_ERANGE;
return ret;
#else #else
return MSVCR120_exp2(x); return MSVCR120_exp2(x);
#endif #endif
...@@ -2421,7 +2429,7 @@ double CDECL MSVCR120_expm1(double x) ...@@ -2421,7 +2429,7 @@ double CDECL MSVCR120_expm1(double x)
#else #else
double ret = exp(x) - 1; double ret = exp(x) - 1;
#endif #endif
if (!isfinite(ret)) *MSVCRT__errno() = MSVCRT_ERANGE; if (isfinite(x) && !isfinite(ret)) *MSVCRT__errno() = MSVCRT_ERANGE;
return ret; return ret;
} }
...@@ -2435,7 +2443,7 @@ float CDECL MSVCR120_expm1f(float x) ...@@ -2435,7 +2443,7 @@ float CDECL MSVCR120_expm1f(float x)
#else #else
float ret = exp(x) - 1; float ret = exp(x) - 1;
#endif #endif
if (!finitef(ret)) *MSVCRT__errno() = MSVCRT_ERANGE; if (finitef(x) && !finitef(ret)) *MSVCRT__errno() = MSVCRT_ERANGE;
return ret; return ret;
} }
...@@ -3124,8 +3132,7 @@ LDOUBLE CDECL MSVCR120_atanhl(LDOUBLE x) ...@@ -3124,8 +3132,7 @@ LDOUBLE CDECL MSVCR120_atanhl(LDOUBLE x)
*/ */
double CDECL MSVCRT__scalb(double num, MSVCRT_long power) double CDECL MSVCRT__scalb(double num, MSVCRT_long power)
{ {
if (!isfinite(num)) *MSVCRT__errno() = MSVCRT_EDOM; return MSVCRT_ldexp(num, power);
return ldexp(num, power);
} }
/********************************************************************* /*********************************************************************
...@@ -3135,8 +3142,7 @@ double CDECL MSVCRT__scalb(double num, MSVCRT_long power) ...@@ -3135,8 +3142,7 @@ double CDECL MSVCRT__scalb(double num, MSVCRT_long power)
*/ */
float CDECL MSVCRT__scalbf(float num, MSVCRT_long power) float CDECL MSVCRT__scalbf(float num, MSVCRT_long power)
{ {
if (!finitef(num)) *MSVCRT__errno() = MSVCRT_EDOM; return MSVCRT_ldexp(num, power);
return ldexpf(num, power);
} }
/********************************************************************* /*********************************************************************
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment