Piotr Caban : msvcrt: Import atanh implementation from musl.
Alexandre Julliard
julliard at winehq.org
Tue May 25 16:08:16 CDT 2021
Module: wine
Branch: master
Commit: ff033db60b41fcbb35a3dcca4ab181db43dd2029
URL: https://source.winehq.org/git/wine.git/?a=commit;h=ff033db60b41fcbb35a3dcca4ab181db43dd2029
Author: Piotr Caban <piotr at codeweavers.com>
Date: Tue May 25 15:21:24 2021 +0200
msvcrt: Import atanh implementation from musl.
Signed-off-by: Piotr Caban <piotr at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>
---
configure | 1 -
configure.ac | 1 -
dlls/msvcrt/math.c | 29 +++++++++++++++++++++++------
dlls/msvcrt/unixlib.c | 14 --------------
dlls/msvcrt/unixlib.h | 1 -
include/config.h.in | 3 ---
6 files changed, 23 insertions(+), 26 deletions(-)
diff --git a/configure b/configure
index 860d57b4868..0aa6e54804c 100755
--- a/configure
+++ b/configure
@@ -19616,7 +19616,6 @@ $as_echo "#define HAVE_ISNAN 1" >>confdefs.h
fi
for ac_func in \
- atanh \
exp2 \
exp2f \
expm1 \
diff --git a/configure.ac b/configure.ac
index f8ade3af9e6..821b2bb092b 100644
--- a/configure.ac
+++ b/configure.ac
@@ -2656,7 +2656,6 @@ then
fi
AC_CHECK_FUNCS(\
- atanh \
exp2 \
exp2f \
expm1 \
diff --git a/dlls/msvcrt/math.c b/dlls/msvcrt/math.c
index 0bffbcdd8a2..732d2084285 100644
--- a/dlls/msvcrt/math.c
+++ b/dlls/msvcrt/math.c
@@ -6668,21 +6668,38 @@ float CDECL acoshf(float x)
/*********************************************************************
* atanh (MSVCR120.@)
+ *
+ * Copied from musl: src/math/atanh.c
*/
double CDECL atanh(double x)
{
- double ret;
+ UINT64 ux = *(UINT64*)&x;
+ int e = ux >> 52 & 0x7ff;
+ int s = ux >> 63;
- if (x > 1 || x < -1) {
+ /* |x| */
+ ux &= (UINT64)-1 / 2;
+ x = *(double*)&ux;
+
+ if (x > 1) {
*_errno() = EDOM;
- /* on Linux atanh returns -NAN in this case */
feraiseexcept(FE_INVALID);
return NAN;
}
- ret = unix_funcs->atanh( x );
- if (!isfinite(ret)) *_errno() = ERANGE;
- return ret;
+ if (e < 0x3ff - 1) {
+ if (e < 0x3ff - 32) {
+ fp_barrier(x + 0x1p120f);
+ if (e == 0) /* handle underflow */
+ fp_barrier(x * x);
+ } else { /* |x| < 0.5, up to 1.7ulp error */
+ x = 0.5 * log1p(2 * x + 2 * x * x / (1 - x));
+ }
+ } else { /* avoid overflow */
+ x = 0.5 * log1p(2 * (x / (1 - x)));
+ if (isinf(x)) *_errno() = ERANGE;
+ }
+ return s ? -x : x;
}
/*********************************************************************
diff --git a/dlls/msvcrt/unixlib.c b/dlls/msvcrt/unixlib.c
index b044a209045..6d3a3bd5a79 100644
--- a/dlls/msvcrt/unixlib.c
+++ b/dlls/msvcrt/unixlib.c
@@ -42,19 +42,6 @@
WINE_DEFAULT_DEBUG_CHANNEL(msvcrt);
-/*********************************************************************
- * atanh
- */
-static double CDECL unix_atanh(double x)
-{
-#ifdef HAVE_ATANH
- return atanh(x);
-#else
- if (-1e-6 < x && x < 1e-6) return x + x*x*x/3;
- else return (log(1+x) - log(1-x)) / 2;
-#endif
-}
-
/*********************************************************************
* cosh
*/
@@ -381,7 +368,6 @@ static float CDECL unix_tgammaf(float x)
static const struct unix_funcs funcs =
{
- unix_atanh,
unix_cosh,
unix_coshf,
unix_exp,
diff --git a/dlls/msvcrt/unixlib.h b/dlls/msvcrt/unixlib.h
index 90b55addd4c..06f0d6ec5c9 100644
--- a/dlls/msvcrt/unixlib.h
+++ b/dlls/msvcrt/unixlib.h
@@ -23,7 +23,6 @@
struct unix_funcs
{
- double (CDECL *atanh)(double x);
double (CDECL *cosh)(double x);
float (CDECL *coshf)(float x);
double (CDECL *exp)(double x);
diff --git a/include/config.h.in b/include/config.h.in
index 132922e1f8c..6ea3949541b 100644
--- a/include/config.h.in
+++ b/include/config.h.in
@@ -31,9 +31,6 @@
/* Define to 1 if you have the <asm/user.h> header file. */
#undef HAVE_ASM_USER_H
-/* Define to 1 if you have the `atanh' function. */
-#undef HAVE_ATANH
-
/* Define to 1 if you have the <AudioToolbox/AudioConverter.h> header file. */
#undef HAVE_AUDIOTOOLBOX_AUDIOCONVERTER_H
More information about the wine-cvs
mailing list