Only clear portion of framebuffer that's actually used (clearing 256MB
[cake.git] / compiler / mlib / math.h
blob5b8988979248546ebfdd4f0760b0388c937c6246
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 #endif /* __BSD_VISIBLE || __ISO_C_VISIBLE >= 1999 || __XSI_VISIBLE */
269 #if __BSD_VISIBLE || __XSI_VISIBLE
270 double j0(double);
271 double j1(double);
272 double jn(int, double);
273 double scalb(double, double);
274 double y0(double);
275 double y1(double);
276 double yn(int, double);
278 #if __XSI_VISIBLE <= 500 || __BSD_VISIBLE
279 double gamma(double);
280 #endif
281 #endif /* __BSD_VISIBLE || __XSI_VISIBLE */
283 #if __BSD_VISIBLE || __ISO_C_VISIBLE >= 1999
284 double copysign(double, double) __pure2;
285 double fdim(double, double);
286 double fmax(double, double) __pure2;
287 double fmin(double, double) __pure2;
288 double nearbyint(double);
289 double round(double);
290 double scalbln(double, long);
291 double scalbn(double, int);
292 double tgamma(double);
293 double trunc(double);
294 #endif
297 * BSD math library entry points
299 #if __BSD_VISIBLE
300 double drem(double, double);
301 int finite(double) __pure2;
302 int isnanf(float) __pure2;
305 * Reentrant version of gamma & lgamma; passes signgam back by reference
306 * as the second argument; user must allocate space for signgam.
308 double gamma_r(double, int *);
309 double lgamma_r(double, int *);
312 * IEEE Test Vector
314 double significand(double);
315 #endif /* __BSD_VISIBLE */
317 /* float versions of ANSI/POSIX functions */
318 #if __ISO_C_VISIBLE >= 1999
319 float acosf(float);
320 float asinf(float);
321 float atanf(float);
322 float atan2f(float, float);
323 float cosf(float);
324 float sinf(float);
325 float tanf(float);
327 float coshf(float);
328 float sinhf(float);
329 float tanhf(float);
331 float exp2f(float);
332 float expf(float);
333 float expm1f(float);
334 float frexpf(float, int *); /* fundamentally !__pure2 */
335 int ilogbf(float) __pure2;
336 float ldexpf(float, int);
337 float log10f(float);
338 float log1pf(float);
339 float logf(float);
340 float modff(float, float *); /* fundamentally !__pure2 */
342 float powf(float, float);
343 float sqrtf(float);
345 float ceilf(float);
346 float fabsf(float) __pure2;
347 float floorf(float);
348 float fmodf(float, float);
349 float roundf(float);
351 float erff(float);
352 float erfcf(float);
353 float hypotf(float, float);
354 float lgammaf(float);
356 float acoshf(float);
357 float asinhf(float);
358 float atanhf(float);
359 float cbrtf(float);
360 float logbf(float);
361 float copysignf(float, float) __pure2;
362 long long llrintf(float);
363 long long llroundf(float);
364 long lrintf(float);
365 long lroundf(float);
366 float nearbyintf(float);
367 float nextafterf(float, float);
368 float remainderf(float, float);
369 float remquof(float, float, int *);
370 float rintf(float);
371 float scalblnf(float, long);
372 float scalbnf(float, int);
373 float truncf(float);
375 float fdimf(float, float);
376 float fmaf(float, float, float);
377 float fmaxf(float, float) __pure2;
378 float fminf(float, float) __pure2;
379 #endif
382 * float versions of BSD math library entry points
384 #if __BSD_VISIBLE
385 float dremf(float, float);
386 int finitef(float) __pure2;
387 float gammaf(float);
388 float j0f(float);
389 float j1f(float);
390 float jnf(int, float);
391 float scalbf(float, float);
392 float y0f(float);
393 float y1f(float);
394 float ynf(int, float);
397 * Float versions of reentrant version of gamma & lgamma; passes
398 * signgam back by reference as the second argument; user must
399 * allocate space for signgam.
401 float gammaf_r(float, int *);
402 float lgammaf_r(float, int *);
405 * float version of IEEE Test Vector
407 float significandf(float);
408 #endif /* __BSD_VISIBLE */
411 * long double versions of ISO/POSIX math functions
413 #if __ISO_C_VISIBLE >= 1999
414 #if 0
415 long double acoshl(long double);
416 long double acosl(long double);
417 long double asinhl(long double);
418 long double asinl(long double);
419 long double atan2l(long double, long double);
420 long double atanhl(long double);
421 long double atanl(long double);
422 long double cbrtl(long double);
423 #endif
424 long double ceill(long double);
425 long double copysignl(long double, long double) __pure2;
426 #if 0
427 long double coshl(long double);
428 long double cosl(long double);
429 long double erfcl(long double);
430 long double erfl(long double);
431 long double exp2l(long double);
432 long double expl(long double);
433 long double expm1l(long double);
434 #endif
435 long double fabsl(long double) __pure2;
436 long double fdiml(long double, long double);
437 long double floorl(long double);
438 long double fmal(long double, long double, long double);
439 long double fmaxl(long double, long double) __pure2;
440 long double fminl(long double, long double) __pure2;
441 #if 0
442 long double fmodl(long double, long double);
443 #endif
444 long double frexpl(long double value, int *); /* fundamentally !__pure2 */
445 #if 0
446 long double hypotl(long double, long double);
447 #endif
448 int ilogbl(long double) __pure2;
449 long double ldexpl(long double, int);
450 #if 0
451 long double lgammal(long double);
452 long long llrintl(long double);
453 #endif
454 long long llroundl(long double);
455 #if 0
456 long double log10l(long double);
457 long double log1pl(long double);
458 long double log2l(long double);
459 long double logbl(long double);
460 long double logl(long double);
461 long lrintl(long double);
462 #endif
463 long lroundl(long double);
464 long double modfl(long double, long double *); /* fundamentally !__pure2 */
465 #if 0
466 long double nanl(const char *) __pure2;
467 long double nearbyintl(long double);
468 #endif
469 long double nextafterl(long double, long double);
470 double nexttoward(double, long double);
471 float nexttowardf(float, long double);
472 long double nexttowardl(long double, long double);
473 #if 0
474 long double powl(long double, long double);
475 long double remainderl(long double, long double);
476 long double remquol(long double, long double, int *);
477 long double rintl(long double);
478 #endif
479 long double roundl(long double);
480 long double scalblnl(long double, long);
481 long double scalbnl(long double, int);
482 #if 0
483 long double sinhl(long double);
484 long double sinl(long double);
485 long double sqrtl(long double);
486 long double tanhl(long double);
487 long double tanl(long double);
488 long double tgammal(long double);
489 #endif
490 long double truncl(long double);
492 #endif /* __ISO_C_VISIBLE >= 1999 */
493 __END_DECLS
495 #endif /* !_MATH_H_ */