Alexandre Julliard : msvcrt: Reimplement _dclass() using musl code.

Alexandre Julliard julliard at winehq.org
Mon Nov 16 15:28:56 CST 2020


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

Author: Alexandre Julliard <julliard at winehq.org>
Date:   Mon Nov 16 12:09:43 2020 +0100

msvcrt: Reimplement _dclass() using musl code.

Signed-off-by: Alexandre Julliard <julliard at winehq.org>

---

 dlls/msvcrt/math.c | 37 +++++++++++++++++--------------------
 1 file changed, 17 insertions(+), 20 deletions(-)

diff --git a/dlls/msvcrt/math.c b/dlls/msvcrt/math.c
index a9cf224575a..f113943c392 100644
--- a/dlls/msvcrt/math.c
+++ b/dlls/msvcrt/math.c
@@ -3678,35 +3678,32 @@ LDOUBLE CDECL MSVCR120_truncl(LDOUBLE x)
 
 /*********************************************************************
  *      _dclass (MSVCR120.@)
+ *
+ * Copied from musl: src/math/__fpclassify.c
  */
 short CDECL MSVCR120__dclass(double x)
 {
-    switch (MSVCRT__fpclass(x)) {
-    case MSVCRT__FPCLASS_QNAN:
-    case MSVCRT__FPCLASS_SNAN:
-        return MSVCRT_FP_NAN;
-    case MSVCRT__FPCLASS_NINF:
-    case MSVCRT__FPCLASS_PINF:
-        return MSVCRT_FP_INFINITE;
-    case MSVCRT__FPCLASS_ND:
-    case MSVCRT__FPCLASS_PD:
-        return MSVCRT_FP_SUBNORMAL;
-    case MSVCRT__FPCLASS_NN:
-    case MSVCRT__FPCLASS_PN:
-    default:
-        return MSVCRT_FP_NORMAL;
-    case MSVCRT__FPCLASS_NZ:
-    case MSVCRT__FPCLASS_PZ:
-        return MSVCRT_FP_ZERO;
-    }
+    union { double f; UINT64 i; } u = { x };
+    int e = u.i >> 52 & 0x7ff;
+
+    if (!e) return u.i << 1 ? MSVCRT_FP_SUBNORMAL : MSVCRT_FP_ZERO;
+    if (e == 0x7ff) return (u.i << 12) ? MSVCRT_FP_NAN : MSVCRT_FP_INFINITE;
+    return MSVCRT_FP_NORMAL;
 }
 
 /*********************************************************************
  *      _fdclass (MSVCR120.@)
+ *
+ * Copied from musl: src/math/__fpclassifyf.c
  */
 short CDECL MSVCR120__fdclass(float x)
 {
-    return MSVCR120__dclass(x);
+    union { float f; UINT32 i; } u = { x };
+    int e = u.i >> 23 & 0xff;
+
+    if (!e) return u.i << 1 ? MSVCRT_FP_SUBNORMAL : MSVCRT_FP_ZERO;
+    if (e == 0xff) return u.i << 9 ? MSVCRT_FP_NAN : MSVCRT_FP_INFINITE;
+    return MSVCRT_FP_NORMAL;
 }
 
 /*********************************************************************
@@ -3730,7 +3727,7 @@ short CDECL MSVCR120__dtest(double *x)
  */
 short CDECL MSVCR120__fdtest(float *x)
 {
-    return MSVCR120__dclass(*x);
+    return MSVCR120__fdclass(*x);
 }
 
 /*********************************************************************




More information about the wine-cvs mailing list