From 854a3cab4c136d3e2292bcd9c42c530e56cef7e9 Mon Sep 17 00:00:00 2001 From: Piotr Caban Date: Fri, 14 May 2021 16:11:48 +0200 Subject: [PATCH] msvcrt: Import neabyint implementation from musl. Signed-off-by: Piotr Caban Signed-off-by: Alexandre Julliard --- configure | 1 - configure.ac | 1 - dlls/msvcrt/math.c | 13 +++++++++++-- dlls/msvcrt/unixlib.c | 13 ------------- dlls/msvcrt/unixlib.h | 1 - include/config.h.in | 3 --- 6 files changed, 11 insertions(+), 21 deletions(-) diff --git a/configure b/configure index 91f0c586c60..525d585130f 100755 --- a/configure +++ b/configure @@ -19640,7 +19640,6 @@ for ac_func in \ log1pf \ log2 \ log2f \ - nearbyint \ nexttoward \ nexttowardf \ remainder \ diff --git a/configure.ac b/configure.ac index df1025aeb98..2e8ff20aeef 100644 --- a/configure.ac +++ b/configure.ac @@ -2680,7 +2680,6 @@ AC_CHECK_FUNCS(\ log1pf \ log2 \ log2f \ - nearbyint \ nexttoward \ nexttowardf \ remainder \ diff --git a/dlls/msvcrt/math.c b/dlls/msvcrt/math.c index 7fe7b9d172b..2bc51213a07 100644 --- a/dlls/msvcrt/math.c +++ b/dlls/msvcrt/math.c @@ -3418,10 +3418,19 @@ double CDECL _yn(int n, double x) /********************************************************************* * _nearbyint (MSVCR120.@) + * + * Based on musl: src/math/nearbyteint.c */ -double CDECL nearbyint(double num) +double CDECL nearbyint(double x) { - return unix_funcs->nearbyint( num ); + fenv_t env; + + fegetenv(&env); + _control87(_MCW_EM, _MCW_EM); + x = rint(x); + feclearexcept(FE_INEXACT); + feupdateenv(&env); + return x; } /********************************************************************* diff --git a/dlls/msvcrt/unixlib.c b/dlls/msvcrt/unixlib.c index a0892e98d97..376bdb5c1c7 100644 --- a/dlls/msvcrt/unixlib.c +++ b/dlls/msvcrt/unixlib.c @@ -547,18 +547,6 @@ static float CDECL unix_modff( float x, float *iptr ) return modff( x, iptr ); } -/********************************************************************* - * nearbyint - */ -static double CDECL unix_nearbyint(double num) -{ -#ifdef HAVE_NEARBYINT - return nearbyint(num); -#else - return num >= 0 ? floor(num + 0.5) : ceil(num - 0.5); -#endif -} - /********************************************************************* * nextafter */ @@ -834,7 +822,6 @@ static const struct unix_funcs funcs = unix_logbf, unix_modf, unix_modff, - unix_nearbyint, unix_nextafter, unix_nextafterf, unix_nexttoward, diff --git a/dlls/msvcrt/unixlib.h b/dlls/msvcrt/unixlib.h index d8b5e6b3f24..ecdbdf0cca1 100644 --- a/dlls/msvcrt/unixlib.h +++ b/dlls/msvcrt/unixlib.h @@ -72,7 +72,6 @@ struct unix_funcs float (CDECL *logbf)(float x); double (CDECL *modf)(double x, double *iptr); float (CDECL *modff)(float x, float *iptr); - double (CDECL *nearbyint)(double num); double (CDECL *nextafter)(double x, double y); float (CDECL *nextafterf)(float x, float y); double (CDECL *nexttoward)(double x, double y); diff --git a/include/config.h.in b/include/config.h.in index 896d44cd71e..a638c0382c9 100644 --- a/include/config.h.in +++ b/include/config.h.in @@ -501,9 +501,6 @@ /* Define if MTLDevice protocol has registryID property. */ #undef HAVE_MTLDEVICE_REGISTRYID -/* Define to 1 if you have the `nearbyint' function. */ -#undef HAVE_NEARBYINT - /* Define to 1 if you have the header file. */ #undef HAVE_NETDB_H