GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: lib/libm/src/ld80/invtrig.h Lines: 4 7 57.1 %
Date: 2017-11-13 Branches: 0 0 0.0 %

Line Branch Exec Source
1
/*	$OpenBSD: invtrig.h,v 1.2 2016/09/12 19:47:03 guenther Exp $	*/
2
/*-
3
 * Copyright (c) 2008 David Schultz <das@FreeBSD.ORG>
4
 * All rights reserved.
5
 *
6
 * Redistribution and use in source and binary forms, with or without
7
 * modification, are permitted provided that the following conditions
8
 * are met:
9
 * 1. Redistributions of source code must retain the above copyright
10
 *    notice, this list of conditions and the following disclaimer.
11
 * 2. Redistributions in binary form must reproduce the above copyright
12
 *    notice, this list of conditions and the following disclaimer in the
13
 *    documentation and/or other materials provided with the distribution.
14
 *
15
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25
 * SUCH DAMAGE.
26
 *
27
 * $FreeBSD: src/lib/msun/ld80/invtrig.h,v 1.2 2008/08/02 03:56:22 das Exp $
28
 */
29
30
#include <sys/types.h>
31
#include <machine/ieee.h>
32
#include <float.h>
33
34
#define	BIAS		(LDBL_MAX_EXP - 1)
35
#define	MANH_SIZE	EXT_FRACHBITS
36
37
/* Approximation thresholds. */
38
#define	ASIN_LINEAR	(BIAS - 32)	/* 2**-32 */
39
#define	ACOS_CONST	(BIAS - 65)	/* 2**-65 */
40
#define	ATAN_CONST	(BIAS + 65)	/* 2**65 */
41
#define	ATAN_LINEAR	(BIAS - 32)	/* 2**-32 */
42
43
/* 0.95 */
44
#ifdef EXT_IMPLICIT_NBIT
45
#define	THRESH	(0xe666666666666666ULL>>(64-(MANH_SIZE-1)))
46
#else /* EXT_IMPLICIT_NBIT */
47
#define	THRESH	((0xe666666666666666ULL>>(64-(MANH_SIZE-1)))|0x80000000)
48
#endif /* EXT_IMPLICIT_NBIT */
49
50
/* Constants shared by the long double inverse trig functions. */
51
#define	pS0	_ItL_pS0
52
#define	pS1	_ItL_pS1
53
#define	pS2	_ItL_pS2
54
#define	pS3	_ItL_pS3
55
#define	pS4	_ItL_pS4
56
#define	pS5	_ItL_pS5
57
#define	pS6	_ItL_pS6
58
#define	qS1	_ItL_qS1
59
#define	qS2	_ItL_qS2
60
#define	qS3	_ItL_qS3
61
#define	qS4	_ItL_qS4
62
#define	qS5	_ItL_qS5
63
#define	atanhi	_ItL_atanhi
64
#define	atanlo	_ItL_atanlo
65
#define	aT	_ItL_aT
66
#define	pi_lo	_ItL_pi_lo
67
68
#define	pio2_hi	atanhi[3]
69
#define	pio2_lo	atanlo[3]
70
#define	pio4_hi	atanhi[1]
71
72
#ifdef STRUCT_DECLS
73
typedef struct longdouble {
74
	uint64_t mant;
75
	uint16_t expsign;
76
} LONGDOUBLE;
77
#else
78
typedef long double LONGDOUBLE;
79
#endif
80
81
__BEGIN_HIDDEN_DECLS
82
extern const LONGDOUBLE pS0, pS1, pS2, pS3, pS4, pS5, pS6;
83
extern const LONGDOUBLE qS1, qS2, qS3, qS4, qS5;
84
extern const LONGDOUBLE atanhi[], atanlo[], aT[];
85
extern const LONGDOUBLE pi_lo;
86
__END_HIDDEN_DECLS
87
88
#ifndef STRUCT_DECLS
89
90
static inline long double
91
P(long double x)
92
{
93
94
	return (x * (pS0 + x * (pS1 + x * (pS2 + x * (pS3 + x * \
95
		(pS4 + x * (pS5 + x * pS6)))))));
96
}
97
98
static inline long double
99
Q(long double x)
100
{
101
102
	return (1.0 + x * (qS1 + x * (qS2 + x * (qS3 + x * (qS4 + x * qS5)))));
103
}
104
105
static inline long double
106
T_even(long double x)
107
{
108
109
588
	return (aT[0] + x * (aT[2] + x * (aT[4] + x * (aT[6] + x * \
110
196
		(aT[8] + x * (aT[10] + x * aT[12]))))));
111
}
112
113
static inline long double
114
T_odd(long double x)
115
{
116
117
588
	return (aT[1] + x * (aT[3] + x * (aT[5] + x * (aT[7] + x * \
118
196
		(aT[9] + x * aT[11])))));
119
}
120
121
#endif