This resolves several warnings when compiling with MinGW because isnanf is not in MinGW's math.h (it's not a standard C function). On the other hand, isnan is a widely available C99 macro designed for both floats and doubles. We also have an isnan implementation in libs/port/isnan.c for pre-C99 compilers.
Signed-off-by: Alex Henrie alexhenrie24@gmail.com --- configure.ac | 1 - dlls/msvcrt/math.c | 30 +++++++++++------------------- 2 files changed, 11 insertions(+), 20 deletions(-)
diff --git a/configure.ac b/configure.ac index 6936a71b6f..2cc481630c 100644 --- a/configure.ac +++ b/configure.ac @@ -2163,7 +2163,6 @@ AC_CHECK_FUNCS(\ getpwuid \ gettimeofday \ getuid \ - isnanf \ kqueue \ lstat \ memmove \ diff --git a/dlls/msvcrt/math.c b/dlls/msvcrt/math.c index a1ba552632..dbfaa24756 100644 --- a/dlls/msvcrt/math.c +++ b/dlls/msvcrt/math.c @@ -38,14 +38,6 @@ WINE_DEFAULT_DEBUG_CHANNEL(msvcrt); #define finitef(x) isfinite(x) #endif
-#ifndef HAVE_ISNANF -#ifdef HAVE_ISNAN -#define isnanf(x) isnan(x) -#else -#define isnanf(x) 0 -#endif -#endif - /* FIXME: Does not work with -NAN and -0. */ #ifndef signbit #define signbit(x) ((x) < 0) @@ -190,7 +182,7 @@ INT CDECL MSVCRT__isnanf( float num ) /* Some implementations return -1 for true(glibc), msvcrt/crtdll return 1. * Do the same, as the result may be used in calculations */ - return isnanf(num) != 0; + return isnan(num) != 0; }
/********************************************************************* @@ -199,7 +191,7 @@ INT CDECL MSVCRT__isnanf( float num ) float CDECL MSVCRT__logbf( float num ) { float ret = logbf(num); - if (isnanf(num)) math_error(_DOMAIN, "_logbf", num, 0, ret); + if (isnan(num)) math_error(_DOMAIN, "_logbf", num, 0, ret); else if (!num) math_error(_SING, "_logbf", num, 0, ret); return ret; } @@ -245,7 +237,7 @@ float CDECL MSVCRT_atanf( float x ) float CDECL MSVCRT_atan2f( float x, float y ) { float ret = atan2f(x, y); - if (isnanf(x)) math_error(_DOMAIN, "atan2f", x, y, ret); + if (isnan(x)) math_error(_DOMAIN, "atan2f", x, y, ret); return ret; }
@@ -265,7 +257,7 @@ float CDECL MSVCRT_cosf( float x ) float CDECL MSVCRT_coshf( float x ) { float ret = coshf(x); - if (isnanf(x)) math_error(_DOMAIN, "coshf", x, 0, ret); + if (isnan(x)) math_error(_DOMAIN, "coshf", x, 0, ret); return ret; }
@@ -275,7 +267,7 @@ float CDECL MSVCRT_coshf( float x ) float CDECL MSVCRT_expf( float x ) { float ret = expf(x); - if (isnanf(x)) math_error(_DOMAIN, "expf", x, 0, ret); + if (isnan(x)) math_error(_DOMAIN, "expf", x, 0, ret); else if (finitef(x) && !ret) math_error(_UNDERFLOW, "expf", x, 0, ret); else if (finitef(x) && !finitef(ret)) math_error(_OVERFLOW, "expf", x, 0, ret); return ret; @@ -342,7 +334,7 @@ float CDECL MSVCRT_sinf( float x ) float CDECL MSVCRT_sinhf( float x ) { float ret = sinhf(x); - if (isnanf(x)) math_error(_DOMAIN, "sinhf", x, 0, ret); + if (isnan(x)) math_error(_DOMAIN, "sinhf", x, 0, ret); return ret; }
@@ -2943,9 +2935,9 @@ LDOUBLE CDECL MSVCR120_erfcl(LDOUBLE x) */ float CDECL MSVCR120_fmaxf(float x, float y) { - if(isnanf(x)) + if(isnan(x)) return y; - if(isnanf(y)) + if(isnan(y)) return x; if(x==0 && y==0) return signbit(x) ? y : x; @@ -3008,9 +3000,9 @@ int CDECL MSVCR120__fdpcomp(float x, float y) */ float CDECL MSVCR120_fminf(float x, float y) { - if(isnanf(x)) + if(isnan(x)) return y; - if(isnanf(y)) + if(isnan(y)) return x; if(x==0 && y==0) return signbit(x) ? x : y; @@ -3232,7 +3224,7 @@ float CDECL MSVCR120_remainderf(float x, float y) #ifdef HAVE_REMAINDERF /* this matches 64-bit Windows. 32-bit Windows is slightly different */ if(!finitef(x)) *MSVCRT__errno() = MSVCRT_EDOM; - if(isnanf(y) || y==0.0f) *MSVCRT__errno() = MSVCRT_EDOM; + if(isnan(y) || y==0.0f) *MSVCRT__errno() = MSVCRT_EDOM; return remainderf(x, y); #else FIXME( "not implemented\n" );
Signed-off-by: Alex Henrie alexhenrie24@gmail.com --- This one wasn't causing any problems in practice that I know of, but it's less confusing to just use the standard macro. --- configure.ac | 1 - dlls/msvcrt/math.c | 42 +++++++++++++++++++----------------------- 2 files changed, 19 insertions(+), 24 deletions(-)
diff --git a/configure.ac b/configure.ac index 2cc481630c..ff8c98fde6 100644 --- a/configure.ac +++ b/configure.ac @@ -2146,7 +2146,6 @@ AC_CHECK_FUNCS(\ dlopen \ epoll_create \ ffs \ - finitef \ fnmatch \ fork \ fpclass \ diff --git a/dlls/msvcrt/math.c b/dlls/msvcrt/math.c index dbfaa24756..a98defd868 100644 --- a/dlls/msvcrt/math.c +++ b/dlls/msvcrt/math.c @@ -34,10 +34,6 @@
WINE_DEFAULT_DEBUG_CHANNEL(msvcrt);
-#ifndef HAVE_FINITEF -#define finitef(x) isfinite(x) -#endif - /* FIXME: Does not work with -NAN and -0. */ #ifndef signbit #define signbit(x) ((x) < 0) @@ -159,7 +155,7 @@ float CDECL MSVCRT__copysignf( float num, float sign ) */ float CDECL MSVCRT__nextafterf( float num, float next ) { - if (!finitef(num) || !finitef(next)) *MSVCRT__errno() = MSVCRT_EDOM; + if (!isfinite(num) || !isfinite(next)) *MSVCRT__errno() = MSVCRT_EDOM; return nextafterf( num, next ); }
@@ -171,7 +167,7 @@ float CDECL MSVCRT__nextafterf( float num, float next ) */ int CDECL MSVCRT__finitef( float num ) { - return finitef(num) != 0; /* See comment for _isnan() */ + return isfinite(num) != 0; /* See comment for _isnan() */ }
/********************************************************************* @@ -207,7 +203,7 @@ float CDECL MSVCRT_acosf( float x ) * cancellation. The sqrt() makes things worse. A safer way to calculate * acos() is to use atan2(sqrt((1 - x) * (1 + x)), x). */ float ret = atan2f(sqrtf((1 - x) * (1 + x)), x); - if (x < -1.0 || x > 1.0 || !finitef(x)) math_error(_DOMAIN, "acosf", x, 0, ret); + if (x < -1.0 || x > 1.0 || !isfinite(x)) math_error(_DOMAIN, "acosf", x, 0, ret); return ret; }
@@ -217,7 +213,7 @@ float CDECL MSVCRT_acosf( float x ) float CDECL MSVCRT_asinf( float x ) { float ret = atan2f(x, sqrtf((1 - x) * (1 + x))); - if (x < -1.0 || x > 1.0 || !finitef(x)) math_error(_DOMAIN, "asinf", x, 0, ret); + if (x < -1.0 || x > 1.0 || !isfinite(x)) math_error(_DOMAIN, "asinf", x, 0, ret); return ret; }
@@ -227,7 +223,7 @@ float CDECL MSVCRT_asinf( float x ) float CDECL MSVCRT_atanf( float x ) { float ret = atanf(x); - if (!finitef(x)) math_error(_DOMAIN, "atanf", x, 0, ret); + if (!isfinite(x)) math_error(_DOMAIN, "atanf", x, 0, ret); return ret; }
@@ -247,7 +243,7 @@ float CDECL MSVCRT_atan2f( float x, float y ) float CDECL MSVCRT_cosf( float x ) { float ret = cosf(x); - if (!finitef(x)) math_error(_DOMAIN, "cosf", x, 0, ret); + if (!isfinite(x)) math_error(_DOMAIN, "cosf", x, 0, ret); return ret; }
@@ -268,8 +264,8 @@ float CDECL MSVCRT_expf( float x ) { float ret = expf(x); if (isnan(x)) math_error(_DOMAIN, "expf", x, 0, ret); - else if (finitef(x) && !ret) math_error(_UNDERFLOW, "expf", x, 0, ret); - else if (finitef(x) && !finitef(ret)) math_error(_OVERFLOW, "expf", x, 0, ret); + else if (isfinite(x) && !ret) math_error(_UNDERFLOW, "expf", x, 0, ret); + else if (isfinite(x) && !isfinite(ret)) math_error(_OVERFLOW, "expf", x, 0, ret); return ret; }
@@ -279,7 +275,7 @@ float CDECL MSVCRT_expf( float x ) float CDECL MSVCRT_fmodf( float x, float y ) { float ret = fmodf(x, y); - if (!finitef(x) || !finitef(y)) math_error(_DOMAIN, "fmodf", x, 0, ret); + if (!isfinite(x) || !isfinite(y)) math_error(_DOMAIN, "fmodf", x, 0, ret); return ret; }
@@ -312,9 +308,9 @@ float CDECL MSVCRT_powf( float x, float y ) { float z = powf(x,y); if (x < 0 && y != floorf(y)) math_error(_DOMAIN, "powf", x, y, z); - else if (!x && finitef(y) && y < 0) math_error(_SING, "powf", x, y, z); - else if (finitef(x) && finitef(y) && !finitef(z)) math_error(_OVERFLOW, "powf", x, y, z); - else if (x && finitef(x) && finitef(y) && !z) math_error(_UNDERFLOW, "powf", x, y, z); + else if (!x && isfinite(y) && y < 0) math_error(_SING, "powf", x, y, z); + else if (isfinite(x) && isfinite(y) && !isfinite(z)) math_error(_OVERFLOW, "powf", x, y, z); + else if (x && isfinite(x) && isfinite(y) && !z) math_error(_UNDERFLOW, "powf", x, y, z); return z; }
@@ -324,7 +320,7 @@ float CDECL MSVCRT_powf( float x, float y ) float CDECL MSVCRT_sinf( float x ) { float ret = sinf(x); - if (!finitef(x)) math_error(_DOMAIN, "sinf", x, 0, ret); + if (!isfinite(x)) math_error(_DOMAIN, "sinf", x, 0, ret); return ret; }
@@ -354,7 +350,7 @@ float CDECL MSVCRT_sqrtf( float x ) float CDECL MSVCRT_tanf( float x ) { float ret = tanf(x); - if (!finitef(x)) math_error(_DOMAIN, "tanf", x, 0, ret); + if (!isfinite(x)) math_error(_DOMAIN, "tanf", x, 0, ret); return ret; }
@@ -364,7 +360,7 @@ float CDECL MSVCRT_tanf( float x ) float CDECL MSVCRT_tanhf( float x ) { float ret = tanhf(x); - if (!finitef(x)) math_error(_DOMAIN, "tanhf", x, 0, ret); + if (!isfinite(x)) math_error(_DOMAIN, "tanhf", x, 0, ret); return ret; }
@@ -2468,7 +2464,7 @@ float CDECL MSVCR120_exp2f(float x) { #ifdef HAVE_EXP2F float ret = exp2f(x); - if (finitef(x) && !finitef(ret)) *MSVCRT__errno() = MSVCRT_ERANGE; + if (isfinite(x) && !isfinite(ret)) *MSVCRT__errno() = MSVCRT_ERANGE; return ret; #else return MSVCR120_exp2(x); @@ -2507,7 +2503,7 @@ float CDECL MSVCR120_expm1f(float x) #else float ret = exp(x) - 1; #endif - if (finitef(x) && !finitef(ret)) *MSVCRT__errno() = MSVCRT_ERANGE; + if (isfinite(x) && !isfinite(ret)) *MSVCRT__errno() = MSVCRT_ERANGE; return ret; }
@@ -3152,7 +3148,7 @@ float CDECL MSVCR120_atanhf(float x)
ret = atanhf(x);
- if (!finitef(ret)) *MSVCRT__errno() = MSVCRT_ERANGE; + if (!isfinite(ret)) *MSVCRT__errno() = MSVCRT_ERANGE; return ret; #else return MSVCR120_atanh(x); @@ -3223,7 +3219,7 @@ float CDECL MSVCR120_remainderf(float x, float y) { #ifdef HAVE_REMAINDERF /* this matches 64-bit Windows. 32-bit Windows is slightly different */ - if(!finitef(x)) *MSVCRT__errno() = MSVCRT_EDOM; + if(!isfinite(x)) *MSVCRT__errno() = MSVCRT_EDOM; if(isnan(y) || y==0.0f) *MSVCRT__errno() = MSVCRT_EDOM; return remainderf(x, y); #else
Hi Alex,
On 09/26/18 05:03, Alex Henrie wrote:
This one wasn't causing any problems in practice that I know of, but it's less confusing to just use the standard macro.
I think that since there's no problem with current code there's no reason to change it (I don't have a strong opinion in this regard). Potentially this change can affect performance but probably it will be optimized anyway.
Thanks, Piotr