xref: /haiku/src/system/libroot/posix/musl/math/asinhl.c (revision f504f61099b010fbfa94b1cc63d2e9072c7f7185)
1*f504f610SAugustin Cavalier #include "libm.h"
2*f504f610SAugustin Cavalier 
3*f504f610SAugustin Cavalier #if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024
asinhl(long double x)4*f504f610SAugustin Cavalier long double asinhl(long double x)
5*f504f610SAugustin Cavalier {
6*f504f610SAugustin Cavalier 	return asinh(x);
7*f504f610SAugustin Cavalier }
8*f504f610SAugustin Cavalier #elif LDBL_MANT_DIG == 64 && LDBL_MAX_EXP == 16384
9*f504f610SAugustin Cavalier /* asinh(x) = sign(x)*log(|x|+sqrt(x*x+1)) ~= x - x^3/6 + o(x^5) */
asinhl(long double x)10*f504f610SAugustin Cavalier long double asinhl(long double x)
11*f504f610SAugustin Cavalier {
12*f504f610SAugustin Cavalier 	union ldshape u = {x};
13*f504f610SAugustin Cavalier 	unsigned e = u.i.se & 0x7fff;
14*f504f610SAugustin Cavalier 	unsigned s = u.i.se >> 15;
15*f504f610SAugustin Cavalier 
16*f504f610SAugustin Cavalier 	/* |x| */
17*f504f610SAugustin Cavalier 	u.i.se = e;
18*f504f610SAugustin Cavalier 	x = u.f;
19*f504f610SAugustin Cavalier 
20*f504f610SAugustin Cavalier 	if (e >= 0x3fff + 32) {
21*f504f610SAugustin Cavalier 		/* |x| >= 0x1p32 or inf or nan */
22*f504f610SAugustin Cavalier 		x = logl(x) + 0.693147180559945309417232121458176568L;
23*f504f610SAugustin Cavalier 	} else if (e >= 0x3fff + 1) {
24*f504f610SAugustin Cavalier 		/* |x| >= 2 */
25*f504f610SAugustin Cavalier 		x = logl(2*x + 1/(sqrtl(x*x+1)+x));
26*f504f610SAugustin Cavalier 	} else if (e >= 0x3fff - 32) {
27*f504f610SAugustin Cavalier 		/* |x| >= 0x1p-32 */
28*f504f610SAugustin Cavalier 		x = log1pl(x + x*x/(sqrtl(x*x+1)+1));
29*f504f610SAugustin Cavalier 	} else {
30*f504f610SAugustin Cavalier 		/* |x| < 0x1p-32, raise inexact if x!=0 */
31*f504f610SAugustin Cavalier 		FORCE_EVAL(x + 0x1p120f);
32*f504f610SAugustin Cavalier 	}
33*f504f610SAugustin Cavalier 	return s ? -x : x;
34*f504f610SAugustin Cavalier }
35*f504f610SAugustin Cavalier #elif LDBL_MANT_DIG == 113 && LDBL_MAX_EXP == 16384
36*f504f610SAugustin Cavalier // TODO: broken implementation to make things compile
asinhl(long double x)37*f504f610SAugustin Cavalier long double asinhl(long double x)
38*f504f610SAugustin Cavalier {
39*f504f610SAugustin Cavalier 	return asinh(x);
40*f504f610SAugustin Cavalier }
41*f504f610SAugustin Cavalier #endif
42