1 #pragma once
2 
3 #ifdef __cplusplus
4 extern "C" {
5 #endif
6 
7 #include <features.h>
8 
9 #define __NEED_float_t
10 #define __NEED_double_t
11 #include <bits/alltypes.h>
12 
13 #if 100 * __GNUC__ + __GNUC_MINOR__ >= 303
14 #define NAN __builtin_nanf("")
15 #define INFINITY __builtin_inff()
16 #else
17 #define NAN (0.0f / 0.0f)
18 #define INFINITY 1e5000f
19 #endif
20 
21 #define HUGE_VALF INFINITY
22 #define HUGE_VAL ((double)INFINITY)
23 #define HUGE_VALL ((long double)INFINITY)
24 
25 #define MATH_ERRNO 1
26 #define MATH_ERREXCEPT 2
27 #define math_errhandling 2
28 
29 #define FP_ILOGBNAN (-1 - (int)(((unsigned)-1) >> 1))
30 #define FP_ILOGB0 FP_ILOGBNAN
31 
32 #define FP_NAN 0
33 #define FP_INFINITE 1
34 #define FP_ZERO 2
35 #define FP_SUBNORMAL 3
36 #define FP_NORMAL 4
37 
38 int __fpclassify(double);
39 int __fpclassifyf(float);
40 int __fpclassifyl(long double);
41 
__FLOAT_BITS(float __f)42 static __inline unsigned __FLOAT_BITS(float __f) {
43     union {
44         float __f;
45         unsigned __i;
46     } __u;
47     __u.__f = __f;
48     return __u.__i;
49 }
__DOUBLE_BITS(double __f)50 static __inline unsigned long long __DOUBLE_BITS(double __f) {
51     union {
52         double __f;
53         unsigned long long __i;
54     } __u;
55     __u.__f = __f;
56     return __u.__i;
57 }
58 
59 #define fpclassify(x)                                                            \
60     (sizeof(x) == sizeof(float) ? __fpclassifyf(x) : sizeof(x) == sizeof(double) \
61                                                          ? __fpclassify(x)       \
62                                                          : __fpclassifyl(x))
63 
64 #define isinf(x)                                                                           \
65     (sizeof(x) == sizeof(float)                                                            \
66          ? (__FLOAT_BITS(x) & 0x7fffffff) == 0x7f800000                                    \
67          : sizeof(x) == sizeof(double) ? (__DOUBLE_BITS(x) & -1ULL >> 1) == 0x7ffULL << 52 \
68                                        : __fpclassifyl(x) == FP_INFINITE)
69 
70 #define isnan(x)                                                                          \
71     (sizeof(x) == sizeof(float)                                                           \
72          ? (__FLOAT_BITS(x) & 0x7fffffff) > 0x7f800000                                    \
73          : sizeof(x) == sizeof(double) ? (__DOUBLE_BITS(x) & -1ULL >> 1) > 0x7ffULL << 52 \
74                                        : __fpclassifyl(x) == FP_NAN)
75 
76 #define isnormal(x)                                                             \
77     (sizeof(x) == sizeof(float)                                                 \
78          ? ((__FLOAT_BITS(x) + 0x00800000) & 0x7fffffff) >= 0x01000000          \
79          : sizeof(x) == sizeof(double)                                          \
80                ? ((__DOUBLE_BITS(x) + (1ULL << 52)) & -1ULL >> 1) >= 1ULL << 53 \
81                : __fpclassifyl(x) == FP_NORMAL)
82 
83 #define isfinite(x)                                                                       \
84     (sizeof(x) == sizeof(float)                                                           \
85          ? (__FLOAT_BITS(x) & 0x7fffffff) < 0x7f800000                                    \
86          : sizeof(x) == sizeof(double) ? (__DOUBLE_BITS(x) & -1ULL >> 1) < 0x7ffULL << 52 \
87                                        : __fpclassifyl(x) > FP_INFINITE)
88 
89 int __signbit(double);
90 int __signbitf(float);
91 int __signbitl(long double);
92 
93 #define signbit(x)                      \
94     (sizeof(x) == sizeof(float)         \
95          ? (int)(__FLOAT_BITS(x) >> 31) \
96          : sizeof(x) == sizeof(double) ? (int)(__DOUBLE_BITS(x) >> 63) : __signbitl(x))
97 
98 #define isunordered(x, y) __builtin_isunordered(x, y)
99 
100 #define __ISREL_DEF(rel, op, type)                      \
101     static __inline int __is##rel(type __x, type __y) { \
102         return !isunordered(__x, __y) && __x op __y;    \
103     }
104 
105 __ISREL_DEF(lessf, <, float_t)
106 __ISREL_DEF(less, <, double_t)
107 __ISREL_DEF(lessl, <, long double)
108 __ISREL_DEF(lessequalf, <=, float_t)
109 __ISREL_DEF(lessequal, <=, double_t)
110 __ISREL_DEF(lessequall, <=, long double)
111 __ISREL_DEF(lessgreaterf, !=, float_t)
112 __ISREL_DEF(lessgreater, !=, double_t)
113 __ISREL_DEF(lessgreaterl, !=, long double)
114 __ISREL_DEF(greaterf, >, float_t)
115 __ISREL_DEF(greater, >, double_t)
116 __ISREL_DEF(greaterl, >, long double)
117 __ISREL_DEF(greaterequalf, >=, float_t)
118 __ISREL_DEF(greaterequal, >=, double_t)
119 __ISREL_DEF(greaterequall, >=, long double)
120 
121 #define isless(x, y) __builtin_isless(x, y)
122 #define islessequal(x, y) __builtin_islessequal(x, y)
123 #define islessgreater(x, y) __builtin_islessgreater(x, y)
124 #define isgreater(x, y) __builtin_isgreater(x, y)
125 #define isgreaterequal(x, y) __builtin_isgreaterequal(x, y)
126 
127 double acos(double);
128 float acosf(float);
129 long double acosl(long double);
130 
131 double acosh(double);
132 float acoshf(float);
133 long double acoshl(long double);
134 
135 double asin(double);
136 float asinf(float);
137 long double asinl(long double);
138 
139 double asinh(double);
140 float asinhf(float);
141 long double asinhl(long double);
142 
143 double atan(double);
144 float atanf(float);
145 long double atanl(long double);
146 
147 double atan2(double, double);
148 float atan2f(float, float);
149 long double atan2l(long double, long double);
150 
151 double atanh(double);
152 float atanhf(float);
153 long double atanhl(long double);
154 
155 double cbrt(double);
156 float cbrtf(float);
157 long double cbrtl(long double);
158 
159 double ceil(double);
160 float ceilf(float);
161 long double ceill(long double);
162 
163 double copysign(double, double);
164 float copysignf(float, float);
165 long double copysignl(long double, long double);
166 
167 double cos(double);
168 float cosf(float);
169 long double cosl(long double);
170 
171 double cosh(double);
172 float coshf(float);
173 long double coshl(long double);
174 
175 double erf(double);
176 float erff(float);
177 long double erfl(long double);
178 
179 double erfc(double);
180 float erfcf(float);
181 long double erfcl(long double);
182 
183 double exp(double);
184 float expf(float);
185 long double expl(long double);
186 
187 double exp2(double);
188 float exp2f(float);
189 long double exp2l(long double);
190 
191 double expm1(double);
192 float expm1f(float);
193 long double expm1l(long double);
194 
195 double fabs(double);
196 float fabsf(float);
197 long double fabsl(long double);
198 
199 double fdim(double, double);
200 float fdimf(float, float);
201 long double fdiml(long double, long double);
202 
203 double floor(double);
204 float floorf(float);
205 long double floorl(long double);
206 
207 double fma(double, double, double);
208 float fmaf(float, float, float);
209 long double fmal(long double, long double, long double);
210 
211 double fmax(double, double);
212 float fmaxf(float, float);
213 long double fmaxl(long double, long double);
214 
215 double fmin(double, double);
216 float fminf(float, float);
217 long double fminl(long double, long double);
218 
219 double fmod(double, double);
220 float fmodf(float, float);
221 long double fmodl(long double, long double);
222 
223 double frexp(double, int*);
224 float frexpf(float, int*);
225 long double frexpl(long double, int*);
226 
227 double hypot(double, double);
228 float hypotf(float, float);
229 long double hypotl(long double, long double);
230 
231 int ilogb(double);
232 int ilogbf(float);
233 int ilogbl(long double);
234 
235 double ldexp(double, int);
236 float ldexpf(float, int);
237 long double ldexpl(long double, int);
238 
239 double lgamma(double);
240 float lgammaf(float);
241 long double lgammal(long double);
242 
243 long long llrint(double);
244 long long llrintf(float);
245 long long llrintl(long double);
246 
247 long long llround(double);
248 long long llroundf(float);
249 long long llroundl(long double);
250 
251 double log(double);
252 float logf(float);
253 long double logl(long double);
254 
255 double log10(double);
256 float log10f(float);
257 long double log10l(long double);
258 
259 double log1p(double);
260 float log1pf(float);
261 long double log1pl(long double);
262 
263 double log2(double);
264 float log2f(float);
265 long double log2l(long double);
266 
267 double logb(double);
268 float logbf(float);
269 long double logbl(long double);
270 
271 long lrint(double);
272 long lrintf(float);
273 long lrintl(long double);
274 
275 long lround(double);
276 long lroundf(float);
277 long lroundl(long double);
278 
279 double modf(double, double*);
280 float modff(float, float*);
281 long double modfl(long double, long double*);
282 
283 double nan(const char*);
284 float nanf(const char*);
285 long double nanl(const char*);
286 
287 double nearbyint(double);
288 float nearbyintf(float);
289 long double nearbyintl(long double);
290 
291 double nextafter(double, double);
292 float nextafterf(float, float);
293 long double nextafterl(long double, long double);
294 
295 double nexttoward(double, long double);
296 float nexttowardf(float, long double);
297 long double nexttowardl(long double, long double);
298 
299 double pow(double, double);
300 float powf(float, float);
301 long double powl(long double, long double);
302 
303 double remainder(double, double);
304 float remainderf(float, float);
305 long double remainderl(long double, long double);
306 
307 double remquo(double, double, int*);
308 float remquof(float, float, int*);
309 long double remquol(long double, long double, int*);
310 
311 double rint(double);
312 float rintf(float);
313 long double rintl(long double);
314 
315 double round(double);
316 float roundf(float);
317 long double roundl(long double);
318 
319 double scalbln(double, long);
320 float scalblnf(float, long);
321 long double scalblnl(long double, long);
322 
323 double scalbn(double, int);
324 float scalbnf(float, int);
325 long double scalbnl(long double, int);
326 
327 double sin(double);
328 float sinf(float);
329 long double sinl(long double);
330 
331 double sinh(double);
332 float sinhf(float);
333 long double sinhl(long double);
334 
335 double sqrt(double);
336 float sqrtf(float);
337 long double sqrtl(long double);
338 
339 double tan(double);
340 float tanf(float);
341 long double tanl(long double);
342 
343 double tanh(double);
344 float tanhf(float);
345 long double tanhl(long double);
346 
347 double tgamma(double);
348 float tgammaf(float);
349 long double tgammal(long double);
350 
351 double trunc(double);
352 float truncf(float);
353 long double truncl(long double);
354 
355 #if defined(_XOPEN_SOURCE) || defined(_BSD_SOURCE)
356 #undef MAXFLOAT
357 #define MAXFLOAT 3.40282346638528859812e+38F
358 #endif
359 
360 #if defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
361 #define M_E 2.7182818284590452354         /* e */
362 #define M_LOG2E 1.4426950408889634074     /* log_2 e */
363 #define M_LOG10E 0.43429448190325182765   /* log_10 e */
364 #define M_LN2 0.69314718055994530942      /* log_e 2 */
365 #define M_LN10 2.30258509299404568402     /* log_e 10 */
366 #define M_PI 3.14159265358979323846       /* pi */
367 #define M_PI_2 1.57079632679489661923     /* pi/2 */
368 #define M_PI_4 0.78539816339744830962     /* pi/4 */
369 #define M_1_PI 0.31830988618379067154     /* 1/pi */
370 #define M_2_PI 0.63661977236758134308     /* 2/pi */
371 #define M_2_SQRTPI 1.12837916709551257390 /* 2/sqrt(pi) */
372 #define M_SQRT2 1.41421356237309504880    /* sqrt(2) */
373 #define M_SQRT1_2 0.70710678118654752440  /* 1/sqrt(2) */
374 
375 extern int signgam;
376 
377 double j0(double);
378 double j1(double);
379 double jn(int, double);
380 
381 double y0(double);
382 double y1(double);
383 double yn(int, double);
384 #endif
385 
386 #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
387 #define HUGE 3.40282346638528859812e+38F
388 
389 double drem(double, double);
390 float dremf(float, float);
391 
392 int finite(double);
393 int finitef(float);
394 
395 double scalb(double, double);
396 float scalbf(float, float);
397 
398 double significand(double);
399 float significandf(float);
400 
401 double lgamma_r(double, int*);
402 float lgammaf_r(float, int*);
403 
404 float j0f(float);
405 float j1f(float);
406 float jnf(int, float);
407 
408 float y0f(float);
409 float y1f(float);
410 float ynf(int, float);
411 #endif
412 
413 #ifdef _GNU_SOURCE
414 long double lgammal_r(long double, int*);
415 
416 void sincos(double, double*, double*);
417 void sincosf(float, float*, float*);
418 void sincosl(long double, long double*, long double*);
419 
420 double exp10(double);
421 float exp10f(float);
422 long double exp10l(long double);
423 
424 double pow10(double);
425 float pow10f(float);
426 long double pow10l(long double);
427 #endif
428 
429 #ifdef __cplusplus
430 }
431 #endif
432