Piotr Caban : msvcrt: Import rintf implementation from musl.

Alexandre Julliard julliard at winehq.org
Mon May 10 15:44:05 CDT 2021


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

Author: Piotr Caban <piotr at codeweavers.com>
Date:   Mon May 10 20:11:40 2021 +0200

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

diff --git a/configure b/configure
index 59248c28c99..25161a1f27a 100755
--- a/configure
+++ b/configure
@@ -19652,7 +19652,6 @@ for ac_func in \
 	remainderf \
 	remquo \
 	remquof \
-	rintf \
 	tgamma \
 	tgammaf \
 	trunc \
diff --git a/configure.ac b/configure.ac
index 0c1ea608d7e..46d6f17fe73 100644
--- a/configure.ac
+++ b/configure.ac
@@ -2692,7 +2692,6 @@ AC_CHECK_FUNCS(\
 	remainderf \
 	remquo \
 	remquof \
-	rintf \
 	tgamma \
 	tgammaf \
 	trunc \
diff --git a/dlls/msvcrt/math.c b/dlls/msvcrt/math.c
index c1702c5b810..1e67aa03964 100644
--- a/dlls/msvcrt/math.c
+++ b/dlls/msvcrt/math.c
@@ -4312,10 +4312,27 @@ double CDECL rint(double x)
 
 /*********************************************************************
  *      rintf (MSVCR120.@)
+ *
+ * Copied from musl: src/math/rintf.c
  */
 float CDECL rintf(float x)
 {
-    return unix_funcs->rintf(x);
+    static const float toint = 1 / FLT_EPSILON;
+
+    unsigned int ix = *(unsigned int*)&x;
+    int e = ix >> 23 & 0xff;
+    int s = ix >> 31;
+    float y;
+
+    if (e >= 0x7f + 23)
+        return x;
+    if (s)
+        y = fp_barrierf(x - toint) + toint;
+    else
+        y = fp_barrierf(x + toint) - toint;
+    if (y == 0)
+        return s ? -0.0f : 0.0f;
+    return y;
 }
 
 /*********************************************************************
diff --git a/dlls/msvcrt/unixlib.c b/dlls/msvcrt/unixlib.c
index f72fd0cc161..e36c2e047b9 100644
--- a/dlls/msvcrt/unixlib.c
+++ b/dlls/msvcrt/unixlib.c
@@ -729,18 +729,6 @@ static float CDECL unix_remquof(float x, float y, int *quo)
 #endif
 }
 
-/*********************************************************************
- *      rintf
- */
-static float CDECL unix_rintf(float x)
-{
-#ifdef HAVE_RINTF
-    return rintf(x);
-#else
-    return x >= 0 ? floorf(x + 0.5) : ceilf(x - 0.5);
-#endif
-}
-
 /*********************************************************************
  *      sin
  */
@@ -922,7 +910,6 @@ static const struct unix_funcs funcs =
     unix_remainderf,
     unix_remquo,
     unix_remquof,
-    unix_rintf,
     unix_sin,
     unix_sinf,
     unix_sinh,
diff --git a/dlls/msvcrt/unixlib.h b/dlls/msvcrt/unixlib.h
index f5245cfb645..74545507b26 100644
--- a/dlls/msvcrt/unixlib.h
+++ b/dlls/msvcrt/unixlib.h
@@ -88,7 +88,6 @@ struct unix_funcs
     float           (CDECL *remainderf)(float x, float y);
     double          (CDECL *remquo)(double x, double y, int *quo);
     float           (CDECL *remquof)(float x, float y, int *quo);
-    float           (CDECL *rintf)(float x);
     double          (CDECL *sin)(double x);
     float           (CDECL *sinf)(float x);
     double          (CDECL *sinh)(double x);
diff --git a/include/config.h.in b/include/config.h.in
index 181cbc3d5aa..ee34d528122 100644
--- a/include/config.h.in
+++ b/include/config.h.in
@@ -684,9 +684,6 @@
 /* Define to 1 if you have the `res_getservers' function. */
 #undef HAVE_RES_GETSERVERS
 
-/* Define to 1 if you have the `rintf' function. */
-#undef HAVE_RINTF
-
 /* Define to 1 if you have the <sasl/sasl.h> header file. */
 #undef HAVE_SASL_SASL_H
 




More information about the wine-cvs mailing list