consistency
[AROS.git] / compiler / mlib / math.h
blobd00492963807e8f4ba1c20e278033cbb340c5b7f
1 /*
2 * ====================================================
3 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
5 * Developed at SunPro, a Sun Microsystems, Inc. business.
6 * Permission to use, copy, modify, and distribute this
7 * software is freely granted, provided that this notice
8 * is preserved.
9 * ====================================================
13 * from: @(#)fdlibm.h 5.1 93/09/24
14 * $FreeBSD: src/lib/msun/src/math.h,v 1.62 2007/01/07 07:54:21 das Exp $
17 #ifndef _MATH_H_
18 #define _MATH_H_
20 #include <sys/cdefs.h>
22 #ifndef __AROS__
23 #include <sys/_types.h>
24 #include <machine/_limits.h>
25 #else
26 #include <sys/types.h>
27 #include <limits.h>
29 /* AROS doesn't define __INT_MAX, but INT_MAX will do just as well */
30 #define __INT_MAX INT_MAX
32 #define __GNUC_PREREQ__ __GNUC_PREREQ
34 #endif /* __AROS__ */
37 * ANSI/POSIX
39 extern const union __infinity_un {
40 unsigned char __uc[8];
41 double __ud;
42 } __infinity;
44 extern const union __nan_un {
45 unsigned char __uc[sizeof(float)];
46 float __uf;
47 } __nan;
49 #if __GNUC_PREREQ__(3, 3) || (defined(__INTEL_COMPILER) && __INTEL_COMPILER >= 800)
50 #define __MATH_BUILTIN_CONSTANTS
51 #endif
53 #if __GNUC_PREREQ__(3, 0) && !defined(__INTEL_COMPILER)
54 #define __MATH_BUILTIN_RELOPS
55 #endif
57 #ifdef __MATH_BUILTIN_CONSTANTS
58 #define HUGE_VAL __builtin_huge_val()
59 #else
60 #define HUGE_VAL (__infinity.__ud)
61 #endif
63 #if __ISO_C_VISIBLE >= 1999
64 #define FP_ILOGB0 (-__INT_MAX)
65 #define FP_ILOGBNAN __INT_MAX
67 #ifdef __MATH_BUILTIN_CONSTANTS
68 #define HUGE_VALF __builtin_huge_valf()
69 #define HUGE_VALL __builtin_huge_vall()
70 #define INFINITY __builtin_inf()
71 #define NAN __builtin_nan("")
72 #else
73 #define HUGE_VALF (float)HUGE_VAL
74 #define HUGE_VALL (long double)HUGE_VAL
75 #define INFINITY HUGE_VALF
76 #define NAN (__nan.__uf)
77 #endif /* __MATH_BUILTIN_CONSTANTS */
79 #define MATH_ERRNO 1
80 #define MATH_ERREXCEPT 2
81 #define math_errhandling MATH_ERREXCEPT
83 /* XXX We need a <machine/math.h>. */
84 #if defined(__ia64__) || defined(__sparc64__)
85 #define FP_FAST_FMA
86 #endif
87 #ifdef __ia64__
88 #define FP_FAST_FMAL
89 #endif
90 #define FP_FAST_FMAF
92 /* Symbolic constants to classify floating point numbers. */
93 #define FP_INFINITE 0x01
94 #define FP_NAN 0x02
95 #define FP_NORMAL 0x04
96 #define FP_SUBNORMAL 0x08
97 #define FP_ZERO 0x10
98 #define fpclassify(x) \
99 ((sizeof (x) == sizeof (float)) ? __fpclassifyf(x) \
100 : (sizeof (x) == sizeof (double)) ? __fpclassifyd(x) \
101 : __fpclassifyl(x))
103 #define isfinite(x) \
104 ((sizeof (x) == sizeof (float)) ? __isfinitef(x) \
105 : (sizeof (x) == sizeof (double)) ? __isfinite(x) \
106 : __isfinitel(x))
107 #define isinf(x) \
108 ((sizeof (x) == sizeof (float)) ? __isinff(x) \
109 : (sizeof (x) == sizeof (double)) ? isinf(x) \
110 : __isinfl(x))
111 #ifndef __AROS__
112 #define isnan(x) \
113 ((sizeof (x) == sizeof (float)) ? isnanf(x) \
114 : (sizeof (x) == sizeof (double)) ? isnan(x) \
115 : __isnanl(x))
116 #else
117 #define isnan(x) \
118 ((sizeof (x) == sizeof (float)) ? isnanf(x) \
119 : (sizeof (x) == sizeof (double)) ? __isnan(x) \
120 : __isnanl(x))
121 #endif
122 #define isnormal(x) \
123 ((sizeof (x) == sizeof (float)) ? __isnormalf(x) \
124 : (sizeof (x) == sizeof (double)) ? __isnormal(x) \
125 : __isnormall(x))
127 #ifdef __MATH_BUILTIN_RELOPS
128 #define isgreater(x, y) __builtin_isgreater((x), (y))
129 #define isgreaterequal(x, y) __builtin_isgreaterequal((x), (y))
130 #define isless(x, y) __builtin_isless((x), (y))
131 #define islessequal(x, y) __builtin_islessequal((x), (y))
132 #define islessgreater(x, y) __builtin_islessgreater((x), (y))
133 #define isunordered(x, y) __builtin_isunordered((x), (y))
134 #else
135 #define isgreater(x, y) (!isunordered((x), (y)) && (x) > (y))
136 #define isgreaterequal(x, y) (!isunordered((x), (y)) && (x) >= (y))
137 #define isless(x, y) (!isunordered((x), (y)) && (x) < (y))
138 #define islessequal(x, y) (!isunordered((x), (y)) && (x) <= (y))
139 #define islessgreater(x, y) (!isunordered((x), (y)) && \
140 ((x) > (y) || (y) > (x)))
141 #define isunordered(x, y) (isnan(x) || isnan(y))
142 #endif /* __MATH_BUILTIN_RELOPS */
144 #define signbit(x) \
145 ((sizeof (x) == sizeof (float)) ? __signbitf(x) \
146 : (sizeof (x) == sizeof (double)) ? __signbit(x) \
147 : __signbitl(x))
149 typedef __double_t double_t;
150 typedef __float_t float_t;
151 #endif /* __ISO_C_VISIBLE >= 1999 */
154 * XOPEN/SVID
156 #if __BSD_VISIBLE || __XSI_VISIBLE
157 #define M_E 2.7182818284590452354 /* e */
158 #define M_LOG2E 1.4426950408889634074 /* log 2e */
159 #define M_LOG10E 0.43429448190325182765 /* log 10e */
160 #define M_LN2 0.69314718055994530942 /* log e2 */
161 #define M_LN10 2.30258509299404568402 /* log e10 */
162 #define M_PI 3.14159265358979323846 /* pi */
163 #define M_PI_2 1.57079632679489661923 /* pi/2 */
164 #define M_PI_4 0.78539816339744830962 /* pi/4 */
165 #define M_1_PI 0.31830988618379067154 /* 1/pi */
166 #define M_2_PI 0.63661977236758134308 /* 2/pi */
167 #define M_2_SQRTPI 1.12837916709551257390 /* 2/sqrt(pi) */
168 #define M_SQRT2 1.41421356237309504880 /* sqrt(2) */
169 #define M_SQRT1_2 0.70710678118654752440 /* 1/sqrt(2) */
171 #define MAXFLOAT ((float)3.40282346638528860e+38)
172 extern int signgam;
173 #endif /* __BSD_VISIBLE || __XSI_VISIBLE */
175 #if __BSD_VISIBLE
176 #if 0
177 /* Old value from 4.4BSD-Lite math.h; this is probably better. */
178 #define HUGE HUGE_VAL
179 #else
180 #define HUGE MAXFLOAT
181 #endif
182 #endif /* __BSD_VISIBLE */
185 * Most of these functions depend on the rounding mode and have the side
186 * effect of raising floating-point exceptions, so they are not declared
187 * as __pure2. In C99, FENV_ACCESS affects the purity of these functions.
189 __BEGIN_DECLS
191 * ANSI/POSIX
193 int __fpclassifyd(double) __pure2;
194 int __fpclassifyf(float) __pure2;
195 int __fpclassifyl(long double) __pure2;
196 int __isfinitef(float) __pure2;
197 int __isfinite(double) __pure2;
198 int __isfinitel(long double) __pure2;
199 int __isinff(float) __pure2;
200 int __isinfl(long double) __pure2;
201 #ifdef __AROS__
202 int __isnan(double) __pure2;
203 #endif
204 int __isnanl(long double) __pure2;
205 int __isnormalf(float) __pure2;
206 int __isnormal(double) __pure2;
207 int __isnormall(long double) __pure2;
208 int __signbit(double) __pure2;
209 int __signbitf(float) __pure2;
210 int __signbitl(long double) __pure2;
212 double acos(double);
213 double asin(double);
214 double atan(double);
215 double atan2(double, double);
216 double cos(double);
217 double sin(double);
218 double tan(double);
220 double cosh(double);
221 double sinh(double);
222 double tanh(double);
224 double exp(double);
225 double frexp(double, int *); /* fundamentally !__pure2 */
226 double ldexp(double, int);
227 double log(double);
228 double log10(double);
229 double modf(double, double *); /* fundamentally !__pure2 */
231 double pow(double, double);
232 double sqrt(double);
234 double ceil(double);
235 double fabs(double) __pure2;
236 double floor(double);
237 double fmod(double, double);
240 * These functions are not in C90.
242 #if __BSD_VISIBLE || __ISO_C_VISIBLE >= 1999 || __XSI_VISIBLE
243 double acosh(double);
244 double asinh(double);
245 double atanh(double);
246 double cbrt(double);
247 double erf(double);
248 double erfc(double);
249 double exp2(double);
250 double expm1(double);
251 double fma(double, double, double);
252 double hypot(double, double);
253 int ilogb(double) __pure2;
254 int (isinf)(double) __pure2;
255 int (isnan)(double) __pure2;
256 double lgamma(double);
257 long long llrint(double);
258 long long llround(double);
259 double log1p(double);
260 double logb(double);
261 long lrint(double);
262 long lround(double);
263 double nextafter(double, double);
264 double remainder(double, double);
265 double remquo(double, double, int *);
266 double rint(double);
267 double nan(const char *tagp);
268 #endif /* __BSD_VISIBLE || __ISO_C_VISIBLE >= 1999 || __XSI_VISIBLE */
270 #if __BSD_VISIBLE || __XSI_VISIBLE
271 double j0(double);
272 double j1(double);
273 double jn(int, double);
274 double scalb(double, double);
275 double y0(double);
276 double y1(double);
277 double yn(int, double);
279 #if __XSI_VISIBLE <= 500 || __BSD_VISIBLE
280 double gamma(double);
281 #endif
282 #endif /* __BSD_VISIBLE || __XSI_VISIBLE */
284 #if __BSD_VISIBLE || __ISO_C_VISIBLE >= 1999
285 double copysign(double, double) __pure2;
286 double fdim(double, double);
287 double fmax(double, double) __pure2;
288 double fmin(double, double) __pure2;
289 double nearbyint(double);
290 double round(double);
291 double scalbln(double, long);
292 double scalbn(double, int);
293 double tgamma(double);
294 double trunc(double);
295 #endif
298 * BSD math library entry points
300 #if __BSD_VISIBLE
301 double drem(double, double);
302 int finite(double) __pure2;
303 int isnanf(float) __pure2;
306 * Reentrant version of gamma & lgamma; passes signgam back by reference
307 * as the second argument; user must allocate space for signgam.
309 double gamma_r(double, int *);
310 double lgamma_r(double, int *);
313 * IEEE Test Vector
315 double significand(double);
316 #endif /* __BSD_VISIBLE */
318 /* float versions of ANSI/POSIX functions */
319 #if __ISO_C_VISIBLE >= 1999
320 float acosf(float);
321 float asinf(float);
322 float atanf(float);
323 float atan2f(float, float);
324 float cosf(float);
325 float sinf(float);
326 float tanf(float);
328 float coshf(float);
329 float sinhf(float);
330 float tanhf(float);
332 float exp2f(float);
333 float expf(float);
334 float expm1f(float);
335 float frexpf(float, int *); /* fundamentally !__pure2 */
336 int ilogbf(float) __pure2;
337 float ldexpf(float, int);
338 float log10f(float);
339 float log1pf(float);
340 float logf(float);
341 float modff(float, float *); /* fundamentally !__pure2 */
343 float powf(float, float);
344 float sqrtf(float);
346 float ceilf(float);
347 float fabsf(float) __pure2;
348 float floorf(float);
349 float fmodf(float, float);
350 float roundf(float);
352 float erff(float);
353 float erfcf(float);
354 float hypotf(float, float);
355 float lgammaf(float);
357 float acoshf(float);
358 float asinhf(float);
359 float atanhf(float);
360 float cbrtf(float);
361 float logbf(float);
362 float copysignf(float, float) __pure2;
363 long long llrintf(float);
364 long long llroundf(float);
365 long lrintf(float);
366 long lroundf(float);
367 float nearbyintf(float);
368 float nextafterf(float, float);
369 float remainderf(float, float);
370 float remquof(float, float, int *);
371 float rintf(float);
372 float scalblnf(float, long);
373 float scalbnf(float, int);
374 float truncf(float);
376 float fdimf(float, float);
377 float fmaf(float, float, float);
378 float fmaxf(float, float) __pure2;
379 float fminf(float, float) __pure2;
381 float nanf(const char *tagp);
382 #endif
385 * float versions of BSD math library entry points
387 #if __BSD_VISIBLE
388 float dremf(float, float);
389 int finitef(float) __pure2;
390 float gammaf(float);
391 float j0f(float);
392 float j1f(float);
393 float jnf(int, float);
394 float scalbf(float, float);
395 float y0f(float);
396 float y1f(float);
397 float ynf(int, float);
400 * Float versions of reentrant version of gamma & lgamma; passes
401 * signgam back by reference as the second argument; user must
402 * allocate space for signgam.
404 float gammaf_r(float, int *);
405 float lgammaf_r(float, int *);
408 * float version of IEEE Test Vector
410 float significandf(float);
411 #endif /* __BSD_VISIBLE */
414 * long double versions of ISO/POSIX math functions
416 #if __ISO_C_VISIBLE >= 1999
417 #if 0
418 long double acoshl(long double);
419 long double acosl(long double);
420 long double asinhl(long double);
421 long double asinl(long double);
422 long double atan2l(long double, long double);
423 long double atanhl(long double);
424 long double atanl(long double);
425 long double cbrtl(long double);
426 #endif
427 long double ceill(long double);
428 long double copysignl(long double, long double) __pure2;
429 #if 0
430 long double coshl(long double);
431 long double cosl(long double);
432 long double erfcl(long double);
433 long double erfl(long double);
434 long double exp2l(long double);
435 long double expl(long double);
436 long double expm1l(long double);
437 #endif
438 long double fabsl(long double) __pure2;
439 long double fdiml(long double, long double);
440 long double floorl(long double);
441 long double fmal(long double, long double, long double);
442 long double fmaxl(long double, long double) __pure2;
443 long double fminl(long double, long double) __pure2;
444 #if 0
445 long double fmodl(long double, long double);
446 #endif
447 long double frexpl(long double value, int *); /* fundamentally !__pure2 */
448 #if 0
449 long double hypotl(long double, long double);
450 #endif
451 int ilogbl(long double) __pure2;
452 long double ldexpl(long double, int);
453 #if 0
454 long double lgammal(long double);
455 long long llrintl(long double);
456 #endif
457 long long llroundl(long double);
458 #if 0
459 long double log10l(long double);
460 long double log1pl(long double);
461 long double log2l(long double);
462 long double logbl(long double);
463 long double logl(long double);
464 long lrintl(long double);
465 #endif
466 long lroundl(long double);
467 long double modfl(long double, long double *); /* fundamentally !__pure2 */
468 #if 0
469 long double nanl(const char *) __pure2;
470 long double nearbyintl(long double);
471 #endif
472 long double nextafterl(long double, long double);
473 double nexttoward(double, long double);
474 float nexttowardf(float, long double);
475 long double nexttowardl(long double, long double);
476 #if 0
477 long double powl(long double, long double);
478 long double remainderl(long double, long double);
479 long double remquol(long double, long double, int *);
480 long double rintl(long double);
481 #endif
482 long double roundl(long double);
483 long double scalblnl(long double, long);
484 long double scalbnl(long double, int);
485 #if 0
486 long double sinhl(long double);
487 long double sinl(long double);
488 long double sqrtl(long double);
489 long double tanhl(long double);
490 long double tanl(long double);
491 long double tgammal(long double);
492 #endif
493 long double truncl(long double);
494 long double nanl(const char *tagp);
496 #endif /* __ISO_C_VISIBLE >= 1999 */
497 __END_DECLS
499 #endif /* !_MATH_H_ */