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

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


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

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

ntdll: Copy tan() implementation from msvcrt.

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

---

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

diff --git a/dlls/ntdll/math.c b/dlls/ntdll/math.c
index 55d82cc3f8e..58965c7b169 100644
--- a/dlls/ntdll/math.c
+++ b/dlls/ntdll/math.c
@@ -507,6 +507,65 @@ static double __cos(double x, double y)
     return w + (((1.0 - w) - hz) + (z * r - x * y));
 }
 
+/* Copied from musl: src/math/__tan.c */
+static double __tan(double x, double y, int odd)
+{
+    static const double T[] = {
+        3.33333333333334091986e-01,
+        1.33333333333201242699e-01,
+        5.39682539762260521377e-02,
+        2.18694882948595424599e-02,
+        8.86323982359930005737e-03,
+        3.59207910759131235356e-03,
+        1.45620945432529025516e-03,
+        5.88041240820264096874e-04,
+        2.46463134818469906812e-04,
+        7.81794442939557092300e-05,
+        7.14072491382608190305e-05,
+        -1.85586374855275456654e-05,
+        2.59073051863633712884e-05,
+    };
+    static const double pio4 = 7.85398163397448278999e-01;
+    static const double pio4lo = 3.06161699786838301793e-17;
+
+    double z, r, v, w, s, a, w0, a0;
+    UINT32 hx;
+    int big, sign;
+
+    hx = *(ULONGLONG*)&x >> 32;
+    big = (hx & 0x7fffffff) >= 0x3FE59428; /* |x| >= 0.6744 */
+    if (big) {
+        sign = hx >> 31;
+        if (sign) {
+            x = -x;
+            y = -y;
+        }
+        x = (pio4 - x) + (pio4lo - y);
+        y = 0.0;
+    }
+    z = x * x;
+    w = z * z;
+    r = T[1] + w * (T[3] + w * (T[5] + w * (T[7] + w * (T[9] + w * T[11]))));
+    v = z * (T[2] + w * (T[4] + w * (T[6] + w * (T[8] + w * (T[10] + w * T[12])))));
+    s = z * x;
+    r = y + z * (s * (r + v) + y) + s * T[0];
+    w = x + r;
+    if (big) {
+        s = 1 - 2 * odd;
+        v = s - 2.0 * (x + (r - w * w / (w + s)));
+        return sign ? -v : v;
+    }
+    if (!odd)
+        return w;
+    /* -1.0/(x+r) has up to 2ulp error, so compute it accurately */
+    w0 = w;
+    *(LONGLONG*)&w0 = *(LONGLONG*)&w0 & 0xffffffff00000000ULL;
+    v = r - (w0 - x);       /* w0+v = r+x */
+    a0 = a = -1.0 / w;
+    *(LONGLONG*)&a0 = *(LONGLONG*)&a0 & 0xffffffff00000000ULL;
+    return a0 + a * (1.0 + a0 * w0 + a0 * v);
+}
+
 
 /*********************************************************************
  *                  abs   (NTDLL.@)
@@ -778,10 +837,33 @@ double CDECL sqrt( double d )
 
 /*********************************************************************
  *                  tan   (NTDLL.@)
+ *
+ * Copied from musl: src/math/tan.c
  */
-double CDECL tan( double d )
+double CDECL tan( double x )
 {
-    return unix_funcs->tan( d );
+    double y[2];
+    UINT32 ix;
+    unsigned n;
+
+    ix = *(ULONGLONG*)&x >> 32;
+    ix &= 0x7fffffff;
+
+    if (ix <= 0x3fe921fb) { /* |x| ~< pi/4 */
+        if (ix < 0x3e400000) { /* |x| < 2**-27 */
+            /* raise inexact if x!=0 and underflow if subnormal */
+            fp_barrier(ix < 0x00100000 ? x / 0x1p120f : x + 0x1p120f);
+            return x;
+        }
+        return __tan(x, 0.0, 0);
+    }
+
+    if (isinf(x)) return x - x;
+    if (ix >= 0x7ff00000)
+        return x - x;
+
+    n = __rem_pio2(x, y);
+    return __tan(y[0], y[1], n & 1);
 }
 
 #if (defined(__GNUC__) || defined(__clang__)) && defined(__i386__)




More information about the wine-cvs mailing list