Alexandre Julliard : ntdll: Copy floor() implementation from msvcrt.

Alexandre Julliard julliard at winehq.org
Tue Oct 26 16:19:19 CDT 2021


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

Author: Alexandre Julliard <julliard at winehq.org>
Date:   Tue Oct 26 10:33:43 2021 +0200

ntdll: Copy floor() implementation from msvcrt.

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

---

 dlls/ntdll/math.c | 25 +++++++++++++++++++++++--
 1 file changed, 23 insertions(+), 2 deletions(-)

diff --git a/dlls/ntdll/math.c b/dlls/ntdll/math.c
index e7f5987a5af..a7d20acdf59 100644
--- a/dlls/ntdll/math.c
+++ b/dlls/ntdll/math.c
@@ -191,10 +191,31 @@ double CDECL fabs( double d )
 
 /*********************************************************************
  *                  floor   (NTDLL.@)
+ *
+ * Based on musl: src/math/floorf.c
  */
-double CDECL floor( double d )
+double CDECL floor( double x )
 {
-    return unix_funcs->floor( d );
+    union {double f; UINT64 i;} u = {x};
+    int e = (int)(u.i >> 52 & 0x7ff) - 0x3ff;
+    UINT64 m;
+
+    if (e >= 52)
+        return x;
+    if (e >= 0) {
+        m = 0x000fffffffffffffULL >> e;
+        if ((u.i & m) == 0)
+            return x;
+        if (u.i >> 63)
+            u.i += m;
+        u.i &= ~m;
+    } else {
+        if (u.i >> 63 == 0)
+            return 0;
+        else if (u.i << 1)
+            return -1;
+    }
+    return u.f;
 }
 
 /*********************************************************************




More information about the wine-cvs mailing list