xref: /aosp_15_r20/bionic/libm/upstream-freebsd/lib/msun/ld128/invtrig.h (revision 8d67ca893c1523eb926b9080dbe4e2ffd2a27ba1)
1*8d67ca89SAndroid Build Coastguard Worker /*-
2*8d67ca89SAndroid Build Coastguard Worker  * SPDX-License-Identifier: BSD-2-Clause
3*8d67ca89SAndroid Build Coastguard Worker  *
4*8d67ca89SAndroid Build Coastguard Worker  * Copyright (c) 2008 David Schultz <[email protected]>
5*8d67ca89SAndroid Build Coastguard Worker  * All rights reserved.
6*8d67ca89SAndroid Build Coastguard Worker  *
7*8d67ca89SAndroid Build Coastguard Worker  * Redistribution and use in source and binary forms, with or without
8*8d67ca89SAndroid Build Coastguard Worker  * modification, are permitted provided that the following conditions
9*8d67ca89SAndroid Build Coastguard Worker  * are met:
10*8d67ca89SAndroid Build Coastguard Worker  * 1. Redistributions of source code must retain the above copyright
11*8d67ca89SAndroid Build Coastguard Worker  *    notice, this list of conditions and the following disclaimer.
12*8d67ca89SAndroid Build Coastguard Worker  * 2. Redistributions in binary form must reproduce the above copyright
13*8d67ca89SAndroid Build Coastguard Worker  *    notice, this list of conditions and the following disclaimer in the
14*8d67ca89SAndroid Build Coastguard Worker  *    documentation and/or other materials provided with the distribution.
15*8d67ca89SAndroid Build Coastguard Worker  *
16*8d67ca89SAndroid Build Coastguard Worker  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17*8d67ca89SAndroid Build Coastguard Worker  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18*8d67ca89SAndroid Build Coastguard Worker  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19*8d67ca89SAndroid Build Coastguard Worker  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20*8d67ca89SAndroid Build Coastguard Worker  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21*8d67ca89SAndroid Build Coastguard Worker  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22*8d67ca89SAndroid Build Coastguard Worker  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23*8d67ca89SAndroid Build Coastguard Worker  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24*8d67ca89SAndroid Build Coastguard Worker  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25*8d67ca89SAndroid Build Coastguard Worker  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26*8d67ca89SAndroid Build Coastguard Worker  * SUCH DAMAGE.
27*8d67ca89SAndroid Build Coastguard Worker  */
28*8d67ca89SAndroid Build Coastguard Worker 
29*8d67ca89SAndroid Build Coastguard Worker #include <float.h>
30*8d67ca89SAndroid Build Coastguard Worker 
31*8d67ca89SAndroid Build Coastguard Worker #include "fpmath.h"
32*8d67ca89SAndroid Build Coastguard Worker 
33*8d67ca89SAndroid Build Coastguard Worker #define	BIAS		(LDBL_MAX_EXP - 1)
34*8d67ca89SAndroid Build Coastguard Worker #define	MANH_SIZE	(LDBL_MANH_SIZE + 1)
35*8d67ca89SAndroid Build Coastguard Worker 
36*8d67ca89SAndroid Build Coastguard Worker /* Approximation thresholds. */
37*8d67ca89SAndroid Build Coastguard Worker #define	ASIN_LINEAR	(BIAS - 56)	/* 2**-56 */
38*8d67ca89SAndroid Build Coastguard Worker #define	ACOS_CONST	(BIAS - 113)	/* 2**-113 */
39*8d67ca89SAndroid Build Coastguard Worker #define	ATAN_CONST	(BIAS + 113)	/* 2**113 */
40*8d67ca89SAndroid Build Coastguard Worker #define	ATAN_LINEAR	(BIAS - 56)	/* 2**-56 */
41*8d67ca89SAndroid Build Coastguard Worker 
42*8d67ca89SAndroid Build Coastguard Worker /* 0.95 */
43*8d67ca89SAndroid Build Coastguard Worker #define	THRESH	((0xe666666666666666ULL>>(64-(MANH_SIZE-1)))|LDBL_NBIT)
44*8d67ca89SAndroid Build Coastguard Worker 
45*8d67ca89SAndroid Build Coastguard Worker /* Constants shared by the long double inverse trig functions. */
46*8d67ca89SAndroid Build Coastguard Worker #define	pS0	_ItL_pS0
47*8d67ca89SAndroid Build Coastguard Worker #define	pS1	_ItL_pS1
48*8d67ca89SAndroid Build Coastguard Worker #define	pS2	_ItL_pS2
49*8d67ca89SAndroid Build Coastguard Worker #define	pS3	_ItL_pS3
50*8d67ca89SAndroid Build Coastguard Worker #define	pS4	_ItL_pS4
51*8d67ca89SAndroid Build Coastguard Worker #define	pS5	_ItL_pS5
52*8d67ca89SAndroid Build Coastguard Worker #define	pS6	_ItL_pS6
53*8d67ca89SAndroid Build Coastguard Worker #define	pS7	_ItL_pS7
54*8d67ca89SAndroid Build Coastguard Worker #define	pS8	_ItL_pS8
55*8d67ca89SAndroid Build Coastguard Worker #define	pS9	_ItL_pS9
56*8d67ca89SAndroid Build Coastguard Worker #define	qS1	_ItL_qS1
57*8d67ca89SAndroid Build Coastguard Worker #define	qS2	_ItL_qS2
58*8d67ca89SAndroid Build Coastguard Worker #define	qS3	_ItL_qS3
59*8d67ca89SAndroid Build Coastguard Worker #define	qS4	_ItL_qS4
60*8d67ca89SAndroid Build Coastguard Worker #define	qS5	_ItL_qS5
61*8d67ca89SAndroid Build Coastguard Worker #define	qS6	_ItL_qS6
62*8d67ca89SAndroid Build Coastguard Worker #define	qS7	_ItL_qS7
63*8d67ca89SAndroid Build Coastguard Worker #define	qS8	_ItL_qS8
64*8d67ca89SAndroid Build Coastguard Worker #define	qS9	_ItL_qS9
65*8d67ca89SAndroid Build Coastguard Worker #define	atanhi	_ItL_atanhi
66*8d67ca89SAndroid Build Coastguard Worker #define	atanlo	_ItL_atanlo
67*8d67ca89SAndroid Build Coastguard Worker #define	aT	_ItL_aT
68*8d67ca89SAndroid Build Coastguard Worker #define	pi_lo	_ItL_pi_lo
69*8d67ca89SAndroid Build Coastguard Worker 
70*8d67ca89SAndroid Build Coastguard Worker #define	pio2_hi	atanhi[3]
71*8d67ca89SAndroid Build Coastguard Worker #define	pio2_lo	atanlo[3]
72*8d67ca89SAndroid Build Coastguard Worker #define	pio4_hi	atanhi[1]
73*8d67ca89SAndroid Build Coastguard Worker 
74*8d67ca89SAndroid Build Coastguard Worker /* Constants shared by the long double inverse trig functions. */
75*8d67ca89SAndroid Build Coastguard Worker extern const long double pS0, pS1, pS2, pS3, pS4, pS5, pS6, pS7, pS8, pS9;
76*8d67ca89SAndroid Build Coastguard Worker extern const long double qS1, qS2, qS3, qS4, qS5, qS6, qS7, qS8, qS9;
77*8d67ca89SAndroid Build Coastguard Worker extern const long double atanhi[], atanlo[], aT[];
78*8d67ca89SAndroid Build Coastguard Worker extern const long double pi_lo;
79*8d67ca89SAndroid Build Coastguard Worker 
80*8d67ca89SAndroid Build Coastguard Worker static inline long double
P(long double x)81*8d67ca89SAndroid Build Coastguard Worker P(long double x)
82*8d67ca89SAndroid Build Coastguard Worker {
83*8d67ca89SAndroid Build Coastguard Worker 
84*8d67ca89SAndroid Build Coastguard Worker 	return (x * (pS0 + x * (pS1 + x * (pS2 + x * (pS3 + x * \
85*8d67ca89SAndroid Build Coastguard Worker 		(pS4 + x * (pS5 + x * (pS6 + x * (pS7 + x * (pS8 + x * \
86*8d67ca89SAndroid Build Coastguard Worker 		pS9))))))))));
87*8d67ca89SAndroid Build Coastguard Worker }
88*8d67ca89SAndroid Build Coastguard Worker 
89*8d67ca89SAndroid Build Coastguard Worker static inline long double
Q(long double x)90*8d67ca89SAndroid Build Coastguard Worker Q(long double x)
91*8d67ca89SAndroid Build Coastguard Worker {
92*8d67ca89SAndroid Build Coastguard Worker 
93*8d67ca89SAndroid Build Coastguard Worker 	return (1.0 + x * (qS1 + x * (qS2 + x * (qS3 + x * (qS4 + x * \
94*8d67ca89SAndroid Build Coastguard Worker 		(qS5 + x * (qS6 + x * (qS7 + x * (qS8 + x * qS9)))))))));
95*8d67ca89SAndroid Build Coastguard Worker }
96*8d67ca89SAndroid Build Coastguard Worker 
97*8d67ca89SAndroid Build Coastguard Worker static inline long double
T_even(long double x)98*8d67ca89SAndroid Build Coastguard Worker T_even(long double x)
99*8d67ca89SAndroid Build Coastguard Worker {
100*8d67ca89SAndroid Build Coastguard Worker 
101*8d67ca89SAndroid Build Coastguard Worker 	return (aT[0] + x * (aT[2] + x * (aT[4] + x * (aT[6] + x * \
102*8d67ca89SAndroid Build Coastguard Worker 		(aT[8] + x * (aT[10] + x * (aT[12] + x * (aT[14] + x * \
103*8d67ca89SAndroid Build Coastguard Worker 		(aT[16] + x * (aT[18] + x * (aT[20] + x * aT[22])))))))))));
104*8d67ca89SAndroid Build Coastguard Worker }
105*8d67ca89SAndroid Build Coastguard Worker 
106*8d67ca89SAndroid Build Coastguard Worker static inline long double
T_odd(long double x)107*8d67ca89SAndroid Build Coastguard Worker T_odd(long double x)
108*8d67ca89SAndroid Build Coastguard Worker {
109*8d67ca89SAndroid Build Coastguard Worker 
110*8d67ca89SAndroid Build Coastguard Worker 	return (aT[1] + x * (aT[3] + x * (aT[5] + x * (aT[7] + x * \
111*8d67ca89SAndroid Build Coastguard Worker 		(aT[9] + x * (aT[11] + x * (aT[13] + x * (aT[15] + x * \
112*8d67ca89SAndroid Build Coastguard Worker 		(aT[17] + x * (aT[19] + x * (aT[21] + x * aT[23])))))))))));
113*8d67ca89SAndroid Build Coastguard Worker }
114