Piotr Caban : msvcrt: Import _logb implementation from musl.

Alexandre Julliard julliard at winehq.org
Fri May 21 14:19:44 CDT 2021


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

Author: Piotr Caban <piotr at codeweavers.com>
Date:   Thu May 20 23:04:36 2021 +0200

msvcrt: Import _logb implementation from musl.

Signed-off-by: Piotr Caban <piotr at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>

---

 dlls/msvcrt/math.c    | 47 +++++++++++++++++++++++++++--------------------
 dlls/msvcrt/unixlib.c |  9 ---------
 dlls/msvcrt/unixlib.h |  1 -
 3 files changed, 27 insertions(+), 30 deletions(-)

diff --git a/dlls/msvcrt/math.c b/dlls/msvcrt/math.c
index 2e2161e91c4..df00f0532bb 100644
--- a/dlls/msvcrt/math.c
+++ b/dlls/msvcrt/math.c
@@ -1897,15 +1897,36 @@ __int64 CDECL _abs64( __int64 n )
     return n >= 0 ? n : -n;
 }
 
+/* Copied from musl: src/math/ilogb.c */
+static int __ilogb(double x)
+{
+    union { double f; UINT64 i; } u = { x };
+    int e = u.i >> 52 & 0x7ff;
+
+    if (!e)
+    {
+        u.i <<= 12;
+        if (u.i == 0) return FP_ILOGB0;
+        /* subnormal x */
+        for (e = -0x3ff; u.i >> 63 == 0; e--, u.i <<= 1);
+        return e;
+    }
+    if (e == 0x7ff) return u.i << 12 ? FP_ILOGBNAN : INT_MAX;
+    return e - 0x3ff;
+}
+
 /*********************************************************************
  *		_logb (MSVCRT.@)
+ *
+ * Copied from musl: src/math/logb.c
  */
-double CDECL _logb(double num)
+double CDECL _logb(double x)
 {
-  double ret = unix_funcs->logb(num);
-  if (isnan(num)) return math_error(_DOMAIN, "_logb", num, 0, ret);
-  if (!num) return math_error(_SING, "_logb", num, 0, ret);
-  return ret;
+    if (!isfinite(x))
+        return x * x;
+    if (x == 0)
+        return math_error(_SING, "_logb", x, 0, -1 / (x * x));
+    return __ilogb(x);
 }
 
 /*********************************************************************
@@ -6149,24 +6170,10 @@ double CDECL MSVCR120_creal(_Dcomplex z)
 
 /*********************************************************************
  *      ilogb (MSVCR120.@)
- *
- * Copied from musl: src/math/ilogb.c
  */
 int CDECL ilogb(double x)
 {
-    union { double f; UINT64 i; } u = { x };
-    int e = u.i >> 52 & 0x7ff;
-
-    if (!e)
-    {
-        u.i <<= 12;
-        if (u.i == 0) return FP_ILOGB0;
-        /* subnormal x */
-        for (e = -0x3ff; u.i >> 63 == 0; e--, u.i <<= 1);
-        return e;
-    }
-    if (e == 0x7ff) return u.i << 12 ? FP_ILOGBNAN : INT_MAX;
-    return e - 0x3ff;
+    return __ilogb(x);
 }
 
 /*********************************************************************
diff --git a/dlls/msvcrt/unixlib.c b/dlls/msvcrt/unixlib.c
index fd82c5afb94..51fe7ef6f0f 100644
--- a/dlls/msvcrt/unixlib.c
+++ b/dlls/msvcrt/unixlib.c
@@ -387,14 +387,6 @@ static float CDECL unix_log2f(float x)
 #endif
 }
 
-/*********************************************************************
- *      logb
- */
-static double CDECL unix_logb( double x )
-{
-    return logb( x );
-}
-
 /*********************************************************************
  *      logbf
  */
@@ -544,7 +536,6 @@ static const struct unix_funcs funcs =
     unix_log1pf,
     unix_log2,
     unix_log2f,
-    unix_logb,
     unix_logbf,
     unix_pow,
     unix_powf,
diff --git a/dlls/msvcrt/unixlib.h b/dlls/msvcrt/unixlib.h
index 95b4a6488de..a0cded99e20 100644
--- a/dlls/msvcrt/unixlib.h
+++ b/dlls/msvcrt/unixlib.h
@@ -56,7 +56,6 @@ struct unix_funcs
     float           (CDECL *log1pf)(float x);
     double          (CDECL *log2)(double x);
     float           (CDECL *log2f)(float x);
-    double          (CDECL *logb)(double x);
     float           (CDECL *logbf)(float x);
     double          (CDECL *pow)(double x, double y);
     float           (CDECL *powf)(float x, float y);




More information about the wine-cvs mailing list