xref: /haiku/src/system/libroot/posix/musl/math/sinl.c (revision f504f61099b010fbfa94b1cc63d2e9072c7f7185)
1*f504f610SAugustin Cavalier #include "libm.h"
2*f504f610SAugustin Cavalier 
3*f504f610SAugustin Cavalier #if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024
sinl(long double x)4*f504f610SAugustin Cavalier long double sinl(long double x)
5*f504f610SAugustin Cavalier {
6*f504f610SAugustin Cavalier 	return sin(x);
7*f504f610SAugustin Cavalier }
8*f504f610SAugustin Cavalier #elif (LDBL_MANT_DIG == 64 || LDBL_MANT_DIG == 113) && LDBL_MAX_EXP == 16384
sinl(long double x)9*f504f610SAugustin Cavalier long double sinl(long double x)
10*f504f610SAugustin Cavalier {
11*f504f610SAugustin Cavalier 	union ldshape u = {x};
12*f504f610SAugustin Cavalier 	unsigned n;
13*f504f610SAugustin Cavalier 	long double y[2], hi, lo;
14*f504f610SAugustin Cavalier 
15*f504f610SAugustin Cavalier 	u.i.se &= 0x7fff;
16*f504f610SAugustin Cavalier 	if (u.i.se == 0x7fff)
17*f504f610SAugustin Cavalier 		return x - x;
18*f504f610SAugustin Cavalier 	if (u.f < M_PI_4) {
19*f504f610SAugustin Cavalier 		if (u.i.se < 0x3fff - LDBL_MANT_DIG/2) {
20*f504f610SAugustin Cavalier 			/* raise inexact if x!=0 and underflow if subnormal */
21*f504f610SAugustin Cavalier 			FORCE_EVAL(u.i.se == 0 ? x*0x1p-120f : x+0x1p120f);
22*f504f610SAugustin Cavalier 			return x;
23*f504f610SAugustin Cavalier 		}
24*f504f610SAugustin Cavalier 		return __sinl(x, 0.0, 0);
25*f504f610SAugustin Cavalier 	}
26*f504f610SAugustin Cavalier 	n = __rem_pio2l(x, y);
27*f504f610SAugustin Cavalier 	hi = y[0];
28*f504f610SAugustin Cavalier 	lo = y[1];
29*f504f610SAugustin Cavalier 	switch (n & 3) {
30*f504f610SAugustin Cavalier 	case 0:
31*f504f610SAugustin Cavalier 		return __sinl(hi, lo, 1);
32*f504f610SAugustin Cavalier 	case 1:
33*f504f610SAugustin Cavalier 		return __cosl(hi, lo);
34*f504f610SAugustin Cavalier 	case 2:
35*f504f610SAugustin Cavalier 		return -__sinl(hi, lo, 1);
36*f504f610SAugustin Cavalier 	case 3:
37*f504f610SAugustin Cavalier 	default:
38*f504f610SAugustin Cavalier 		return -__cosl(hi, lo);
39*f504f610SAugustin Cavalier 	}
40*f504f610SAugustin Cavalier }
41*f504f610SAugustin Cavalier #endif
42