Fix a number of core kernel issues related to HAMMER operation.
[dragonfly.git] / include / math.h
blob97199744d3af1fe45d46f2aa0beaf3b9b5b8d605
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 * ====================================================
11 * $NetBSD: math.h,v 1.46 2007/02/22 22:08:19 drochner Exp $
12 * $DragonFly: src/include/math.h,v 1.12 2007/06/17 18:00:08 pavalos Exp $
16 * @(#)fdlibm.h 5.1 93/09/24
19 #ifndef _MATH_H_
20 #define _MATH_H_
22 #include <sys/cdefs.h>
24 #if __GNUC_PREREQ__(3, 3) || (defined(__INTEL_COMPILER) && __INTEL_COMPILER >= 800)
25 #define __MATH_BUILTIN_CONSTANTS
26 #endif
28 #if __GNUC_PREREQ__(3, 0) && !defined(__INTEL_COMPILER)
29 #define __MATH_BUILTIN_RELOPS
30 #endif
32 union __float_u {
33 unsigned char __dummy[sizeof(float)];
34 float __val;
37 union __double_u {
38 unsigned char __dummy[sizeof(double)];
39 double __val;
42 union __long_double_u {
43 unsigned char __dummy[sizeof(long double)];
44 long double __val;
47 #include <machine/math.h>
49 #ifdef __HAVE_LONG_DOUBLE
50 #define __fpmacro_unary_floating(__name, __arg0) \
51 /* LINTED */ \
52 ((sizeof (__arg0) == sizeof (float)) \
53 ? __ ## __name ## f (__arg0) \
54 : (sizeof (__arg0) == sizeof (double)) \
55 ? __ ## __name ## d (__arg0) \
56 : __ ## __name ## l (__arg0))
57 #else
58 #define __fpmacro_unary_floating(__name, __arg0) \
59 /* LINTED */ \
60 ((sizeof (__arg0) == sizeof (float)) \
61 ? __ ## __name ## f (__arg0) \
62 : __ ## __name ## d (__arg0))
63 #endif /* __HAVE_LONG_DOUBLE */
66 * ANSI/POSIX
68 /* 7.12#3 HUGE_VAL, HUGELF, HUGE_VALL */
69 extern const union __double_u __infinity;
70 #ifdef __MATH_BUILTIN_CONSTANTS
71 #define HUGE_VAL __builtin_huge_val()
72 #else
73 #define HUGE_VAL __infinity.__val
74 #endif
77 * ISO C99
79 #if __ISO_C_VISIBLE >= 1999
80 /* 7.12#3 HUGE_VAL, HUGELF, HUGE_VALL */
81 extern const union __float_u __infinityf;
82 #ifdef __MATH_BUILTIN_CONSTANTS
83 #define HUGE_VALF __builtin_huge_valf()
84 #else
85 #define HUGE_VALF __infinityf.__val
86 #endif
88 extern const union __long_double_u __infinityl;
89 #define HUGE_VALL __infinityl.__val
91 /* 7.12#4 INFINITY */
92 #ifdef __MATH_BUILTIN_CONSTANTS
93 #define INFINITY __builtin_inf()
94 #elif defined(__INFINITY)
95 #define INFINITY __INFINITY /* float constant which overflows */
96 #else
97 #define INFINITY HUGE_VALF /* positive infinity */
98 #endif /* __INFINITY */
100 /* 7.12#5 NAN: a quiet NaN, if supported */
101 #ifdef __MATH_BUILTIN_CONSTANTS
102 #define NAN __builtin_nan("")
103 #elif defined(__HAVE_NANF)
104 extern const union __float_u __nanf;
105 #define NAN __nanf.__val
106 #endif /* __HAVE_NANF */
108 /* 7.12#6 number classification macros */
109 #define FP_INFINITE 0x00
110 #define FP_NAN 0x01
111 #define FP_NORMAL 0x02
112 #define FP_SUBNORMAL 0x03
113 #define FP_ZERO 0x04
114 /* NetBSD extensions */
115 #define _FP_LOMD 0x80 /* range for machine-specific classes */
116 #define _FP_HIMD 0xff
118 #endif /* ISO C99 */
121 * XOPEN/SVID
123 #if __XSI_VISIBLE > 0
124 #define M_E 2.7182818284590452354 /* e */
125 #define M_LOG2E 1.4426950408889634074 /* log 2e */
126 #define M_LOG10E 0.43429448190325182765 /* log 10e */
127 #define M_LN2 0.69314718055994530942 /* log e2 */
128 #define M_LN10 2.30258509299404568402 /* log e10 */
129 #define M_PI 3.14159265358979323846 /* pi */
130 #define M_PI_2 1.57079632679489661923 /* pi/2 */
131 #define M_PI_4 0.78539816339744830962 /* pi/4 */
132 #define M_1_PI 0.31830988618379067154 /* 1/pi */
133 #define M_2_PI 0.63661977236758134308 /* 2/pi */
134 #define M_2_SQRTPI 1.12837916709551257390 /* 2/sqrt(pi) */
135 #define M_SQRT2 1.41421356237309504880 /* sqrt(2) */
136 #define M_SQRT1_2 0.70710678118654752440 /* 1/sqrt(2) */
138 #define MAXFLOAT ((float)3.40282346638528860e+38)
139 extern int signgam;
140 #endif /* _XSI_VISIBLE */
142 #if __DF_VISIBLE
143 #define HUGE MAXFLOAT
146 * set X_TLOSS = pi*2**52, which is possibly defined in <values.h>
147 * (one may replace the following line by "#include <values.h>")
150 #define X_TLOSS 1.41484755040568800000e+16
152 #define DOMAIN 1
153 #define SING 2
154 #define OVERFLOW 3
155 #define UNDERFLOW 4
156 #define TLOSS 5
157 #define PLOSS 6
159 #endif /* __DF_VISIBLE */
161 __BEGIN_DECLS
163 * ANSI/POSIX
165 double acos(double);
166 double asin(double);
167 double atan(double);
168 double atan2(double, double);
169 double cos(double);
170 double sin(double);
171 double tan(double);
173 double cosh(double);
174 double sinh(double);
175 double tanh(double);
177 double exp(double);
178 double frexp(double, int *);
179 double ldexp(double, int);
180 double log(double);
181 double log2(double);
182 double log10(double);
183 double modf(double, double *);
185 double pow(double, double);
186 double sqrt(double);
188 double ceil(double);
189 double fabs(double);
190 double floor(double);
191 double fmod(double, double);
193 #if __XSI_VISIBLE > 0
194 double erf(double);
195 double erfc(double);
196 double gamma(double);
197 double hypot(double, double);
198 int finite(double);
199 double j0(double);
200 double j1(double);
201 double jn(int, double);
202 double lgamma(double);
203 double y0(double);
204 double y1(double);
205 double yn(int, double);
206 #endif /* __XSI_VISIBLE */
208 #if __XSI_VISIBLE >= 500
209 double acosh(double);
210 double asinh(double);
211 double atanh(double);
212 double cbrt(double);
213 double expm1(double);
214 int ilogb(double);
215 double log1p(double);
216 double logb(double);
217 double nextafter(double, double);
218 double remainder(double, double);
219 double rint(double);
220 double scalb(double, double);
221 #endif /* __XSI_VISIBLE >= 500 */
224 * ISO C99
226 #if __ISO_C_VISIBLE >= 1999
227 /* 7.12.3.1 int fpclassify(real-floating x) */
228 #define fpclassify(__x) __fpmacro_unary_floating(fpclassify, __x)
230 /* 7.12.3.2 int isfinite(real-floating x) */
231 #define isfinite(__x) __fpmacro_unary_floating(isfinite, __x)
233 /* 7.12.3.5 int isnormal(real-floating x) */
234 #define isnormal(__x) (fpclassify(__x) == FP_NORMAL)
236 /* 7.12.3.6 int signbit(real-floating x) */
237 #define signbit(__x) __fpmacro_unary_floating(signbit, __x)
239 /* 7.12.4 trigonometric */
241 float acosf(float);
242 float asinf(float);
243 float atanf(float);
244 float atan2f(float, float);
245 float cosf(float);
246 float sinf(float);
247 float tanf(float);
249 /* 7.12.5 hyperbolic */
251 float acoshf(float);
252 float asinhf(float);
253 float atanhf(float);
254 float coshf(float);
255 float sinhf(float);
256 float tanhf(float);
258 /* 7.12.6 exp / log */
260 float expf(float);
261 float expm1f(float);
262 float frexpf(float, int *);
263 int ilogbf(float);
264 float ldexpf(float, int);
265 float logf(float);
266 float log2f(float);
267 float log10f(float);
268 float log1pf(float);
269 float logbf(float);
270 float modff(float, float *);
271 float scalbnf(float, int);
273 /* 7.12.7 power / absolute */
275 float cbrtf(float);
276 float fabsf(float);
277 float hypotf(float, float);
278 float powf(float, float);
279 float sqrtf(float);
281 /* 7.12.8 error / gamma */
283 float erff(float);
284 float erfcf(float);
285 float lgammaf(float);
287 /* 7.12.9 nearest integer */
289 float ceilf(float);
290 float floorf(float);
291 float rintf(float);
292 double round(double);
293 float roundf(float);
294 double trunc(double);
295 float truncf(float);
296 long int lrint(double);
297 long int lrintf(float);
298 /* LONGLONG */
299 long long int llrint(double);
300 /* LONGLONG */
301 long long int llrintf(float);
302 long int lround(double);
303 long int lroundf(float);
304 /* LONGLONG */
305 long long int llround(double);
306 /* LONGLONG */
307 long long int llroundf(float);
309 /* 7.12.10 remainder */
311 float fmodf(float, float);
312 float remainderf(float, float);
314 /* 7.12.11 manipulation */
316 float copysignf(float, float);
317 double nan(const char *);
318 float nanf(const char *);
319 long double nanl(const char *);
320 float nextafterf(float, float);
322 #endif /* __ISO_C_VISIBLE >= 1999 */
324 #if __ISO_C_VISIBLE >= 1999
325 /* 7.12.3.3 int isinf(real-floating x) */
326 #ifdef __isinf
327 #define isinf(__x) __isinf(__x)
328 #else
329 #define isinf(__x) __fpmacro_unary_floating(isinf, __x)
330 #endif
332 /* 7.12.3.4 int isnan(real-floating x) */
333 #ifdef __isnan
334 #define isnan(__x) __isnan(__x)
335 #else
336 #define isnan(__x) __fpmacro_unary_floating(isnan, __x)
337 #endif
339 /* 7.12.14 Comparision macros */
340 #ifdef __MATH_BUILTIN_RELOPS
341 #define isgreater(x, y) __builtin_isgreater((x), (y))
342 #define isgreaterequal(x, y) __builtin_isgreaterequal((x), (y))
343 #define isless(x, y) __builtin_isless((x), (y))
344 #define islessequal(x, y) __builtin_islessequal((x), (y))
345 #define islessgreater(x, y) __builtin_islessgreater((x), (y))
346 #define isunordered(x, y) __builtin_isunordered((x), (y))
347 #else
348 #define isgreater(x, y) (!isunordered((x), (y)) && (x) > (y))
349 #define isgreaterequal(x, y) (!isunordered((x), (y)) && (x) >= (y))
350 #define isless(x, y) (!isunordered((x), (y)) && (x) < (y))
351 #define islessequal(x, y) (!isunordered((x), (y)) && (x) <= (y))
352 #define islessgreater(x, y) (!isunordered((x), (y)) && \
353 ((x) > (y) || (y) > (x)))
354 #define isunordered(x, y) (isnan(x) || isnan(y))
355 #endif /* __MATH_BUILTIN_RELOPS */
357 #endif /* __ISO_C_VISIBLE >= 1999 */
359 #if __DF_VISIBLE
361 * IEEE Test Vector
363 double significand(double);
366 * Functions callable from C, intended to support IEEE arithmetic.
368 double copysign(double, double);
369 double scalbn(double, int);
372 * BSD math library entry points
374 double drem(double, double);
377 * Reentrant version of gamma & lgamma; passes signgam back by reference
378 * as the second argument; user must allocate space for signgam.
380 double gamma_r(double, int *);
381 double lgamma_r(double, int *);
382 #endif /* __DF_VISIBLE */
385 #if __DF_VISIBLE
387 /* float versions of ANSI/POSIX functions */
389 float gammaf(float);
390 int finitef(float);
391 float j0f(float);
392 float j1f(float);
393 float jnf(int, float);
394 float y0f(float);
395 float y1f(float);
396 float ynf(int, float);
398 float scalbf(float, float);
401 * float version of IEEE Test Vector
403 float significandf(float);
406 * float versions of BSD math library entry points
408 float dremf(float, float);
411 * Float versions of reentrant version of gamma & lgamma; passes
412 * signgam back by reference as the second argument; user must
413 * allocate space for signgam.
415 float gammaf_r(float, int *);
416 float lgammaf_r(float, int *);
417 #endif /* __DF_VISIBLE */
420 * Library implementation
422 int __fpclassifyf(float);
423 int __fpclassifyd(double);
424 int __isfinitef(float);
425 int __isfinited(double);
426 int __isinff(float);
427 int __isinfd(double);
428 int __isnanf(float);
429 int __isnand(double);
430 int __signbitf(float);
431 int __signbitd(double);
433 #ifdef __HAVE_LONG_DOUBLE
434 int __fpclassifyl(long double);
435 int __isfinitel(long double);
436 int __isinfl(long double);
437 int __isnanl(long double);
438 int __signbitl(long double);
439 #endif
440 __END_DECLS
442 #endif /* _MATH_H_ */