blob: d7326483eeb0dc0f7d7eb2c01ad287abbe7c90a3 [file] [log] [blame]
Rich Felker0b44a032011-02-12 00:22:29 -05001#ifndef _MATH_H
2#define _MATH_H
3
Rich Felker3ed8c9f2011-11-10 20:40:06 -05004#ifdef __cplusplus
5extern "C" {
6#endif
7
Rich Felker414a4cd2012-02-15 21:47:55 -05008#define __NEED_float_t
9#define __NEED_double_t
Rich Felker0b44a032011-02-12 00:22:29 -050010#define __NEED___uint16_t
11#define __NEED___uint32_t
12#define __NEED___uint64_t
13#include <bits/alltypes.h>
14
Rich Felker405ce582012-03-02 22:35:37 -050015#if 100*__GNUC__+__GNUC_MINOR__ >= 303
16#define NAN __builtin_nanf("")
17#define INFINITY __builtin_inff()
18#else
19#define NAN (0.0f/0.0f)
20#define INFINITY 1e40f
21#endif
Rich Felker0b44a032011-02-12 00:22:29 -050022
23#define HUGE_VALF INFINITY
24#define HUGE_VAL ((double)INFINITY)
25#define HUGE_VALL ((long double)INFINITY)
26
Rich Felker0b44a032011-02-12 00:22:29 -050027#define MATH_ERRNO 1
Rich Felkered0e3a32012-04-18 11:41:04 -040028#define MATH_ERREXCEPT 2
Rich Felker0b44a032011-02-12 00:22:29 -050029#define math_errhandling 2
30
Rich Felker98c9af52012-05-05 22:22:46 -040031#define FP_ILOGBNAN (-1-(int)(((unsigned)-1)>>1))
32#define FP_ILOGB0 FP_ILOGBNAN
Rich Felker0b44a032011-02-12 00:22:29 -050033
34#define FP_NAN 0
35#define FP_INFINITE 1
36#define FP_ZERO 2
37#define FP_SUBNORMAL 3
38#define FP_NORMAL 4
39
Rich Felker0b44a032011-02-12 00:22:29 -050040int __fpclassify(double);
Rich Felkerb69f6952012-03-13 01:17:53 -040041int __fpclassifyf(float);
Rich Felker0b44a032011-02-12 00:22:29 -050042int __fpclassifyl(long double);
43
Rich Felker93a18a12012-03-30 23:33:00 -040044union __float_repr { float __f; __uint32_t __i; };
45union __double_repr { double __f; __uint64_t __i; };
46
47#define __FLOAT_BITS(f) (((union __float_repr){ (float)(f) }).__i)
48#define __DOUBLE_BITS(f) (((union __double_repr){ (double)(f) }).__i)
Rich Felkerb69f6952012-03-13 01:17:53 -040049
Rich Felker0b44a032011-02-12 00:22:29 -050050#define fpclassify(x) ( \
51 sizeof(x) == sizeof(float) ? __fpclassifyf(x) : \
52 sizeof(x) == sizeof(double) ? __fpclassify(x) : \
53 __fpclassifyl(x) )
54
Rich Felkerb69f6952012-03-13 01:17:53 -040055#define isinf(x) ( \
56 sizeof(x) == sizeof(float) ? (__FLOAT_BITS(x) & 0x7fffffff) == 0x7f800000 : \
57 sizeof(x) == sizeof(double) ? (__DOUBLE_BITS(x) & (__uint64_t)-1>>1) == (__uint64_t)0x7ff<<52 : \
58 __fpclassifyl(x) == FP_INFINITE)
Rich Felker0b44a032011-02-12 00:22:29 -050059
Rich Felkerb69f6952012-03-13 01:17:53 -040060#define isnan(x) ( \
61 sizeof(x) == sizeof(float) ? (__FLOAT_BITS(x) & 0x7fffffff) > 0x7f800000 : \
62 sizeof(x) == sizeof(double) ? (__DOUBLE_BITS(x) & (__uint64_t)-1>>1) > (__uint64_t)0x7ff<<52 : \
63 __fpclassifyl(x) == FP_NAN)
Rich Felkere0037ef2011-06-08 16:33:04 -040064
Rich Felkerb69f6952012-03-13 01:17:53 -040065#define isnormal(x) ( \
66 sizeof(x) == sizeof(float) ? ((__FLOAT_BITS(x)+0x00800000) & 0x7fffffff) >= 0x01000000 : \
67 sizeof(x) == sizeof(double) ? ((__DOUBLE_BITS(x)+((__uint64_t)1<<52)) & (__uint64_t)-1>>1) >= (__uint64_t)1<<53 : \
68 __fpclassifyl(x) == FP_NORMAL)
69
70#define isfinite(x) ( \
71 sizeof(x) == sizeof(float) ? (__FLOAT_BITS(x) & 0x7fffffff) < 0x7f800000 : \
72 sizeof(x) == sizeof(double) ? (__DOUBLE_BITS(x) & (__uint64_t)-1>>1) < (__uint64_t)0x7ff<<52 : \
73 __fpclassifyl(x) > FP_INFINITE)
74
75int __signbit(double);
76int __signbitf(float);
77int __signbitl(long double);
78
79#define signbit(x) ( \
Rich Felker4dbd9412012-03-30 23:41:43 -040080 sizeof(x) == sizeof(float) ? (int)(__FLOAT_BITS(x)>>31) : \
81 sizeof(x) == sizeof(double) ? (int)(__DOUBLE_BITS(x)>>63) : \
Rich Felkerb69f6952012-03-13 01:17:53 -040082 __signbitl(x) )
83
84#define isunordered(x,y) (isnan((x)) ? ((void)(y),1) : isnan((y)))
85
Rich Felker9fcecd72012-03-02 11:38:39 -050086#if __STDC_VERSION__ >= 199901L
Rich Felkerdb3e78c2012-03-02 00:36:26 -050087inline
88#endif
Rich Felkerb69f6952012-03-13 01:17:53 -040089static int __isrel(long double __x, long double __y, int __rel)
Rich Felkere0037ef2011-06-08 16:33:04 -040090{
91 if (isunordered(__x, __y)) return 0;
92 if (__rel==-2) return __x < __y;
93 if (__rel==2) return __x > __y;
94 if (__rel==-1) return __x <= __y;
95 if (__rel==1) return __x >= __y;
96 return __x != __y;
97}
98
99#define isless(x,y) __isrel((x), (y), -2)
100#define islessequal(x,y) __isrel((x), (y), -1)
101#define islessgreater(x,y) __isrel((x), (y), 0)
102#define isgreaterequal(x,y) __isrel((x), (y), 1)
103#define isgreater(x,y) __isrel((x), (y), 2)
104
Rich Felker0b44a032011-02-12 00:22:29 -0500105double acos(double);
106float acosf(float);
107long double acosl(long double);
108
109double acosh(double);
110float acoshf(float);
111long double acoshl(long double);
112
113double asin(double);
114float asinf(float);
115long double asinl(long double);
116
117double asinh(double);
118float asinhf(float);
119long double asinhl(long double);
120
121double atan(double);
122float atanf(float);
123long double atanl(long double);
124
125double atan2(double, double);
126float atan2f(float, float);
127long double atan2l(long double, long double);
128
129double atanh(double);
130float atanhf(float);
131long double atanhl(long double);
132
133double cbrt(double);
134float cbrtf(float);
135long double cbrtl(long double);
136
137double ceil(double);
138float ceilf(float);
139long double ceill(long double);
140
141double copysign(double, double);
142float copysignf(float, float);
143long double copysignl(long double, long double);
144
145double cos(double);
146float cosf(float);
147long double cosl(long double);
148
149double cosh(double);
150float coshf(float);
151long double coshl(long double);
152
153double erf(double);
154float erff(float);
155long double erfl(long double);
156
157double erfc(double);
158float erfcf(float);
159long double erfcl(long double);
160
161double exp(double);
162float expf(float);
163long double expl(long double);
164
165double exp2(double);
166float exp2f(float);
167long double exp2l(long double);
168
169double expm1(double);
170float expm1f(float);
171long double expm1l(long double);
172
173double fabs(double);
174float fabsf(float);
175long double fabsl(long double);
176
177double fdim(double, double);
178float fdimf(float, float);
179long double fdiml(long double, long double);
180
181double floor(double);
182float floorf(float);
183long double floorl(long double);
184
185double fma(double, double, double);
186float fmaf(float, float, float);
187long double fmal(long double, long double, long double);
188
189double fmax(double, double);
190float fmaxf(float, float);
191long double fmaxl(long double, long double);
192
193double fmin(double, double);
194float fminf(float, float);
195long double fminl(long double, long double);
196
197double fmod(double, double);
198float fmodf(float, float);
199long double fmodl(long double, long double);
200
201double frexp(double, int *);
202float frexpf(float value, int *);
203long double frexpl(long double value, int *);
204
205double hypot(double, double);
206float hypotf(float, float);
207long double hypotl(long double, long double);
208
209int ilogb(double);
210int ilogbf(float);
211int ilogbl(long double);
212
213double ldexp(double, int);
214float ldexpf(float, int);
215long double ldexpl(long double, int);
216
217double lgamma(double);
218float lgammaf(float);
219long double lgammal(long double);
220
221long long llrint(double);
222long long llrintf(float);
223long long llrintl(long double);
224
225long long llround(double);
226long long llroundf(float);
227long long llroundl(long double);
228
229double log(double);
230float logf(float);
231long double logl(long double);
232
233double log10(double);
234float log10f(float);
235long double log10l(long double);
236
237double log1p(double);
238float log1pf(float);
239long double log1pl(long double);
240
241double log2(double);
242float log2f(float);
243long double log2l(long double);
244
245double logb(double);
246float logbf(float);
247long double logbl(long double);
248
249long lrint(double);
250long lrintf(float);
251long lrintl(long double);
252
253long lround(double);
254long lroundf(float);
255long lroundl(long double);
256
257double modf(double, double *);
258float modff(float, float *);
259long double modfl(long double, long double *);
260
261double nan(const char *);
262float nanf(const char *);
263long double nanl(const char *);
264
265double nearbyint(double);
266float nearbyintf(float);
267long double nearbyintl(long double);
268
269double nextafter(double, double);
270float nextafterf(float, float);
271long double nextafterl(long double, long double);
272
273double nexttoward(double, long double);
274float nexttowardf(float, long double);
275long double nexttowardl(long double, long double);
276
277double pow(double, double);
278float powf(float, float);
279long double powl(long double, long double);
280
281double remainder(double, double);
282float remainderf(float, float);
283long double remainderl(long double, long double);
284
285double remquo(double, double, int *);
286float remquof(float, float, int *);
287long double remquol(long double, long double, int *);
288
289double rint(double);
290float rintf(float);
291long double rintl(long double);
292
293double round(double);
294float roundf(float);
295long double roundl(long double);
296
297double scalbln(double, long);
298float scalblnf(float, long);
299long double scalblnl(long double, long);
300
301double scalbn(double, int);
302float scalbnf(float, int);
303long double scalbnl(long double, int);
304
305double sin(double);
306float sinf(float);
307long double sinl(long double);
308
309double sinh(double);
310float sinhf(float);
311long double sinhl(long double);
312
313double sqrt(double);
314float sqrtf(float);
315long double sqrtl(long double);
316
317double tan(double);
318float tanf(float);
319long double tanl(long double);
320
321double tanh(double);
322float tanhf(float);
323long double tanhl(long double);
324
325double tgamma(double);
326float tgammaf(float);
327long double tgammal(long double);
328
329double trunc(double);
330float truncf(float);
331long double truncl(long double);
332
Rich Felker419ae6d2012-05-22 21:52:08 -0400333#if defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
Rich Felker74eea622011-02-14 18:41:25 -0500334#define M_E 2.7182818284590452354 /* e */
335#define M_LOG2E 1.4426950408889634074 /* log_2 e */
336#define M_LOG10E 0.43429448190325182765 /* log_10 e */
337#define M_LN2 0.69314718055994530942 /* log_e 2 */
338#define M_LN10 2.30258509299404568402 /* log_e 10 */
339#define M_PI 3.14159265358979323846 /* pi */
340#define M_PI_2 1.57079632679489661923 /* pi/2 */
341#define M_PI_4 0.78539816339744830962 /* pi/4 */
342#define M_1_PI 0.31830988618379067154 /* 1/pi */
343#define M_2_PI 0.63661977236758134308 /* 2/pi */
344#define M_2_SQRTPI 1.12837916709551257390 /* 2/sqrt(pi) */
345#define M_SQRT2 1.41421356237309504880 /* sqrt(2) */
346#define M_SQRT1_2 0.70710678118654752440 /* 1/sqrt(2) */
Rich Felker419ae6d2012-05-22 21:52:08 -0400347#endif
Rich Felkerb69f6952012-03-13 01:17:53 -0400348
Rich Felker419ae6d2012-05-22 21:52:08 -0400349#if defined(_XOPEN_SOURCE)
350#define MAXFLOAT 3.40282347e+38F
351#endif
352
353#if defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE)
Rich Felker0b44a032011-02-12 00:22:29 -0500354extern int signgam;
Rich Felkerb69f6952012-03-13 01:17:53 -0400355
Rich Felkerb69f6952012-03-13 01:17:53 -0400356double j0(double);
Rich Felkerb69f6952012-03-13 01:17:53 -0400357double j1(double);
Rich Felkerb69f6952012-03-13 01:17:53 -0400358double jn(int, double);
Rich Felkerb69f6952012-03-13 01:17:53 -0400359
360double y0(double);
Rich Felkerb69f6952012-03-13 01:17:53 -0400361double y1(double);
Rich Felkerb69f6952012-03-13 01:17:53 -0400362double yn(int, double);
Rich Felker74eea622011-02-14 18:41:25 -0500363#endif
364
365#ifdef _GNU_SOURCE
Rich Felker419ae6d2012-05-22 21:52:08 -0400366#define HUGE 3.40282347e+38F
Rich Felker74eea622011-02-14 18:41:25 -0500367double scalb(double, double);
Rich Felkerb69f6952012-03-13 01:17:53 -0400368float scalbf(float, float);
369long double scalbl(long double, long double);
nsz0144b452012-03-15 08:17:28 +0100370
371void sincos(double, double*, double*);
372void sincosf(float, float*, float*);
373void sincosl(long double, long double*, long double*);
nsz40305f72012-03-15 09:29:53 +0100374
Rich Felker8e092212012-03-17 21:48:48 -0400375double gamma(double);
376float gammaf(float);
377long double gammal(long double);
378
nsz40305f72012-03-15 09:29:53 +0100379double lgamma_r(double, int*);
380float lgammaf_r(float, int*);
381long double lgammal_r(long double, int*);
382
383float j0f(float);
384long double j0l(long double);
385float j1f(float);
386long double j1l(long double);
387float jnf(int, float);
388long double jnl(int, long double);
389
390float y0f(float);
391long double y0l(long double);
392float y1f(float);
393long double y1l(long double);
394float ynf(int, float);
395long double ynl(int, long double);
Rich Felkerf6819752012-04-30 03:26:53 -0400396
397double exp10(double);
398float exp10f(float);
399long double exp10l(long double);
Rich Felkera917c032012-05-01 00:07:37 -0400400double pow10(double);
401float pow10f(float);
402long double pow10l(long double);
Rich Felker74eea622011-02-14 18:41:25 -0500403#endif
Rich Felker0b44a032011-02-12 00:22:29 -0500404
Rich Felker3ed8c9f2011-11-10 20:40:06 -0500405#ifdef __cplusplus
406}
407#endif
408
Rich Felker0b44a032011-02-12 00:22:29 -0500409#endif