1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
// This is part of SLEEF, written by Naoki
// Shibata. http://shibatch.sourceforge.net
// The code in this file is distributed under the Creative Commons
// Attribution 4.0 International License.
#define N 8 // Degree of equation
#define S 40 // Number of samples for phase 1
#define L 4 // Number of high precision coefficients
#define MIN 0.0 // Min argument
#define MAX (M_PI/4) // Max argument
#define PMUL 2 // The form of polynomial is y = x^(PADD+PMUL*0) + x^(PADD+PMUL*1) + ...
#define PADD 1
void TARGET(mpfr_t ret, mpfr_t a) { mpfr_sin(ret, a, GMP_RNDN); } // The function to approximate
void CFUNC(mpfr_t dst, mpfr_t src) { mpfr_set(dst, src, GMP_RNDN); }
#define FIXCOEF0 1.0 // Fix coef 0 to 1.0
#define N 10
#define S 40
#define L 2
#define MIN 0.0
#define MAX (M_PI/4)
void TARGET(mpfr_t ret, mpfr_t a) { // cos(x) - 1
mpfr_t x;
mpfr_init(x);
mpfr_cos(ret, a, GMP_RNDN);
mpfr_set_ld(x, 1, GMP_RNDN);
mpfr_sub(ret, ret, x, GMP_RNDN);
mpfr_clear(x);
}
void CFUNC(mpfr_t dst, mpfr_t src) { mpfr_set(dst, src, GMP_RNDN); }
#define PMUL 2
#define PADD 2
#define FIXCOEF0 (-0.5)
// for xsincospi4_u05
#define N 9
#define S 40
#define L 2
#define MIN 0.0
#define MAX 1.0
#define PMUL 2
#define PADD 1
void TARGET(mpfr_t ret, mpfr_t a) {
mpfr_t x, y;
mpfr_inits(x, y, NULL);
mpfr_const_pi(x, GMP_RNDN);
mpfr_set_d(y, 1.0/4, GMP_RNDN);
mpfr_mul(x, x, y, GMP_RNDN);
mpfr_mul(x, x, a, GMP_RNDN);
mpfr_sin(ret, x, GMP_RNDN);
mpfr_clears(x, y, NULL);
}
void CFUNC(mpfr_t dst, mpfr_t src) { mpfr_set(dst, src, GMP_RNDN); }
// for xsincospi4_u05
#define N 9
#define S 40
#define L 2
#define MIN 0.0
#define MAX 1.0
void TARGET(mpfr_t ret, mpfr_t a) { // cos(x) - 1
mpfr_t x, y;
mpfr_inits(x, y, NULL);
mpfr_const_pi(x, GMP_RNDN);
mpfr_set_d(y, 1.0/4, GMP_RNDN);
mpfr_mul(x, x, y, GMP_RNDN);
mpfr_mul(x, x, a, GMP_RNDN);
mpfr_cos(ret, x, GMP_RNDN);
mpfr_set_ld(x, 1, GMP_RNDN);
mpfr_sub(ret, ret, x, GMP_RNDN);
mpfr_clears(x, y, NULL);
}
void CFUNC(mpfr_t dst, mpfr_t src) { mpfr_set(dst, src, GMP_RNDN); }
#define PMUL 2
#define PADD 2
// for xsincospi4
#define N 7
#define S 40
#define L 0
#define MIN 0.0
#define MAX 1.0
#define PMUL 2
#define PADD 1
void TARGET(mpfr_t ret, mpfr_t a) {
mpfr_t x, y;
mpfr_inits(x, y, NULL);
mpfr_const_pi(x, GMP_RNDN);
mpfr_set_d(y, 1.0/4, GMP_RNDN);
mpfr_mul(x, x, y, GMP_RNDN);
mpfr_mul(x, x, a, GMP_RNDN);
mpfr_sin(ret, x, GMP_RNDN);
mpfr_clears(x, y, NULL);
}
void CFUNC(mpfr_t dst, mpfr_t src) { mpfr_set(dst, src, GMP_RNDN); }
#define N 17
#define S 40
#define L 0
#define MIN 0.0
#define MAX (M_PI/4)
#define PMUL 2
#define PADD 1
void TARGET(mpfr_t ret, mpfr_t a) { mpfr_tan(ret, a, GMP_RNDN); }
void CFUNC(mpfr_t dst, mpfr_t src) { mpfr_set(dst, src, GMP_RNDN); }
#define FIXCOEF0 1.0
#define N 9
#define S 40
#define L 2
#define MIN 1 //0.75
#define MAX 1.5
#define PMUL 2
#define PADD 1
void TARGET(mpfr_t ret, mpfr_t a) { mpfr_log(ret, a, GMP_RNDN); }
void CFUNC(mpfr_t frd, mpfr_t fra) {
mpfr_t tmp, one;
mpfr_inits(tmp, one, NULL);
mpfr_set_d(one, 1, GMP_RNDN);
mpfr_add(tmp, fra, one, GMP_RNDN);
mpfr_sub(frd, fra, one, GMP_RNDN);
mpfr_div(frd, frd, tmp, GMP_RNDN);
mpfr_clear(tmp, one, NULL);
}
#define FIXCOEF0 2.0
#define N 12
#define S 50
#define L 0
#define MIN -0.347
#define MAX 0.347 // 0.5 log 2
#define PMUL 1
#define PADD 0
void TARGET(mpfr_t ret, mpfr_t a) { mpfr_exp(ret, a, GMP_RNDN); }
void CFUNC(mpfr_t dst, mpfr_t src) { mpfr_set(dst, src, GMP_RNDN); }
#define FIXCOEF0 1.0
#define FIXCOEF1 1.0
#define FIXCOEF2 0.5
#define N 22
#define S 100
#define L 2
#define MIN 0.0
#define MAX 1.0
#define PMUL 2
#define PADD 1
void TARGET(mpfr_t ret, mpfr_t a) { mpfr_atan(ret, a, GMP_RNDN); }
void CFUNC(mpfr_t dst, mpfr_t src) { mpfr_set(dst, src, GMP_RNDN); }
#define FIXCOEF0 1.0