1*2f2c0062Sguenther /* $OpenBSD: invtrig.h,v 1.2 2016/09/12 19:47:03 guenther Exp $ */
2390c8400Smartynas /*-
3390c8400Smartynas * Copyright (c) 2008 David Schultz <das@FreeBSD.ORG>
4390c8400Smartynas * All rights reserved.
5390c8400Smartynas *
6390c8400Smartynas * Redistribution and use in source and binary forms, with or without
7390c8400Smartynas * modification, are permitted provided that the following conditions
8390c8400Smartynas * are met:
9390c8400Smartynas * 1. Redistributions of source code must retain the above copyright
10390c8400Smartynas * notice, this list of conditions and the following disclaimer.
11390c8400Smartynas * 2. Redistributions in binary form must reproduce the above copyright
12390c8400Smartynas * notice, this list of conditions and the following disclaimer in the
13390c8400Smartynas * documentation and/or other materials provided with the distribution.
14390c8400Smartynas *
15390c8400Smartynas * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16390c8400Smartynas * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17390c8400Smartynas * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18390c8400Smartynas * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19390c8400Smartynas * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20390c8400Smartynas * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21390c8400Smartynas * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22390c8400Smartynas * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23390c8400Smartynas * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24390c8400Smartynas * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25390c8400Smartynas * SUCH DAMAGE.
26390c8400Smartynas *
27390c8400Smartynas * $FreeBSD: src/lib/msun/ld80/invtrig.h,v 1.2 2008/08/02 03:56:22 das Exp $
28390c8400Smartynas */
29390c8400Smartynas
30390c8400Smartynas #include <sys/types.h>
31390c8400Smartynas #include <machine/ieee.h>
32390c8400Smartynas #include <float.h>
33390c8400Smartynas
34390c8400Smartynas #define BIAS (LDBL_MAX_EXP - 1)
35390c8400Smartynas #define MANH_SIZE EXT_FRACHBITS
36390c8400Smartynas
37390c8400Smartynas /* Approximation thresholds. */
38390c8400Smartynas #define ASIN_LINEAR (BIAS - 32) /* 2**-32 */
39390c8400Smartynas #define ACOS_CONST (BIAS - 65) /* 2**-65 */
40390c8400Smartynas #define ATAN_CONST (BIAS + 65) /* 2**65 */
41390c8400Smartynas #define ATAN_LINEAR (BIAS - 32) /* 2**-32 */
42390c8400Smartynas
43390c8400Smartynas /* 0.95 */
44390c8400Smartynas #ifdef EXT_IMPLICIT_NBIT
45390c8400Smartynas #define THRESH (0xe666666666666666ULL>>(64-(MANH_SIZE-1)))
46390c8400Smartynas #else /* EXT_IMPLICIT_NBIT */
47390c8400Smartynas #define THRESH ((0xe666666666666666ULL>>(64-(MANH_SIZE-1)))|0x80000000)
48390c8400Smartynas #endif /* EXT_IMPLICIT_NBIT */
49390c8400Smartynas
50390c8400Smartynas /* Constants shared by the long double inverse trig functions. */
51390c8400Smartynas #define pS0 _ItL_pS0
52390c8400Smartynas #define pS1 _ItL_pS1
53390c8400Smartynas #define pS2 _ItL_pS2
54390c8400Smartynas #define pS3 _ItL_pS3
55390c8400Smartynas #define pS4 _ItL_pS4
56390c8400Smartynas #define pS5 _ItL_pS5
57390c8400Smartynas #define pS6 _ItL_pS6
58390c8400Smartynas #define qS1 _ItL_qS1
59390c8400Smartynas #define qS2 _ItL_qS2
60390c8400Smartynas #define qS3 _ItL_qS3
61390c8400Smartynas #define qS4 _ItL_qS4
62390c8400Smartynas #define qS5 _ItL_qS5
63390c8400Smartynas #define atanhi _ItL_atanhi
64390c8400Smartynas #define atanlo _ItL_atanlo
65390c8400Smartynas #define aT _ItL_aT
66390c8400Smartynas #define pi_lo _ItL_pi_lo
67390c8400Smartynas
68390c8400Smartynas #define pio2_hi atanhi[3]
69390c8400Smartynas #define pio2_lo atanlo[3]
70390c8400Smartynas #define pio4_hi atanhi[1]
71390c8400Smartynas
72390c8400Smartynas #ifdef STRUCT_DECLS
73390c8400Smartynas typedef struct longdouble {
74390c8400Smartynas uint64_t mant;
75390c8400Smartynas uint16_t expsign;
76390c8400Smartynas } LONGDOUBLE;
77390c8400Smartynas #else
78390c8400Smartynas typedef long double LONGDOUBLE;
79390c8400Smartynas #endif
80390c8400Smartynas
81*2f2c0062Sguenther __BEGIN_HIDDEN_DECLS
82390c8400Smartynas extern const LONGDOUBLE pS0, pS1, pS2, pS3, pS4, pS5, pS6;
83390c8400Smartynas extern const LONGDOUBLE qS1, qS2, qS3, qS4, qS5;
84390c8400Smartynas extern const LONGDOUBLE atanhi[], atanlo[], aT[];
85390c8400Smartynas extern const LONGDOUBLE pi_lo;
86*2f2c0062Sguenther __END_HIDDEN_DECLS
87390c8400Smartynas
88390c8400Smartynas #ifndef STRUCT_DECLS
89390c8400Smartynas
90390c8400Smartynas static inline long double
P(long double x)91390c8400Smartynas P(long double x)
92390c8400Smartynas {
93390c8400Smartynas
94390c8400Smartynas return (x * (pS0 + x * (pS1 + x * (pS2 + x * (pS3 + x * \
95390c8400Smartynas (pS4 + x * (pS5 + x * pS6)))))));
96390c8400Smartynas }
97390c8400Smartynas
98390c8400Smartynas static inline long double
Q(long double x)99390c8400Smartynas Q(long double x)
100390c8400Smartynas {
101390c8400Smartynas
102390c8400Smartynas return (1.0 + x * (qS1 + x * (qS2 + x * (qS3 + x * (qS4 + x * qS5)))));
103390c8400Smartynas }
104390c8400Smartynas
105390c8400Smartynas static inline long double
T_even(long double x)106390c8400Smartynas T_even(long double x)
107390c8400Smartynas {
108390c8400Smartynas
109390c8400Smartynas return (aT[0] + x * (aT[2] + x * (aT[4] + x * (aT[6] + x * \
110390c8400Smartynas (aT[8] + x * (aT[10] + x * aT[12]))))));
111390c8400Smartynas }
112390c8400Smartynas
113390c8400Smartynas static inline long double
T_odd(long double x)114390c8400Smartynas T_odd(long double x)
115390c8400Smartynas {
116390c8400Smartynas
117390c8400Smartynas return (aT[1] + x * (aT[3] + x * (aT[5] + x * (aT[7] + x * \
118390c8400Smartynas (aT[9] + x * aT[11])))));
119390c8400Smartynas }
120390c8400Smartynas
121390c8400Smartynas #endif
122