1 /* origin: FreeBSD /usr/src/lib/msun/src/e_acosl.c */
3 * ====================================================
4 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
6 * Developed at SunSoft, a Sun Microsystems, Inc. business.
7 * Permission to use, copy, modify, and distribute this
8 * software is freely granted, provided that this notice
10 * ====================================================
13 * See comments in acos.c.
14 * Converted to long double by David Schultz <das@FreeBSD.ORG>.
19 #if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024
20 long double acosl(long double x)
24 #elif (LDBL_MANT_DIG == 64 || LDBL_MANT_DIG == 113) && LDBL_MAX_EXP == 16384
25 #include "__invtrigl.h"
27 static const long double
28 one = 1.00000000000000000000e+00,
29 pi = 3.14159265358979323846264338327950280e+00L;
31 long double acosl(long double x)
34 long double z, p, q, r, w, s, c, df;
35 int16_t expsign, expt;
37 expsign = u.xbits.expsign;
38 expt = expsign & 0x7fff;
39 if (expt >= BIAS) { /* |x| >= 1 */
41 ((u.bits.manh & ~LDBL_NBIT) | u.bits.manl) == 0) {
43 return 0.0; /* acos(1) = 0 */
45 return pi + 2.0 * pio2_lo; /* acos(-1)= pi */
47 return (x - x) / (x - x); /* acos(|x|>1) is NaN */
49 if (expt < BIAS - 1) { /* |x| < 0.5 */
50 if (expt < ACOS_CONST)
51 return pio2_hi + pio2_lo; /* x tiny: acosl=pi/2 */
56 return pio2_hi - (x - (pio2_lo - x * r));
57 } else if (expsign < 0) { /* x < -0.5 */
64 return pi - 2.0 * (s + w);
65 } else { /* x > 0.5 */
71 c = (z - df * df) / (s + df);
76 return 2.0 * (df + w);