xref: /haiku/src/system/libroot/posix/musl/math/sincosl.c (revision f504f61099b010fbfa94b1cc63d2e9072c7f7185)
1*f504f610SAugustin Cavalier #define _GNU_SOURCE
2*f504f610SAugustin Cavalier #include "libm.h"
3*f504f610SAugustin Cavalier 
4*f504f610SAugustin Cavalier #if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024
sincosl(long double x,long double * sin,long double * cos)5*f504f610SAugustin Cavalier void sincosl(long double x, long double *sin, long double *cos)
6*f504f610SAugustin Cavalier {
7*f504f610SAugustin Cavalier 	double sind, cosd;
8*f504f610SAugustin Cavalier 	sincos(x, &sind, &cosd);
9*f504f610SAugustin Cavalier 	*sin = sind;
10*f504f610SAugustin Cavalier 	*cos = cosd;
11*f504f610SAugustin Cavalier }
12*f504f610SAugustin Cavalier #elif (LDBL_MANT_DIG == 64 || LDBL_MANT_DIG == 113) && LDBL_MAX_EXP == 16384
sincosl(long double x,long double * sin,long double * cos)13*f504f610SAugustin Cavalier void sincosl(long double x, long double *sin, long double *cos)
14*f504f610SAugustin Cavalier {
15*f504f610SAugustin Cavalier 	union ldshape u = {x};
16*f504f610SAugustin Cavalier 	unsigned n;
17*f504f610SAugustin Cavalier 	long double y[2], s, c;
18*f504f610SAugustin Cavalier 
19*f504f610SAugustin Cavalier 	u.i.se &= 0x7fff;
20*f504f610SAugustin Cavalier 	if (u.i.se == 0x7fff) {
21*f504f610SAugustin Cavalier 		*sin = *cos = x - x;
22*f504f610SAugustin Cavalier 		return;
23*f504f610SAugustin Cavalier 	}
24*f504f610SAugustin Cavalier 	if (u.f < M_PI_4) {
25*f504f610SAugustin Cavalier 		if (u.i.se < 0x3fff - LDBL_MANT_DIG) {
26*f504f610SAugustin Cavalier 			/* raise underflow if subnormal */
27*f504f610SAugustin Cavalier 			if (u.i.se == 0) FORCE_EVAL(x*0x1p-120f);
28*f504f610SAugustin Cavalier 			*sin = x;
29*f504f610SAugustin Cavalier 			/* raise inexact if x!=0 */
30*f504f610SAugustin Cavalier 			*cos = 1.0 + x;
31*f504f610SAugustin Cavalier 			return;
32*f504f610SAugustin Cavalier 		}
33*f504f610SAugustin Cavalier 		*sin = __sinl(x, 0, 0);
34*f504f610SAugustin Cavalier 		*cos = __cosl(x, 0);
35*f504f610SAugustin Cavalier 		return;
36*f504f610SAugustin Cavalier 	}
37*f504f610SAugustin Cavalier 	n = __rem_pio2l(x, y);
38*f504f610SAugustin Cavalier 	s = __sinl(y[0], y[1], 1);
39*f504f610SAugustin Cavalier 	c = __cosl(y[0], y[1]);
40*f504f610SAugustin Cavalier 	switch (n & 3) {
41*f504f610SAugustin Cavalier 	case 0:
42*f504f610SAugustin Cavalier 		*sin = s;
43*f504f610SAugustin Cavalier 		*cos = c;
44*f504f610SAugustin Cavalier 		break;
45*f504f610SAugustin Cavalier 	case 1:
46*f504f610SAugustin Cavalier 		*sin = c;
47*f504f610SAugustin Cavalier 		*cos = -s;
48*f504f610SAugustin Cavalier 		break;
49*f504f610SAugustin Cavalier 	case 2:
50*f504f610SAugustin Cavalier 		*sin = -s;
51*f504f610SAugustin Cavalier 		*cos = -c;
52*f504f610SAugustin Cavalier 		break;
53*f504f610SAugustin Cavalier 	case 3:
54*f504f610SAugustin Cavalier 	default:
55*f504f610SAugustin Cavalier 		*sin = -c;
56*f504f610SAugustin Cavalier 		*cos = s;
57*f504f610SAugustin Cavalier 		break;
58*f504f610SAugustin Cavalier 	}
59*f504f610SAugustin Cavalier }
60*f504f610SAugustin Cavalier #endif
61