From 5544e6de07392395b907333afd8b0e71e1a166aa Mon Sep 17 00:00:00 2001 From: Piotr Caban Date: Mon, 17 May 2021 15:38:18 +0200 Subject: [PATCH] msvcrt: Import truncf implementation from musl. Signed-off-by: Piotr Caban Signed-off-by: Alexandre Julliard --- configure | 3 +-- configure.ac | 3 +-- dlls/msvcrt/math.c | 16 +++++++++++++++- dlls/msvcrt/unixlib.c | 13 ------------- dlls/msvcrt/unixlib.h | 1 - include/config.h.in | 3 --- 6 files changed, 17 insertions(+), 22 deletions(-) diff --git a/configure b/configure index 69b97958832..fe54e30321f 100755 --- a/configure +++ b/configure @@ -19644,8 +19644,7 @@ for ac_func in \ remquof \ tgamma \ tgammaf \ - trunc \ - truncf + trunc do : as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh` diff --git a/configure.ac b/configure.ac index 7fde36f7616..fb4ec181ea2 100644 --- a/configure.ac +++ b/configure.ac @@ -2684,8 +2684,7 @@ AC_CHECK_FUNCS(\ remquof \ tgamma \ tgammaf \ - trunc \ - truncf + trunc ) LIBS="$ac_save_LIBS" diff --git a/dlls/msvcrt/math.c b/dlls/msvcrt/math.c index 5682b00bb66..246f329ee95 100644 --- a/dlls/msvcrt/math.c +++ b/dlls/msvcrt/math.c @@ -4989,10 +4989,24 @@ double CDECL trunc(double x) /********************************************************************* * truncf (MSVCR120.@) + * + * Copied from musl: src/math/truncf.c */ float CDECL truncf(float x) { - return unix_funcs->truncf(x); + union {float f; UINT32 i;} u = {x}; + int e = (u.i >> 23 & 0xff) - 0x7f + 9; + UINT32 m; + + if (e >= 23 + 9) + return x; + if (e < 9) + e = 1; + m = -1U >> e; + if ((u.i & m) == 0) + return x; + u.i &= ~m; + return u.f; } /********************************************************************* diff --git a/dlls/msvcrt/unixlib.c b/dlls/msvcrt/unixlib.c index 83a1e5386c1..e809d7353ff 100644 --- a/dlls/msvcrt/unixlib.c +++ b/dlls/msvcrt/unixlib.c @@ -648,18 +648,6 @@ static double CDECL unix_trunc(double x) #endif } -/********************************************************************* - * truncf - */ -static float CDECL unix_truncf(float x) -{ -#ifdef HAVE_TRUNCF - return truncf(x); -#else - return unix_trunc(x); -#endif -} - /********************************************************************* * tgammaf */ @@ -735,7 +723,6 @@ static const struct unix_funcs funcs = unix_tgamma, unix_tgammaf, unix_trunc, - unix_truncf }; NTSTATUS CDECL __wine_init_unix_lib( HMODULE module, DWORD reason, const void *ptr_in, void *ptr_out ) diff --git a/dlls/msvcrt/unixlib.h b/dlls/msvcrt/unixlib.h index a86e2d34852..fd279cf5519 100644 --- a/dlls/msvcrt/unixlib.h +++ b/dlls/msvcrt/unixlib.h @@ -83,7 +83,6 @@ struct unix_funcs double (CDECL *tgamma)(double x); float (CDECL *tgammaf)(float x); double (CDECL *trunc)(double x); - float (CDECL *truncf)(float x); }; #endif /* __UNIXLIB_H */ diff --git a/include/config.h.in b/include/config.h.in index ce83ecacd8e..7fe9383a778 100644 --- a/include/config.h.in +++ b/include/config.h.in @@ -1013,9 +1013,6 @@ /* Define to 1 if you have the `trunc' function. */ #undef HAVE_TRUNC -/* Define to 1 if you have the `truncf' function. */ -#undef HAVE_TRUNCF - /* Define to 1 if you have the `udev' library (-ludev). */ #undef HAVE_UDEV