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