]>
git.proxmox.com Git - wasi-libc.git/blob - libc-top-half/musl/include/math.h
10 #define __NEED_float_t
11 #define __NEED_double_t
12 #include <bits/alltypes.h>
14 #if 100*__GNUC__+__GNUC_MINOR__ >= 303
15 #define NAN __builtin_nanf("")
16 #define INFINITY __builtin_inff()
18 #define NAN (0.0f/0.0f)
19 #define INFINITY 1e5000f
22 #define HUGE_VALF INFINITY
23 #define HUGE_VAL ((double)INFINITY)
24 #define HUGE_VALL ((long double)INFINITY)
27 #define MATH_ERREXCEPT 2
28 #define math_errhandling 2
30 #define FP_ILOGBNAN (-1-0x7fffffff)
31 #define FP_ILOGB0 FP_ILOGBNAN
36 #define FP_SUBNORMAL 3
44 #define FP_FAST_FMAF 1
48 #define FP_FAST_FMAL 1
51 #ifdef __wasilibc_unmodified_upstream /* Use the compiler's definition of the fpclassify-like operations */
52 int __fpclassify(double);
53 int __fpclassifyf(float);
54 int __fpclassifyl(long double);
56 static __inline
unsigned __FLOAT_BITS(float __f
)
58 union {float __f
; unsigned __i
;} __u
;
62 static __inline
unsigned long long __DOUBLE_BITS(double __f
)
64 union {double __f
; unsigned long long __i
;} __u
;
69 #define fpclassify(x) ( \
70 sizeof(x) == sizeof(float) ? __fpclassifyf(x) : \
71 sizeof(x) == sizeof(double) ? __fpclassify(x) : \
75 sizeof(x) == sizeof(float) ? (__FLOAT_BITS(x) & 0x7fffffff) == 0x7f800000 : \
76 sizeof(x) == sizeof(double) ? (__DOUBLE_BITS(x) & -1ULL>>1) == 0x7ffULL<<52 : \
77 __fpclassifyl(x) == FP_INFINITE)
80 sizeof(x) == sizeof(float) ? (__FLOAT_BITS(x) & 0x7fffffff) > 0x7f800000 : \
81 sizeof(x) == sizeof(double) ? (__DOUBLE_BITS(x) & -1ULL>>1) > 0x7ffULL<<52 : \
82 __fpclassifyl(x) == FP_NAN)
84 #define isnormal(x) ( \
85 sizeof(x) == sizeof(float) ? ((__FLOAT_BITS(x)+0x00800000) & 0x7fffffff) >= 0x01000000 : \
86 sizeof(x) == sizeof(double) ? ((__DOUBLE_BITS(x)+(1ULL<<52)) & -1ULL>>1) >= 1ULL<<53 : \
87 __fpclassifyl(x) == FP_NORMAL)
89 #define isfinite(x) ( \
90 sizeof(x) == sizeof(float) ? (__FLOAT_BITS(x) & 0x7fffffff) < 0x7f800000 : \
91 sizeof(x) == sizeof(double) ? (__DOUBLE_BITS(x) & -1ULL>>1) < 0x7ffULL<<52 : \
92 __fpclassifyl(x) > FP_INFINITE)
94 int __signbit(double);
95 int __signbitf(float);
96 int __signbitl(long double);
98 #define signbit(x) ( \
99 sizeof(x) == sizeof(float) ? (int)(__FLOAT_BITS(x)>>31) : \
100 sizeof(x) == sizeof(double) ? (int)(__DOUBLE_BITS(x)>>63) : \
103 #define isunordered(x,y) (isnan((x)) ? ((void)(y),1) : isnan((y)))
105 #define __ISREL_DEF(rel, op, type) \
106 static __inline int __is##rel(type __x, type __y) \
107 { return !isunordered(__x,__y) && __x op __y; }
109 __ISREL_DEF(lessf
, <, float_t
)
110 __ISREL_DEF(less
, <, double_t
)
111 __ISREL_DEF(lessl
, <, long double)
112 __ISREL_DEF(lessequalf
, <=, float_t
)
113 __ISREL_DEF(lessequal
, <=, double_t
)
114 __ISREL_DEF(lessequall
, <=, long double)
115 __ISREL_DEF(lessgreaterf
, !=, float_t
)
116 __ISREL_DEF(lessgreater
, !=, double_t
)
117 __ISREL_DEF(lessgreaterl
, !=, long double)
118 __ISREL_DEF(greaterf
, >, float_t
)
119 __ISREL_DEF(greater
, >, double_t
)
120 __ISREL_DEF(greaterl
, >, long double)
121 __ISREL_DEF(greaterequalf
, >=, float_t
)
122 __ISREL_DEF(greaterequal
, >=, double_t
)
123 __ISREL_DEF(greaterequall
, >=, long double)
125 #define __tg_pred_2(x, y, p) ( \
126 sizeof((x)+(y)) == sizeof(float) ? p##f(x, y) : \
127 sizeof((x)+(y)) == sizeof(double) ? p(x, y) : \
130 #define isless(x, y) __tg_pred_2(x, y, __isless)
131 #define islessequal(x, y) __tg_pred_2(x, y, __islessequal)
132 #define islessgreater(x, y) __tg_pred_2(x, y, __islessgreater)
133 #define isgreater(x, y) __tg_pred_2(x, y, __isgreater)
134 #define isgreaterequal(x, y) __tg_pred_2(x, y, __isgreaterequal)
136 #define fpclassify(x) (__builtin_fpclassify(FP_NAN, FP_INFINITE, \
137 FP_NORMAL, FP_SUBNORMAL, \
139 #define isinf(x) (__builtin_isinf(x))
140 #define isnan(x) (__builtin_isnan(x))
141 #define isnormal(x) (__builtin_isnormal(x))
142 #define isfinite(x) (__builtin_isfinite(x))
143 #define signbit(x) (__builtin_signbit(x))
144 #define isunordered(x, y) (__builtin_isunordered(x, y))
145 #define isless(x, y) (__builtin_isless(x, y))
146 #define islessequal(x, y) (__builtin_islessequal(x, y))
147 #define islessgreater(x, y) (__builtin_islessgreater(x, y))
148 #define isgreater(x, y) (__builtin_isgreater(x, y))
149 #define isgreaterequal(x, y) (__builtin_isgreaterequal(x, y))
154 long double acosl(long double);
156 double acosh(double);
158 long double acoshl(long double);
162 long double asinl(long double);
164 double asinh(double);
166 long double asinhl(long double);
170 long double atanl(long double);
172 double atan2(double, double);
173 float atan2f(float, float);
174 long double atan2l(long double, long double);
176 double atanh(double);
178 long double atanhl(long double);
182 long double cbrtl(long double);
186 long double ceill(long double);
188 double copysign(double, double);
189 float copysignf(float, float);
190 long double copysignl(long double, long double);
194 long double cosl(long double);
198 long double coshl(long double);
202 long double erfl(long double);
206 long double erfcl(long double);
210 long double expl(long double);
214 long double exp2l(long double);
216 double expm1(double);
218 long double expm1l(long double);
222 long double fabsl(long double);
224 double fdim(double, double);
225 float fdimf(float, float);
226 long double fdiml(long double, long double);
228 double floor(double);
230 long double floorl(long double);
232 double fma(double, double, double);
233 float fmaf(float, float, float);
234 long double fmal(long double, long double, long double);
236 double fmax(double, double);
237 float fmaxf(float, float);
238 long double fmaxl(long double, long double);
240 double fmin(double, double);
241 float fminf(float, float);
242 long double fminl(long double, long double);
244 double fmod(double, double);
245 float fmodf(float, float);
246 long double fmodl(long double, long double);
248 double frexp(double, int *);
249 float frexpf(float, int *);
250 long double frexpl(long double, int *);
252 double hypot(double, double);
253 float hypotf(float, float);
254 long double hypotl(long double, long double);
258 int ilogbl(long double);
260 double ldexp(double, int);
261 float ldexpf(float, int);
262 long double ldexpl(long double, int);
264 double lgamma(double);
265 float lgammaf(float);
266 long double lgammal(long double);
268 long long llrint(double);
269 long long llrintf(float);
270 long long llrintl(long double);
272 long long llround(double);
273 long long llroundf(float);
274 long long llroundl(long double);
278 long double logl(long double);
280 double log10(double);
282 long double log10l(long double);
284 double log1p(double);
286 long double log1pl(long double);
290 long double log2l(long double);
294 long double logbl(long double);
298 long lrintl(long double);
302 long lroundl(long double);
304 double modf(double, double *);
305 float modff(float, float *);
306 long double modfl(long double, long double *);
308 double nan(const char *);
309 float nanf(const char *);
310 long double nanl(const char *);
312 double nearbyint(double);
313 float nearbyintf(float);
314 long double nearbyintl(long double);
316 double nextafter(double, double);
317 float nextafterf(float, float);
318 long double nextafterl(long double, long double);
320 double nexttoward(double, long double);
321 float nexttowardf(float, long double);
322 long double nexttowardl(long double, long double);
324 double pow(double, double);
325 float powf(float, float);
326 long double powl(long double, long double);
328 double remainder(double, double);
329 float remainderf(float, float);
330 long double remainderl(long double, long double);
332 double remquo(double, double, int *);
333 float remquof(float, float, int *);
334 long double remquol(long double, long double, int *);
338 long double rintl(long double);
340 double round(double);
342 long double roundl(long double);
344 double scalbln(double, long);
345 float scalblnf(float, long);
346 long double scalblnl(long double, long);
348 double scalbn(double, int);
349 float scalbnf(float, int);
350 long double scalbnl(long double, int);
354 long double sinl(long double);
358 long double sinhl(long double);
362 long double sqrtl(long double);
366 long double tanl(long double);
370 long double tanhl(long double);
372 double tgamma(double);
373 float tgammaf(float);
374 long double tgammal(long double);
376 double trunc(double);
378 long double truncl(long double);
381 #if defined(_XOPEN_SOURCE) || defined(_BSD_SOURCE)
383 #define MAXFLOAT 3.40282346638528859812e+38F
386 #if defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
387 #define M_E 2.7182818284590452354 /* e */
388 #define M_LOG2E 1.4426950408889634074 /* log_2 e */
389 #define M_LOG10E 0.43429448190325182765 /* log_10 e */
390 #define M_LN2 0.69314718055994530942 /* log_e 2 */
391 #define M_LN10 2.30258509299404568402 /* log_e 10 */
392 #define M_PI 3.14159265358979323846 /* pi */
393 #define M_PI_2 1.57079632679489661923 /* pi/2 */
394 #define M_PI_4 0.78539816339744830962 /* pi/4 */
395 #define M_1_PI 0.31830988618379067154 /* 1/pi */
396 #define M_2_PI 0.63661977236758134308 /* 2/pi */
397 #define M_2_SQRTPI 1.12837916709551257390 /* 2/sqrt(pi) */
398 #define M_SQRT2 1.41421356237309504880 /* sqrt(2) */
399 #define M_SQRT1_2 0.70710678118654752440 /* 1/sqrt(2) */
405 double jn(int, double);
409 double yn(int, double);
412 #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
413 #define HUGE 3.40282346638528859812e+38F
415 double drem(double, double);
416 float dremf(float, float);
421 double scalb(double, double);
422 float scalbf(float, float);
424 double significand(double);
425 float significandf(float);
427 double lgamma_r(double, int*);
428 float lgammaf_r(float, int*);
432 float jnf(int, float);
436 float ynf(int, float);
440 long double lgammal_r(long double, int*);
442 void sincos(double, double*, double*);
443 void sincosf(float, float*, float*);
444 void sincosl(long double, long double*, long double*);
446 double exp10(double);
448 long double exp10l(long double);
450 double pow10(double);
452 long double pow10l(long double);