1 | /*
|
---|
2 | * Copyright (c) 2018 CZ.NIC, z.s.p.o.
|
---|
3 | * All rights reserved.
|
---|
4 | *
|
---|
5 | * Redistribution and use in source and binary forms, with or without
|
---|
6 | * modification, are permitted provided that the following conditions
|
---|
7 | * are met:
|
---|
8 | *
|
---|
9 | * - Redistributions of source code must retain the above copyright
|
---|
10 | * notice, this list of conditions and the following disclaimer.
|
---|
11 | * - 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 | * - The name of the author may not be used to endorse or promote products
|
---|
15 | * derived from this software without specific prior written permission.
|
---|
16 | *
|
---|
17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
---|
18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
---|
19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
---|
20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
---|
21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
---|
22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
---|
23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
---|
24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
---|
25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
---|
26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
---|
27 | */
|
---|
28 |
|
---|
29 | #ifndef _MATH_H
|
---|
30 | #define _MATH_H
|
---|
31 |
|
---|
32 | #include <limits.h>
|
---|
33 | #include <stddef.h>
|
---|
34 | #include <float.h>
|
---|
35 |
|
---|
36 | #if defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) || defined(_BSD_SOURCE) || defined(_HELENOS_SOURCE)
|
---|
37 |
|
---|
38 | #define M_E 2.7182818284590452354
|
---|
39 | #define M_LOG2E 1.4426950408889634074
|
---|
40 | #define M_LOG10E 0.43429448190325182765
|
---|
41 | #define M_LN2 0.69314718055994530942
|
---|
42 | #define M_LN10 2.30258509299404568402
|
---|
43 | #define M_PI 3.14159265358979323846
|
---|
44 | #define M_PI_2 1.57079632679489661923
|
---|
45 | #define M_PI_4 0.78539816339744830962
|
---|
46 | #define M_1_PI 0.31830988618379067154
|
---|
47 | #define M_2_PI 0.63661977236758134308
|
---|
48 | #define M_2_SQRTPI 1.12837916709551257390
|
---|
49 | #define M_SQRT2 1.41421356237309504880
|
---|
50 | #define M_SQRT1_2 0.70710678118654752440
|
---|
51 |
|
---|
52 | /* GNU extensions, but GCC emits calls to them as an optimization. */
|
---|
53 | void sincos(double, double *, double *);
|
---|
54 | void sincosf(float, float *, float *);
|
---|
55 | void sincosl(long double, long double *, long double *);
|
---|
56 |
|
---|
57 | #endif
|
---|
58 |
|
---|
59 | #if FLT_EVAL_METHOD == 0
|
---|
60 | typedef float float_t;
|
---|
61 | typedef double double_t;
|
---|
62 | #elif FLT_EVAL_METHOD == 1
|
---|
63 | typedef double float_t;
|
---|
64 | typedef double double_t;
|
---|
65 | #elif FLT_EVAL_METHOD == 2
|
---|
66 | typedef long double float_t;
|
---|
67 | typedef long double double_t;
|
---|
68 | #else
|
---|
69 | #error Unknown FLT_EVAL_METHOD value.
|
---|
70 | #endif
|
---|
71 |
|
---|
72 | #define FP_ILOGB0 INT_MIN
|
---|
73 | #define FP_ILOGBNAN INT_MAX
|
---|
74 |
|
---|
75 | #define FP_NAN 0
|
---|
76 | #define FP_INFINITE 1
|
---|
77 | #define FP_NORMAL 2
|
---|
78 | #define FP_SUBNORMAL 3
|
---|
79 | #define FP_ZERO 4
|
---|
80 |
|
---|
81 | int __fpclassify(size_t, ...);
|
---|
82 | int __signbit(size_t, ...);
|
---|
83 | int __fcompare(size_t, size_t, ...);
|
---|
84 |
|
---|
85 | #define __FCOMPARE_EQUAL 1
|
---|
86 | #define __FCOMPARE_LESS 2
|
---|
87 | #define __FCOMPARE_GREATER 4
|
---|
88 |
|
---|
89 | #if defined(__GNUC__) || defined(__clang__)
|
---|
90 |
|
---|
91 | #define HUGE_VALF __builtin_huge_valf()
|
---|
92 | #define HUGE_VAL __builtin_huge_val()
|
---|
93 | #define HUGE_VALL __builtin_huge_vall()
|
---|
94 | #define INFINITY __builtin_inff()
|
---|
95 | #define NAN __builtin_nan("")
|
---|
96 |
|
---|
97 | #define fpclassify(x) __builtin_fpclassify(FP_NAN, FP_INFINITE, FP_NORMAL, FP_SUBNORMAL, FP_ZERO, (x))
|
---|
98 | #define isfinite(x) __builtin_isfinite(x)
|
---|
99 | #define isinf(x) __builtin_isinf(x)
|
---|
100 | #define isnan(x) __builtin_isnan(x)
|
---|
101 | #define isnormal(x) __builtin_isnormal(x)
|
---|
102 | #define signbit(x) __builtin_signbit(x)
|
---|
103 |
|
---|
104 | #define isgreater(x, y) __builtin_isgreater(x, y)
|
---|
105 | #define isgreaterequal(x, y) __builtin_isgreaterequal(x, y)
|
---|
106 | #define isless(x, y) __builtin_isless(x, y)
|
---|
107 | #define islessequal(x, y) __builtin_islessequal(x, y)
|
---|
108 | #define islessgreater(x, y) __builtin_islessgreater(x, y)
|
---|
109 | #define isunordered(x, y) __builtin_isunordered(x, y)
|
---|
110 |
|
---|
111 | #else /* defined(__GNUC__) || defined(__clang__) */
|
---|
112 |
|
---|
113 | #define HUGE_VALF (1.0f / 0.0f)
|
---|
114 | #define HUGE_VAL (1.0 / 0.0)
|
---|
115 | #define HUGE_VALL (1.0l / 0.0l)
|
---|
116 | #define INFINITY (1.0f / 0.0f)
|
---|
117 | #define NAN (0.0 / 0.0)
|
---|
118 |
|
---|
119 | #define fpclassify(x) __fpclassify(sizeof(x), (x))
|
---|
120 | #define isfinite(x) (fpclassify(x) > FP_INFINITE)
|
---|
121 | #define isinf(x) (fpclassify(x) == FP_INFINITE)
|
---|
122 | #define isnan(x) (fpclassify(x) == FP_NAN)
|
---|
123 | #define isnormal(x) (fpclassify(x) == FP_NORMAL)
|
---|
124 | #define signbit(x) __signbit(sizeof(x), (x))
|
---|
125 |
|
---|
126 | #define isgreater(x, y) (!!(__fcompare(sizeof(x), sizeof(y), (x), (y)) & __FCOMPARE_GREATER))
|
---|
127 | #define isgreaterequal(x, y) (!!(__fcompare(sizeof(x), sizeof(y), (x), (y)) & (__FCOMPARE_GREATER | __FCOMPARE_EQUAL))))
|
---|
128 | #define isless(x, y) (!!(__fcompare(sizeof(x), sizeof(y), (x), (y)) & __FCOMPARE_LESS))
|
---|
129 | #define islessequal(x, y) (!!(__fcompare(sizeof(x), sizeof(y), (x), (y)) & (__FCOMPARE_LESS | __FCOMPARE_EQUAL)))
|
---|
130 | #define islessgreater(x, y) (!!(__fcompare(sizeof(x), sizeof(y), (x), (y)) & (__FCOMPARE_LESS | __FCOMPARE_GREATER)))
|
---|
131 | #define isunordered(x, y) (!__fcompare(sizeof(x), sizeof(y), (x), (y)))
|
---|
132 |
|
---|
133 | #endif /* defined(__GNUC__) || defined(__clang__) */
|
---|
134 |
|
---|
135 | #define MATH_ERRNO 1
|
---|
136 | #define MATH_ERREXCEPT 2
|
---|
137 |
|
---|
138 | #define math_errhandling MATH_ERRNO
|
---|
139 |
|
---|
140 | double acos(double);
|
---|
141 | float acosf(float);
|
---|
142 | long double acosl(long double);
|
---|
143 | double asin(double);
|
---|
144 | float asinf(float);
|
---|
145 | long double asinl(long double);
|
---|
146 | double atan(double);
|
---|
147 | float atanf(float);
|
---|
148 | long double atanl(long double);
|
---|
149 | double atan2(double, double);
|
---|
150 | float atan2f(float, float);
|
---|
151 | long double atan2l(long double, long double);
|
---|
152 | double cos(double);
|
---|
153 | float cosf(float);
|
---|
154 | long double cosl(long double);
|
---|
155 | double sin(double);
|
---|
156 | float sinf(float);
|
---|
157 | long double sinl(long double);
|
---|
158 | double tan(double);
|
---|
159 | float tanf(float);
|
---|
160 | long double tanl(long double);
|
---|
161 | double acosh(double);
|
---|
162 | float acoshf(float);
|
---|
163 | long double acoshl(long double);
|
---|
164 | double asinh(double);
|
---|
165 | float asinhf(float);
|
---|
166 | long double asinhl(long double);
|
---|
167 | double atanh(double);
|
---|
168 | float atanhf(float);
|
---|
169 | long double atanhl(long double);
|
---|
170 | double cosh(double);
|
---|
171 | float coshf(float);
|
---|
172 | long double coshl(long double);
|
---|
173 | double sinh(double);
|
---|
174 | float sinhf(float);
|
---|
175 | long double sinhl(long double);
|
---|
176 | double tanh(double);
|
---|
177 | float tanhf(float);
|
---|
178 | long double tanhl(long double);
|
---|
179 | double exp(double);
|
---|
180 | float expf(float);
|
---|
181 | long double expl(long double);
|
---|
182 | double exp2(double);
|
---|
183 | float exp2f(float);
|
---|
184 | long double exp2l(long double);
|
---|
185 | double expm1(double);
|
---|
186 | float expm1f(float);
|
---|
187 | long double expm1l(long double);
|
---|
188 | double frexp(double, int *);
|
---|
189 | float frexpf(float, int *);
|
---|
190 | long double frexpl(long double, int *);
|
---|
191 | int ilogb(double);
|
---|
192 | int ilogbf(float);
|
---|
193 | int ilogbl(long double);
|
---|
194 | double ldexp(double, int);
|
---|
195 | float ldexpf(float, int);
|
---|
196 | long double ldexpl(long double, int);
|
---|
197 | double log(double);
|
---|
198 | float logf(float);
|
---|
199 | long double logl(long double);
|
---|
200 | double log10(double);
|
---|
201 | float log10f(float);
|
---|
202 | long double log10l(long double);
|
---|
203 | double log1p(double);
|
---|
204 | float log1pf(float);
|
---|
205 | long double log1pl(long double);
|
---|
206 | double log2(double);
|
---|
207 | float log2f(float);
|
---|
208 | long double log2l(long double);
|
---|
209 | double logb(double);
|
---|
210 | float logbf(float);
|
---|
211 | long double logbl(long double);
|
---|
212 | double modf(double value, double *);
|
---|
213 | float modff(float value, float *);
|
---|
214 | long double modfl(long double, long double *);
|
---|
215 | double scalbn(double, int);
|
---|
216 | float scalbnf(float, int);
|
---|
217 | long double scalbnl(long double, int);
|
---|
218 | double scalbln(double, long int);
|
---|
219 | float scalblnf(float, long int);
|
---|
220 | long double scalblnl(long double, long int);
|
---|
221 | double cbrt(double);
|
---|
222 | float cbrtf(float);
|
---|
223 | long double cbrtl(long double);
|
---|
224 | double fabs(double);
|
---|
225 | float fabsf(float);
|
---|
226 | long double fabsl(long double);
|
---|
227 | double hypot(double, double);
|
---|
228 | float hypotf(float, float);
|
---|
229 | long double hypotl(long double, long double);
|
---|
230 | double pow(double, double);
|
---|
231 | float powf(float, float);
|
---|
232 | long double powl(long double, long double);
|
---|
233 | double sqrt(double);
|
---|
234 | float sqrtf(float);
|
---|
235 | long double sqrtl(long double);
|
---|
236 | double erf(double);
|
---|
237 | float erff(float);
|
---|
238 | long double erfl(long double);
|
---|
239 | double erfc(double);
|
---|
240 | float erfcf(float);
|
---|
241 | long double erfcl(long double);
|
---|
242 | double lgamma(double);
|
---|
243 | float lgammaf(float);
|
---|
244 | long double lgammal(long double);
|
---|
245 | double tgamma(double);
|
---|
246 | float tgammaf(float);
|
---|
247 | long double tgammal(long double);
|
---|
248 | double ceil(double);
|
---|
249 | float ceilf(float);
|
---|
250 | long double ceill(long double);
|
---|
251 | double floor(double);
|
---|
252 | float floorf(float);
|
---|
253 | long double floorl(long double);
|
---|
254 | double nearbyint(double);
|
---|
255 | float nearbyintf(float);
|
---|
256 | long double nearbyintl(long double);
|
---|
257 | double rint(double);
|
---|
258 | float rintf(float);
|
---|
259 | long double rintl(long double);
|
---|
260 | long int lrint(double);
|
---|
261 | long int lrintf(float);
|
---|
262 | long int lrintl(long double);
|
---|
263 | long long int llrint(double);
|
---|
264 | long long int llrintf(float);
|
---|
265 | long long int llrintl(long double);
|
---|
266 | double round(double);
|
---|
267 | float roundf(float);
|
---|
268 | long double roundl(long double);
|
---|
269 | long int lround(double);
|
---|
270 | long int lroundf(float);
|
---|
271 | long int lroundl(long double);
|
---|
272 | long long int llround(double);
|
---|
273 | long long int llroundf(float);
|
---|
274 | long long int llroundl(long double);
|
---|
275 | double trunc(double);
|
---|
276 | float truncf(float);
|
---|
277 | long double truncl(long double);
|
---|
278 | double fmod(double, double);
|
---|
279 | float fmodf(float, float);
|
---|
280 | long double fmodl(long double, long double);
|
---|
281 | double remainder(double, double);
|
---|
282 | float remainderf(float, float);
|
---|
283 | long double remainderl(long double, long double);
|
---|
284 | double remquo(double, double, int *);
|
---|
285 | float remquof(float, float, int *);
|
---|
286 | long double remquol(long double, long double, int *);
|
---|
287 | double copysign(double, double);
|
---|
288 | float copysignf(float, float);
|
---|
289 | long double copysignl(long double, long double);
|
---|
290 | double nan(const char *);
|
---|
291 | float nanf(const char *);
|
---|
292 | long double nanl(const char *);
|
---|
293 | double nextafter(double, double);
|
---|
294 | float nextafterf(float, float);
|
---|
295 | long double nextafterl(long double, long double);
|
---|
296 | double nexttoward(double, long double);
|
---|
297 | float nexttowardf(float, long double);
|
---|
298 | long double nexttowardl(long double, long double);
|
---|
299 | double fdim(double, double);
|
---|
300 | float fdimf(float, float);
|
---|
301 | long double fdiml(long double, long double);
|
---|
302 | double fmax(double, double);
|
---|
303 | float fmaxf(float, float);
|
---|
304 | long double fmaxl(long double, long double);
|
---|
305 | double fmin(double, double);
|
---|
306 | float fminf(float, float);
|
---|
307 | long double fminl(long double, long double);
|
---|
308 | double fma(double, double, double);
|
---|
309 | float fmaf(float, float, float);
|
---|
310 | long double fmal(long double, long double, long double);
|
---|
311 |
|
---|
312 | #if defined(__GNUC__) || defined(__clang__)
|
---|
313 |
|
---|
314 | #define copysign __builtin_copysign
|
---|
315 | #define copysignf __builtin_copysignf
|
---|
316 | #define copysignl __builtin_copysignl
|
---|
317 |
|
---|
318 | #define nextafter __builtin_nextafter
|
---|
319 | #define nextafterf __builtin_nextafterf
|
---|
320 | #define nextafterl __builtin_nextafterl
|
---|
321 |
|
---|
322 | #endif
|
---|
323 |
|
---|
324 | #endif /* _MATH_H */
|
---|