Linking blocktest without libc to allow terminal output
[minix3.git] / include / math.h
blobe495021ac825c1fe0215ea7476ea9b2e40b616a8
1 /* $NetBSD: math.h,v 1.63 2013/09/16 15:54:42 martin Exp $ */
3 /*
4 * ====================================================
5 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
7 * Developed at SunPro, a Sun Microsystems, Inc. business.
8 * Permission to use, copy, modify, and distribute this
9 * software is freely granted, provided that this notice
10 * is preserved.
11 * ====================================================
15 * @(#)fdlibm.h 5.1 93/09/24
18 #ifndef _MATH_H_
19 #define _MATH_H_
21 #include <sys/cdefs.h>
22 #include <sys/featuretest.h>
24 union __float_u {
25 unsigned char __dummy[sizeof(float)];
26 float __val;
29 union __double_u {
30 unsigned char __dummy[sizeof(double)];
31 double __val;
34 union __long_double_u {
35 unsigned char __dummy[sizeof(long double)];
36 long double __val;
39 #include <machine/math.h> /* may use __float_u, __double_u,
40 or __long_double_u */
41 #include <limits.h> /* for INT_{MIN,MAX} */
43 #if ((_POSIX_C_SOURCE - 0) >= 200809L || defined(_NETBSD_SOURCE))
44 # if defined(__FLT_EVAL_METHOD__) && (__FLT_EVAL_METHOD__ - 0) == 0
45 typedef double double_t;
46 typedef float float_t;
47 # elif (__FLT_EVAL_METHOD__ - 0) == 1
48 typedef double double_t;
49 typedef double float_t;
50 # elif (__FLT_EVAL_METHOD__ - 0) == 2
51 typedef long double double_t;
52 typedef long double float_t;
53 # endif
54 #endif
56 #ifdef __HAVE_LONG_DOUBLE
57 #define __fpmacro_unary_floating(__name, __arg0) \
58 /* LINTED */ \
59 ((sizeof (__arg0) == sizeof (float)) \
60 ? __ ## __name ## f (__arg0) \
61 : (sizeof (__arg0) == sizeof (double)) \
62 ? __ ## __name ## d (__arg0) \
63 : __ ## __name ## l (__arg0))
64 #else
65 #define __fpmacro_unary_floating(__name, __arg0) \
66 /* LINTED */ \
67 ((sizeof (__arg0) == sizeof (float)) \
68 ? __ ## __name ## f (__arg0) \
69 : __ ## __name ## d (__arg0))
70 #endif /* __HAVE_LONG_DOUBLE */
73 * ANSI/POSIX
75 /* 7.12#3 HUGE_VAL, HUGELF, HUGE_VALL */
76 #if __GNUC_PREREQ__(3, 3)
77 #define HUGE_VAL __builtin_huge_val()
78 #else
79 extern const union __double_u __infinity;
80 #define HUGE_VAL __infinity.__val
81 #endif
84 * ISO C99
86 #if !defined(_ANSI_SOURCE) && !defined(_POSIX_C_SOURCE) && \
87 !defined(_XOPEN_SOURCE) || \
88 ((__STDC_VERSION__ - 0) >= 199901L) || \
89 ((_POSIX_C_SOURCE - 0) >= 200112L) || \
90 ((_XOPEN_SOURCE - 0) >= 600) || \
91 defined(_ISOC99_SOURCE) || defined(_NETBSD_SOURCE)
92 /* 7.12#3 HUGE_VAL, HUGELF, HUGE_VALL */
93 #if __GNUC_PREREQ__(3, 3)
94 #define HUGE_VALF __builtin_huge_valf()
95 #define HUGE_VALL __builtin_huge_vall()
96 #else
97 extern const union __float_u __infinityf;
98 #define HUGE_VALF __infinityf.__val
100 extern const union __long_double_u __infinityl;
101 #define HUGE_VALL __infinityl.__val
102 #endif
104 /* 7.12#4 INFINITY */
105 #if defined(__INFINITY)
106 #define INFINITY __INFINITY /* float constant which overflows */
107 #elif __GNUC_PREREQ__(3, 3)
108 #define INFINITY __builtin_inff()
109 #else
110 #define INFINITY HUGE_VALF /* positive infinity */
111 #endif /* __INFINITY */
113 /* 7.12#5 NAN: a quiet NaN, if supported */
114 #ifdef __HAVE_NANF
115 #if __GNUC_PREREQ__(3,3)
116 #define NAN __builtin_nanf("")
117 #else
118 extern const union __float_u __nanf;
119 #define NAN __nanf.__val
120 #endif
121 #endif /* __HAVE_NANF */
123 /* 7.12#6 number classification macros */
124 #define FP_INFINITE 0x00
125 #define FP_NAN 0x01
126 #define FP_NORMAL 0x02
127 #define FP_SUBNORMAL 0x03
128 #define FP_ZERO 0x04
129 /* NetBSD extensions */
130 #define _FP_LOMD 0x80 /* range for machine-specific classes */
131 #define _FP_HIMD 0xff
133 #define FP_ILOGB0 INT_MIN
134 #define FP_ILOGBNAN INT_MAX
136 #endif /* !_ANSI_SOURCE && ... */
139 * XOPEN/SVID
141 #if defined(_XOPEN_SOURCE) || defined(_NETBSD_SOURCE)
142 #define M_E 2.7182818284590452354 /* e */
143 #define M_LOG2E 1.4426950408889634074 /* log 2e */
144 #define M_LOG10E 0.43429448190325182765 /* log 10e */
145 #define M_LN2 0.69314718055994530942 /* log e2 */
146 #define M_LN10 2.30258509299404568402 /* log e10 */
147 #define M_PI 3.14159265358979323846 /* pi */
148 #define M_PI_2 1.57079632679489661923 /* pi/2 */
149 #define M_PI_4 0.78539816339744830962 /* pi/4 */
150 #define M_1_PI 0.31830988618379067154 /* 1/pi */
151 #define M_2_PI 0.63661977236758134308 /* 2/pi */
152 #define M_2_SQRTPI 1.12837916709551257390 /* 2/sqrt(pi) */
153 #define M_SQRT2 1.41421356237309504880 /* sqrt(2) */
154 #define M_SQRT1_2 0.70710678118654752440 /* 1/sqrt(2) */
156 #define MAXFLOAT ((float)3.40282346638528860e+38)
157 extern int signgam;
158 #endif /* _XOPEN_SOURCE || _NETBSD_SOURCE */
160 #if defined(_NETBSD_SOURCE)
161 enum fdversion {fdlibm_ieee = -1, fdlibm_svid, fdlibm_xopen, fdlibm_posix};
163 #define _LIB_VERSION_TYPE enum fdversion
164 #define _LIB_VERSION _fdlib_version
166 /* if global variable _LIB_VERSION is not desirable, one may
167 * change the following to be a constant by:
168 * #define _LIB_VERSION_TYPE const enum version
169 * In that case, after one initializes the value _LIB_VERSION (see
170 * s_lib_version.c) during compile time, it cannot be modified
171 * in the middle of a program
173 extern _LIB_VERSION_TYPE _LIB_VERSION;
175 #define _IEEE_ fdlibm_ieee
176 #define _SVID_ fdlibm_svid
177 #define _XOPEN_ fdlibm_xopen
178 #define _POSIX_ fdlibm_posix
180 #ifndef __cplusplus
181 struct exception {
182 int type;
183 const char *name;
184 double arg1;
185 double arg2;
186 double retval;
188 #endif
190 #define HUGE MAXFLOAT
193 * set X_TLOSS = pi*2**52, which is possibly defined in <values.h>
194 * (one may replace the following line by "#include <values.h>")
197 #define X_TLOSS 1.41484755040568800000e+16
199 #define DOMAIN 1
200 #define SING 2
201 #define OVERFLOW 3
202 #define UNDERFLOW 4
203 #define TLOSS 5
204 #define PLOSS 6
206 #endif /* _NETBSD_SOURCE */
208 __BEGIN_DECLS
210 * ANSI/POSIX
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 exp2(double);
226 double frexp(double, int *);
227 double ldexp(double, int);
228 double log(double);
229 double log2(double);
230 double log10(double);
231 double modf(double, double *);
233 double pow(double, double);
234 double sqrt(double);
236 double ceil(double);
237 double fabs(double);
238 double floor(double);
239 double fmod(double, double);
241 #if defined(_XOPEN_SOURCE) || defined(_NETBSD_SOURCE)
242 double erf(double);
243 double erfc(double);
244 double gamma(double);
245 double hypot(double, double);
246 int finite(double);
247 double j0(double);
248 double j1(double);
249 double jn(int, double);
250 double lgamma(double);
251 double y0(double);
252 double y1(double);
253 double yn(int, double);
255 #if (_XOPEN_SOURCE - 0) >= 500 || defined(_NETBSD_SOURCE)
256 double acosh(double);
257 double asinh(double);
258 double atanh(double);
259 double cbrt(double);
260 double expm1(double);
261 int ilogb(double);
262 double log1p(double);
263 double logb(double);
264 double nextafter(double, double);
265 double remainder(double, double);
266 double rint(double);
267 double scalb(double, double);
268 #endif /* (_XOPEN_SOURCE - 0) >= 500 || defined(_NETBSD_SOURCE)*/
269 #endif /* _XOPEN_SOURCE || _NETBSD_SOURCE */
272 * ISO C99
274 #if !defined(_ANSI_SOURCE) && !defined(_POSIX_C_SOURCE) && \
275 !defined(_XOPEN_SOURCE) || \
276 ((__STDC_VERSION__ - 0) >= 199901L) || \
277 ((_POSIX_C_SOURCE - 0) >= 200112L) || \
278 ((_XOPEN_SOURCE - 0) >= 600) || \
279 defined(_ISOC99_SOURCE) || defined(_NETBSD_SOURCE)
280 /* 7.12.3.1 int fpclassify(real-floating x) */
281 #define fpclassify(__x) __fpmacro_unary_floating(fpclassify, __x)
283 /* 7.12.3.2 int isfinite(real-floating x) */
284 #define isfinite(__x) __fpmacro_unary_floating(isfinite, __x)
286 /* 7.12.3.5 int isnormal(real-floating x) */
287 #define isnormal(__x) (fpclassify(__x) == FP_NORMAL)
289 /* 7.12.3.6 int signbit(real-floating x) */
290 #define signbit(__x) __fpmacro_unary_floating(signbit, __x)
292 /* 7.12.4 trigonometric */
294 float acosf(float);
295 float asinf(float);
296 float atanf(float);
297 float atan2f(float, float);
298 float cosf(float);
299 float sinf(float);
300 float tanf(float);
302 long double acosl(long double);
303 long double asinl(long double);
304 long double atanl(long double);
305 long double atan2l(long double, long double);
306 long double cosl(long double);
307 long double sinl(long double);
308 long double tanl(long double);
310 /* 7.12.5 hyperbolic */
312 float acoshf(float);
313 float asinhf(float);
314 float atanhf(float);
315 float coshf(float);
316 float sinhf(float);
317 float tanhf(float);
318 long double acoshl(long double);
319 long double asinhl(long double);
320 long double atanhl(long double);
321 long double coshl(long double);
322 long double sinhl(long double);
323 long double tanhl(long double);
325 /* 7.12.6 exp / log */
327 float expf(float);
328 float exp2f(float);
329 float expm1f(float);
330 float frexpf(float, int *);
331 int ilogbf(float);
332 float ldexpf(float, int);
333 float logf(float);
334 float log2f(float);
335 float log10f(float);
336 float log1pf(float);
337 float logbf(float);
338 float modff(float, float *);
339 float scalbnf(float, int);
340 float scalblnf(float, long);
342 long double expl(long double);
343 long double exp2l(long double);
344 long double expm1l(long double);
345 long double frexpl(long double, int *);
346 int ilogbl(long double);
347 long double ldexpl(long double, int);
348 long double logl(long double);
349 long double log2l(long double);
350 long double log10l(long double);
351 long double log1pl(long double);
352 long double logbl(long double);
353 long double modfl(long double, long double *);
354 long double scalbnl(long double, int);
355 long double scalblnl(long double, long);
358 /* 7.12.7 power / absolute */
360 float cbrtf(float);
361 float fabsf(float);
362 float hypotf(float, float);
363 float powf(float, float);
364 float sqrtf(float);
365 long double cbrtl(long double);
366 long double fabsl(long double);
367 long double hypotl(long double, long double);
368 long double powl(long double, long double);
369 long double sqrtl(long double);
371 /* 7.12.8 error / gamma */
373 double tgamma(double);
374 float erff(float);
375 float erfcf(float);
376 float lgammaf(float);
377 float tgammaf(float);
378 long double erfl(long double);
379 long double erfcl(long double);
380 long double lgammal(long double);
381 long double tgammal(long double);
383 /* 7.12.9 nearest integer */
385 /* LONGLONG */
386 long long int llrint(double);
387 long int lround(double);
388 /* LONGLONG */
389 long long int llround(double);
390 long int lrint(double);
391 double round(double);
392 double trunc(double);
394 float ceilf(float);
395 float floorf(float);
396 /* LONGLONG */
397 long long int llrintf(float);
398 long int lroundf(float);
399 /* LONGLONG */
400 long long int llroundf(float);
401 long int lrintf(float);
402 float rintf(float);
403 float roundf(float);
404 float truncf(float);
405 long double ceill(long double);
406 long double floorl(long double);
407 /* LONGLONG */
408 long long int llrintl(long double);
409 long int lroundl(long double);
410 /* LONGLONG */
411 long long int llroundl(long double);
412 long int lrintl(long double);
413 long double rintl(long double);
414 long double roundl(long double);
415 long double truncl(long double);
417 /* 7.12.10 remainder */
419 float fmodf(float, float);
420 float remainderf(float, float);
421 long double fmodl(long double, long double);
422 long double remainderl(long double, long double);
424 /* 7.12.10.3 The remquo functions */
425 double remquo(double, double, int *);
426 float remquof(float, float, int *);
427 long double remquol(long double, long double, int *);
429 /* 7.12.11 manipulation */
431 double nan(const char *);
432 double nearbyint(double);
433 double nexttoward(double, long double);
434 float copysignf(float, float);
435 float nanf(const char *);
436 float nearbyintf(float);
437 float nextafterf(float, float);
438 float nexttowardf(float, long double);
439 long double copysignl(long double, long double);
440 long double nanl(const char *);
441 long double nearbyintl(long double);
442 long double nextafterl(long double, long double);
443 long double nexttowardl(long double, long double);
445 /* 7.12.14 comparison */
447 #define isunordered(x, y) (isnan(x) || isnan(y))
448 #define isgreater(x, y) (!isunordered((x), (y)) && (x) > (y))
449 #define isgreaterequal(x, y) (!isunordered((x), (y)) && (x) >= (y))
450 #define isless(x, y) (!isunordered((x), (y)) && (x) < (y))
451 #define islessequal(x, y) (!isunordered((x), (y)) && (x) <= (y))
452 #define islessgreater(x, y) (!isunordered((x), (y)) && \
453 ((x) > (y) || (y) > (x)))
454 double fdim(double, double);
455 double fma(double, double, double);
456 double fmax(double, double);
457 double fmin(double, double);
458 float fdimf(float, float);
459 float fmaf(float, float, float);
460 float fmaxf(float, float);
461 float fminf(float, float);
462 long double fdiml(long double, long double);
463 long double fmal(long double, long double, long double);
464 long double fmaxl(long double, long double);
465 long double fminl(long double, long double);
467 #endif /* !_ANSI_SOURCE && ... */
469 #if !defined(_ANSI_SOURCE) && !defined(_POSIX_C_SOURCE) || \
470 !defined(_XOPEN_SOURCE) || \
471 ((__STDC_VERSION__ - 0) >= 199901L) || \
472 ((_POSIX_C_SOURCE - 0) >= 200112L) || \
473 defined(_ISOC99_SOURCE) || defined(_NETBSD_SOURCE)
474 /* 7.12.3.3 int isinf(real-floating x) */
475 #if defined(__isinf) || defined(__HAVE_INLINE___ISINF)
476 #define isinf(__x) __isinf(__x)
477 #else
478 #define isinf(__x) __fpmacro_unary_floating(isinf, __x)
479 #endif
481 /* 7.12.3.4 int isnan(real-floating x) */
482 #if defined(__isnan) || defined(__HAVE_INLINE___ISNAN)
483 #define isnan(__x) __isnan(__x)
484 #else
485 #define isnan(__x) __fpmacro_unary_floating(isnan, __x)
486 #endif
487 #endif /* !_ANSI_SOURCE && ... */
489 #if defined(_NETBSD_SOURCE)
490 #ifndef __cplusplus
491 int matherr(struct exception *);
492 #endif
495 * IEEE Test Vector
497 double significand(double);
500 * Functions callable from C, intended to support IEEE arithmetic.
502 double copysign(double, double);
503 double scalbn(double, int);
504 double scalbln(double, long);
507 * BSD math library entry points
509 double drem(double, double);
511 #endif /* _NETBSD_SOURCE */
513 #if defined(_NETBSD_SOURCE) || defined(_REENTRANT)
515 * Reentrant version of gamma & lgamma; passes signgam back by reference
516 * as the second argument; user must allocate space for signgam.
518 double gamma_r(double, int *);
519 double lgamma_r(double, int *);
520 #endif /* _NETBSD_SOURCE || _REENTRANT */
523 #if defined(_NETBSD_SOURCE)
525 /* float versions of ANSI/POSIX functions */
527 float gammaf(float);
528 int isinff(float);
529 int isnanf(float);
530 int finitef(float);
531 float j0f(float);
532 float j1f(float);
533 float jnf(int, float);
534 float y0f(float);
535 float y1f(float);
536 float ynf(int, float);
538 float scalbf(float, float);
541 * float version of IEEE Test Vector
543 float significandf(float);
546 * float versions of BSD math library entry points
548 float dremf(float, float);
549 #endif /* _NETBSD_SOURCE */
551 #if defined(_NETBSD_SOURCE) || defined(_REENTRANT)
553 * Float versions of reentrant version of gamma & lgamma; passes
554 * signgam back by reference as the second argument; user must
555 * allocate space for signgam.
557 float gammaf_r(float, int *);
558 float lgammaf_r(float, int *);
559 #endif /* !... || _REENTRANT */
562 * Library implementation
564 int __fpclassifyf(float);
565 int __fpclassifyd(double);
566 int __isfinitef(float);
567 int __isfinited(double);
568 int __isinff(float);
569 int __isinfd(double);
570 int __isnanf(float);
571 int __isnand(double);
572 int __signbitf(float);
573 int __signbitd(double);
575 #ifdef __HAVE_LONG_DOUBLE
576 int __fpclassifyl(long double);
577 int __isfinitel(long double);
578 int __isinfl(long double);
579 int __isnanl(long double);
580 int __signbitl(long double);
581 #endif
583 __END_DECLS
585 #endif /* _MATH_H_ */