Piotr Caban : msvcrt: Import cos implementation from musl.
Alexandre Julliard
julliard at winehq.org
Fri May 21 14:19:44 CDT 2021
Module: wine
Branch: master
Commit: ef91a7c02c8431a09edb1c1954cacda8b5f8958c
URL: https://source.winehq.org/git/wine.git/?a=commit;h=ef91a7c02c8431a09edb1c1954cacda8b5f8958c
Author: Piotr Caban <piotr at codeweavers.com>
Date: Thu May 20 23:04:58 2021 +0200
msvcrt: Import cos 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 | 35 ++++++++++++++++++++++++++++++++---
1 file changed, 32 insertions(+), 3 deletions(-)
diff --git a/dlls/msvcrt/math.c b/dlls/msvcrt/math.c
index d89a4c7f5bc..7643f39fde7 100644
--- a/dlls/msvcrt/math.c
+++ b/dlls/msvcrt/math.c
@@ -1802,12 +1802,41 @@ static double __cos(double x, double y)
/*********************************************************************
* cos (MSVCRT.@)
+ *
+ * Copied from musl: src/math/cos.c
*/
double CDECL cos( double x )
{
- double ret = unix_funcs->cos( x );
- if (!isfinite(x)) return math_error(_DOMAIN, "cos", x, 0, ret);
- return ret;
+ double y[2];
+ UINT32 ix;
+ unsigned n;
+
+ ix = *(ULONGLONG*)&x >> 32;
+ ix &= 0x7fffffff;
+
+ /* |x| ~< pi/4 */
+ if (ix <= 0x3fe921fb) {
+ if (ix < 0x3e46a09e) { /* |x| < 2**-27 * sqrt(2) */
+ /* raise inexact if x!=0 */
+ fp_barrier(x + 0x1p120f);
+ return 1.0;
+ }
+ return __cos(x, 0);
+ }
+
+ /* cos(Inf or NaN) is NaN */
+ if (isinf(x)) return math_error(_DOMAIN, "cos", x, 0, x - x);
+ if (ix >= 0x7ff00000)
+ return x - x;
+
+ /* argument reduction */
+ n = __rem_pio2(x, y);
+ switch (n & 3) {
+ case 0: return __cos(y[0], y[1]);
+ case 1: return -__sin(y[0], y[1], 1);
+ case 2: return -__cos(y[0], y[1]);
+ default: return __sin(y[0], y[1], 1);
+ }
}
/*********************************************************************
More information about the wine-cvs
mailing list