Piotr Caban : msvcrt: Import atanf implementation from musl.

Alexandre Julliard julliard at winehq.org
Tue May 25 16:08:16 CDT 2021


Module: wine
Branch: master
Commit: ed49a95d1e0ba985f9e101e3769d722894f5803f
URL:    https://source.winehq.org/git/wine.git/?a=commit;h=ed49a95d1e0ba985f9e101e3769d722894f5803f

Author: Piotr Caban <piotr at codeweavers.com>
Date:   Tue May 25 15:21:18 2021 +0200

msvcrt: Import atanf 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    | 28 ++++++++++++++++++++++------
 dlls/msvcrt/unixlib.c | 13 -------------
 dlls/msvcrt/unixlib.h |  1 -
 include/config.h.in   |  3 ---
 6 files changed, 22 insertions(+), 25 deletions(-)

diff --git a/configure b/configure
index 9b41d4ff072..860d57b4868 100755
--- a/configure
+++ b/configure
@@ -19617,7 +19617,6 @@ fi
 
 for ac_func in \
 	atanh \
-	atanhf \
 	exp2 \
 	exp2f \
 	expm1 \
diff --git a/configure.ac b/configure.ac
index 6674e0d15df..f8ade3af9e6 100644
--- a/configure.ac
+++ b/configure.ac
@@ -2657,7 +2657,6 @@ fi
 
 AC_CHECK_FUNCS(\
 	atanh \
-	atanhf \
 	exp2 \
 	exp2f \
 	expm1 \
diff --git a/dlls/msvcrt/math.c b/dlls/msvcrt/math.c
index 8d4ca7bb3fb..0bffbcdd8a2 100644
--- a/dlls/msvcrt/math.c
+++ b/dlls/msvcrt/math.c
@@ -6687,21 +6687,37 @@ double CDECL atanh(double x)
 
 /*********************************************************************
  *      atanhf (MSVCR120.@)
+ *
+ * Copied from musl: src/math/atanhf.c
  */
 float CDECL atanhf(float x)
 {
-    float ret;
+    UINT32 ux = *(UINT32*)&x;
+    int s = ux >> 31;
 
-    if (x > 1 || x < -1) {
+    /* |x| */
+    ux &= 0x7fffffff;
+    x = *(float*)&ux;
+
+    if (x > 1) {
         *_errno() = EDOM;
         feraiseexcept(FE_INVALID);
         return NAN;
     }
 
-    ret = unix_funcs->atanh( x );
-
-    if (!isfinite(ret)) *_errno() = ERANGE;
-    return ret;
+    if (ux < 0x3f800000 - (1 << 23)) {
+        if (ux < 0x3f800000 - (32 << 23)) {
+            fp_barrierf(x + 0x1p120f);
+            if (ux < (1 << 23)) /* handle underflow */
+                fp_barrierf(x * x);
+        } else { /* |x| < 0.5, up to 1.7ulp error */
+            x = 0.5f * log1pf(2 * x + 2 * x * x / (1 - x));
+        }
+    } else { /* avoid overflow */
+        x = 0.5f * log1pf(2 * (x / (1 - x)));
+        if (isinf(x)) *_errno() = ERANGE;
+    }
+    return s ? -x : x;
 }
 
 #endif /* _MSVCR_VER>=120 */
diff --git a/dlls/msvcrt/unixlib.c b/dlls/msvcrt/unixlib.c
index ce055c8ea03..b044a209045 100644
--- a/dlls/msvcrt/unixlib.c
+++ b/dlls/msvcrt/unixlib.c
@@ -55,18 +55,6 @@ static double CDECL unix_atanh(double x)
 #endif
 }
 
-/*********************************************************************
- *      atanhf
- */
-static float CDECL unix_atanhf(float x)
-{
-#ifdef HAVE_ATANHF
-    return atanhf(x);
-#else
-    return unix_atanh(x);
-#endif
-}
-
 /*********************************************************************
  *      cosh
  */
@@ -394,7 +382,6 @@ static float CDECL unix_tgammaf(float x)
 static const struct unix_funcs funcs =
 {
     unix_atanh,
-    unix_atanhf,
     unix_cosh,
     unix_coshf,
     unix_exp,
diff --git a/dlls/msvcrt/unixlib.h b/dlls/msvcrt/unixlib.h
index f915f2f92d0..90b55addd4c 100644
--- a/dlls/msvcrt/unixlib.h
+++ b/dlls/msvcrt/unixlib.h
@@ -24,7 +24,6 @@
 struct unix_funcs
 {
     double          (CDECL *atanh)(double x);
-    float           (CDECL *atanhf)(float 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 bca2d843e58..132922e1f8c 100644
--- a/include/config.h.in
+++ b/include/config.h.in
@@ -34,9 +34,6 @@
 /* Define to 1 if you have the `atanh' function. */
 #undef HAVE_ATANH
 
-/* Define to 1 if you have the `atanhf' function. */
-#undef HAVE_ATANHF
-
 /* 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