e_asinl.c revision 1.4
1
2/* FreeBSD: head/lib/msun/src/e_asin.c 176451 2008-02-22 02:30:36Z das */
3/*
4 * ====================================================
5 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
6 *
7 * Developed at SunSoft, a Sun Microsystems, Inc. business.
8 * Permission to use, copy, modify, and distribute this
9 * software is freely granted, provided that this notice
10 * is preserved.
11 * ====================================================
12 */
13
14#include <sys/cdefs.h>
15__RCSID("$NetBSD: e_asinl.c,v 1.4 2024/06/09 13:33:36 riastradh Exp $");
16
17/*
18 * See comments in e_asin.c.
19 * Converted to long double by David Schultz <das@FreeBSD.ORG>.
20 */
21
22#include "namespace.h"
23
24#include <float.h>
25#include <machine/ieee.h>
26
27#include "math.h"
28#include "math_private.h"
29
30#ifdef __HAVE_LONG_DOUBLE
31
32__weak_alias(asinl, _asinl)
33
34#if LDBL_MANT_DIG == 64
35#include "../ld80/invtrig.h"
36#elif LDBL_MANT_DIG == 113
37#include "../ld128/invtrig.h"
38#else
39#error "Unsupported long double format"
40#endif
41
42#ifdef LDBL_IMPLICIT_NBIT
43#define	LDBL_NBIT	0
44#endif
45
46static const long double
47one =  1.00000000000000000000e+00,
48huge = 1.000e+300;
49
50long double
51asinl(long double x)
52{
53	union ieee_ext_u u;
54	long double t=0.0,w,p,q,c,r,s;
55	int16_t expsign, expt;
56	u.extu_ld = x;
57	expsign = GET_EXPSIGN(&u);
58	expt = expsign & 0x7fff;
59	if(expt >= BIAS) {		/* |x|>= 1 */
60		if(expt==BIAS && ((u.extu_frach&~LDBL_NBIT)|u.extu_fracl)==0)
61		    /* asin(1)=+-pi/2 with inexact */
62		    return x*pio2_hi+x*pio2_lo;
63	    return (x-x)/(x-x);		/* asin(|x|>1) is NaN */
64	} else if (expt<BIAS-1) {	/* |x|<0.5 */
65	    if(expt<ASIN_LINEAR) {	/* if |x| is small, asinl(x)=x */
66		if(huge+x>one) return x;/* return x with inexact if x!=0*/
67	    }
68	    t = x*x;
69	    p = P(t);
70	    q = Q(t);
71	    w = p/q;
72	    return x+x*w;
73	}
74	/* 1> |x|>= 0.5 */
75	w = one-fabsl(x);
76	t = w*0.5;
77	p = P(t);
78	q = Q(t);
79	s = sqrtl(t);
80	if(u.extu_frach>=THRESH) { 	/* if |x| is close to 1 */
81	    w = p/q;
82	    t = pio2_hi-(2.0*(s+s*w)-pio2_lo);
83	} else {
84	    u.extu_ld = s;
85	    u.extu_fracl = 0;
86	    w = u.extu_ld;
87	    c  = (t-w*w)/(s+w);
88	    r  = p/q;
89	    p  = 2.0*s*r-(pio2_lo-2.0*c);
90	    q  = pio4_hi-2.0*w;
91	    t  = pio4_hi-(p-q);
92	}
93	if(expsign>0) return t; else return -t;
94}
95#endif
96