Alexandre Julliard : msvcrt: Import _copysign() from musl.

Alexandre Julliard julliard at winehq.org
Tue Nov 17 15:04:07 CST 2020


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

Author: Alexandre Julliard <julliard at winehq.org>
Date:   Tue Nov 17 09:57:52 2020 +0100

msvcrt: Import _copysign() from musl.

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

---

 dlls/msvcrt/math.c | 22 ++++++++++++++--------
 1 file changed, 14 insertions(+), 8 deletions(-)

diff --git a/dlls/msvcrt/math.c b/dlls/msvcrt/math.c
index 8e8324b8fbe..069a2f7f387 100644
--- a/dlls/msvcrt/math.c
+++ b/dlls/msvcrt/math.c
@@ -177,12 +177,15 @@ float CDECL MSVCRT__chgsignf( float num )
 
 /*********************************************************************
  *      _copysignf (MSVCRT.@)
+ *
+ * Copied from musl: src/math/copysignf.c
  */
-float CDECL MSVCRT__copysignf( float num, float sign )
+float CDECL MSVCRT__copysignf( float x, float y )
 {
-    if (signbit(sign))
-        return signbit(num) ? num : -num;
-    return signbit(num) ? -num : num;
+    union { float f; UINT32 i; } ux = { x }, uy = { y };
+    ux.i &= 0x7fffffff;
+    ux.i |= uy.i & 0x80000000;
+    return ux.f;
 }
 
 /*********************************************************************
@@ -2126,12 +2129,15 @@ int CDECL MSVCRT_fesetround(int round_mode)
 
 /*********************************************************************
  *		_copysign (MSVCRT.@)
+ *
+ * Copied from musl: src/math/copysign.c
  */
-double CDECL MSVCRT__copysign(double num, double sign)
+double CDECL MSVCRT__copysign( double x, double y )
 {
-  if (signbit(sign))
-    return signbit(num) ? num : -num;
-  return signbit(num) ? -num : num;
+    union { double f; UINT64 i; } ux = { x }, uy = { y };
+    ux.i &= ~0ull >> 1;
+    ux.i |= uy.i & 1ull << 63;
+    return ux.f;
 }
 
 /*********************************************************************




More information about the wine-cvs mailing list