Piotr Caban : msvcrt: Import roundf implementation from musl.

Alexandre Julliard julliard at winehq.org
Thu Apr 29 16:38:32 CDT 2021


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

Author: Piotr Caban <piotr at codeweavers.com>
Date:   Thu Apr 29 17:06:27 2021 +0200

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

diff --git a/configure b/configure
index 429d97ebfdc..1ff743f0328 100755
--- a/configure
+++ b/configure
@@ -19656,7 +19656,6 @@ for ac_func in \
 	rint \
 	rintf \
 	round \
-	roundf \
 	tgamma \
 	tgammaf \
 	trunc \
diff --git a/configure.ac b/configure.ac
index e9dde0f9781..8ce76f1d645 100644
--- a/configure.ac
+++ b/configure.ac
@@ -2699,7 +2699,6 @@ AC_CHECK_FUNCS(\
 	rint \
 	rintf \
 	round \
-	roundf \
 	tgamma \
 	tgammaf \
 	trunc \
diff --git a/dlls/msvcrt/math.c b/dlls/msvcrt/math.c
index 5a0c0874ee5..586f8950e0a 100644
--- a/dlls/msvcrt/math.c
+++ b/dlls/msvcrt/math.c
@@ -4329,10 +4329,33 @@ double CDECL round(double x)
 
 /*********************************************************************
  *      roundf (MSVCR120.@)
+ *
+ * Copied from musl: src/math/roundf.c
  */
 float CDECL roundf(float x)
 {
-    return unix_funcs->roundf(x);
+    static const float toint = 1 / FLT_EPSILON;
+
+    unsigned int ix = *(unsigned int*)&x;
+    int e = ix >> 23 & 0xff;
+    float y;
+
+    if (e >= 0x7f + 23)
+        return x;
+    if (ix >> 31)
+        x = -x;
+    if (e < 0x7f - 1)
+        return 0 * *(float*)&ix;
+    y = fp_barrierf(x + toint) - toint - x;
+    if (y > 0.5f)
+        y = y + x - 1;
+    else if (y <= -0.5f)
+        y = y + x + 1;
+    else
+        y = y + x;
+    if (ix >> 31)
+        y = -y;
+    return y;
 }
 
 /*********************************************************************
diff --git a/dlls/msvcrt/unixlib.c b/dlls/msvcrt/unixlib.c
index d62110c0006..456cb3de574 100644
--- a/dlls/msvcrt/unixlib.c
+++ b/dlls/msvcrt/unixlib.c
@@ -765,18 +765,6 @@ static double CDECL unix_round(double x)
 #endif
 }
 
-/*********************************************************************
- *      roundf
- */
-static float CDECL unix_roundf(float x)
-{
-#ifdef HAVE_ROUNDF
-    return roundf(x);
-#else
-    return unix_round(x);
-#endif
-}
-
 /*********************************************************************
  *      lround
  */
@@ -1013,7 +1001,6 @@ static const struct unix_funcs funcs =
     unix_rint,
     unix_rintf,
     unix_round,
-    unix_roundf,
     unix_sin,
     unix_sinf,
     unix_sinh,
diff --git a/dlls/msvcrt/unixlib.h b/dlls/msvcrt/unixlib.h
index 5f1f79d5e4b..2841a28f478 100644
--- a/dlls/msvcrt/unixlib.h
+++ b/dlls/msvcrt/unixlib.h
@@ -95,7 +95,6 @@ struct unix_funcs
     double          (CDECL *rint)(double x);
     float           (CDECL *rintf)(float x);
     double          (CDECL *round)(double x);
-    float           (CDECL *roundf)(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 11f29fcf8bc..749b79e1092 100644
--- a/include/config.h.in
+++ b/include/config.h.in
@@ -705,9 +705,6 @@
 /* Define to 1 if you have the `round' function. */
 #undef HAVE_ROUND
 
-/* Define to 1 if you have the `roundf' function. */
-#undef HAVE_ROUNDF
-
 /* 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