Piotr Caban : msvcrt: Import tanf implementation from musl.
Alexandre Julliard
julliard at winehq.org
Mon May 24 15:59:53 CDT 2021
Module: wine
Branch: master
Commit: 5e34d175307a5732e37e9281fc257bdaf4b10d6a
URL: https://source.winehq.org/git/wine.git/?a=commit;h=5e34d175307a5732e37e9281fc257bdaf4b10d6a
Author: Piotr Caban <piotr at codeweavers.com>
Date: Sun May 23 16:38:05 2021 +0200
msvcrt: Import tanf implementation from musl.
Signed-off-by: Piotr Caban <piotr at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>
---
dlls/msvcrt/math.c | 72 ++++++++++++++++++++++++++++++++++++++++++++++++---
dlls/msvcrt/unixlib.c | 9 -------
dlls/msvcrt/unixlib.h | 1 -
3 files changed, 69 insertions(+), 13 deletions(-)
diff --git a/dlls/msvcrt/math.c b/dlls/msvcrt/math.c
index d26aa06e9e7..811fce1531d 100644
--- a/dlls/msvcrt/math.c
+++ b/dlls/msvcrt/math.c
@@ -1285,14 +1285,80 @@ float CDECL sqrtf( float x )
#endif
}
+/* Copied from musl: src/math/__tandf.c */
+static float __tandf(double x, int odd)
+{
+ static const double T[] = {
+ 0x15554d3418c99f.0p-54,
+ 0x1112fd38999f72.0p-55,
+ 0x1b54c91d865afe.0p-57,
+ 0x191df3908c33ce.0p-58,
+ 0x185dadfcecf44e.0p-61,
+ 0x1362b9bf971bcd.0p-59,
+ };
+
+ double z, r, w, s, t, u;
+
+ z = x * x;
+ r = T[4] + z * T[5];
+ t = T[2] + z * T[3];
+ w = z * z;
+ s = z * x;
+ u = T[0] + z * T[1];
+ r = (x + s * u) + (s * w) * (t + w * r);
+ return odd ? -1.0 / r : r;
+}
+
/*********************************************************************
* tanf (MSVCRT.@)
+ *
+ * Copied from musl: src/math/tanf.c
*/
float CDECL tanf( float x )
{
- float ret = unix_funcs->tanf(x);
- if (!isfinite(x)) return math_error(_DOMAIN, "tanf", x, 0, ret);
- return ret;
+ static const double t1pio2 = 1*M_PI_2,
+ t2pio2 = 2*M_PI_2,
+ t3pio2 = 3*M_PI_2,
+ t4pio2 = 4*M_PI_2;
+
+ double y;
+ UINT32 ix;
+ unsigned n, sign;
+
+ ix = *(UINT32*)&x;
+ sign = ix >> 31;
+ ix &= 0x7fffffff;
+
+ if (ix <= 0x3f490fda) { /* |x| ~<= pi/4 */
+ if (ix < 0x39800000) { /* |x| < 2**-12 */
+ /* raise inexact if x!=0 and underflow if subnormal */
+ fp_barrierf(ix < 0x00800000 ? x / 0x1p120f : x + 0x1p120f);
+ return x;
+ }
+ return __tandf(x, 0);
+ }
+ if (ix <= 0x407b53d1) { /* |x| ~<= 5*pi/4 */
+ if (ix <= 0x4016cbe3) /* |x| ~<= 3pi/4 */
+ return __tandf((sign ? x + t1pio2 : x - t1pio2), 1);
+ else
+ return __tandf((sign ? x + t2pio2 : x - t2pio2), 0);
+ }
+ if (ix <= 0x40e231d5) { /* |x| ~<= 9*pi/4 */
+ if (ix <= 0x40afeddf) /* |x| ~<= 7*pi/4 */
+ return __tandf((sign ? x + t3pio2 : x - t3pio2), 1);
+ else
+ return __tandf((sign ? x + t4pio2 : x - t4pio2), 0);
+ }
+
+ /* tan(Inf or NaN) is NaN */
+ if (isinf(x))
+ return math_error(_DOMAIN, "tanf", x, 0, x - x);
+ if (ix >= 0x7f800000)
+ return x - x;
+
+ /* argument reduction */
+ n = __rem_pio2f(x, &y);
+ return __tandf(y, n & 1);
}
/*********************************************************************
diff --git a/dlls/msvcrt/unixlib.c b/dlls/msvcrt/unixlib.c
index 1fb16f48fcd..c69ca440504 100644
--- a/dlls/msvcrt/unixlib.c
+++ b/dlls/msvcrt/unixlib.c
@@ -403,14 +403,6 @@ static float CDECL unix_sinhf( float x )
return sinhf( x );
}
-/*********************************************************************
- * tanf
- */
-static float CDECL unix_tanf( float x )
-{
- return tanf( x );
-}
-
/*********************************************************************
* tanh
*/
@@ -490,7 +482,6 @@ static const struct unix_funcs funcs =
unix_powf,
unix_sinh,
unix_sinhf,
- unix_tanf,
unix_tanh,
unix_tanhf,
unix_tgamma,
diff --git a/dlls/msvcrt/unixlib.h b/dlls/msvcrt/unixlib.h
index 4c2cf5852ea..6fbafe064c1 100644
--- a/dlls/msvcrt/unixlib.h
+++ b/dlls/msvcrt/unixlib.h
@@ -58,7 +58,6 @@ struct unix_funcs
float (CDECL *powf)(float x, float y);
double (CDECL *sinh)(double x);
float (CDECL *sinhf)(float x);
- float (CDECL *tanf)(float x);
double (CDECL *tanh)(double x);
float (CDECL *tanhf)(float x);
double (CDECL *tgamma)(double x);
More information about the wine-cvs
mailing list