Piotr Caban : msvcrt: Import trunc implementation from musl.
Alexandre Julliard
julliard at winehq.org
Mon May 17 15:45:31 CDT 2021
Module: wine
Branch: master
Commit: f2c18726605315a93f733b583a61fb5417f4dde0
URL: https://source.winehq.org/git/wine.git/?a=commit;h=f2c18726605315a93f733b583a61fb5417f4dde0
Author: Piotr Caban <piotr at codeweavers.com>
Date: Mon May 17 15:38:22 2021 +0200
msvcrt: Import trunc implementation from musl.
Signed-off-by: Piotr Caban <piotr at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>
---
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 fe54e30321f..7c2e31de5af 100755
--- a/configure
+++ b/configure
@@ -19643,8 +19643,7 @@ for ac_func in \
remquo \
remquof \
tgamma \
- tgammaf \
- trunc
+ tgammaf
do :
as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh`
diff --git a/configure.ac b/configure.ac
index fb4ec181ea2..4c98c3e5597 100644
--- a/configure.ac
+++ b/configure.ac
@@ -2683,8 +2683,7 @@ AC_CHECK_FUNCS(\
remquo \
remquof \
tgamma \
- tgammaf \
- trunc
+ tgammaf
)
LIBS="$ac_save_LIBS"
diff --git a/dlls/msvcrt/math.c b/dlls/msvcrt/math.c
index 246f329ee95..f2caa81712b 100644
--- a/dlls/msvcrt/math.c
+++ b/dlls/msvcrt/math.c
@@ -4981,10 +4981,24 @@ __int64 CDECL llroundf(float x)
/*********************************************************************
* trunc (MSVCR120.@)
+ *
+ * Copied from musl: src/math/trunc.c
*/
double CDECL trunc(double x)
{
- return unix_funcs->trunc(x);
+ union {double f; UINT64 i;} u = {x};
+ int e = (u.i >> 52 & 0x7ff) - 0x3ff + 12;
+ UINT64 m;
+
+ if (e >= 52 + 12)
+ return x;
+ if (e < 12)
+ e = 1;
+ m = -1ULL >> 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 e809d7353ff..d7e368d1b37 100644
--- a/dlls/msvcrt/unixlib.c
+++ b/dlls/msvcrt/unixlib.c
@@ -636,18 +636,6 @@ static double CDECL unix_tgamma(double x)
#endif
}
-/*********************************************************************
- * trunc
- */
-static double CDECL unix_trunc(double x)
-{
-#ifdef HAVE_TRUNC
- return trunc(x);
-#else
- return (x > 0) ? floor(x) : ceil(x);
-#endif
-}
-
/*********************************************************************
* tgammaf
*/
@@ -722,7 +710,6 @@ static const struct unix_funcs funcs =
unix_tanhf,
unix_tgamma,
unix_tgammaf,
- unix_trunc,
};
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 fd279cf5519..b8c18b1e2a5 100644
--- a/dlls/msvcrt/unixlib.h
+++ b/dlls/msvcrt/unixlib.h
@@ -82,7 +82,6 @@ struct unix_funcs
float (CDECL *tanhf)(float x);
double (CDECL *tgamma)(double x);
float (CDECL *tgammaf)(float x);
- double (CDECL *trunc)(double x);
};
#endif /* __UNIXLIB_H */
diff --git a/include/config.h.in b/include/config.h.in
index 7fe9383a778..bf7fc0d4e9b 100644
--- a/include/config.h.in
+++ b/include/config.h.in
@@ -1010,9 +1010,6 @@
/* Define to 1 if you have the <tiffio.h> header file. */
#undef HAVE_TIFFIO_H
-/* Define to 1 if you have the `trunc' function. */
-#undef HAVE_TRUNC
-
/* Define to 1 if you have the `udev' library (-ludev). */
#undef HAVE_UDEV
More information about the wine-cvs
mailing list