sh: Remove impossible evalskip check in 'for'.
[dragonfly.git] / include / math.h
1 /*
2  * ====================================================
3  * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
4  *
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  * ====================================================
10  *
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 $
13  */
14
15 /*
16  * @(#)fdlibm.h 5.1 93/09/24
17  */
18
19 #ifndef _MATH_H_
20 #define _MATH_H_
21
22 #include <sys/cdefs.h>
23
24 #if __GNUC_PREREQ__(3, 3) || (defined(__INTEL_COMPILER) && __INTEL_COMPILER >= 800)
25 #define __MATH_BUILTIN_CONSTANTS
26 #endif
27
28 #if __GNUC_PREREQ__(3, 0) && !defined(__INTEL_COMPILER)
29 #define __MATH_BUILTIN_RELOPS
30 #endif
31
32 union __float_u {
33         unsigned char __dummy[sizeof(float)];
34         float __val;
35 };
36
37 union __double_u {
38         unsigned char __dummy[sizeof(double)];
39         double __val;
40 };
41
42 union __long_double_u {
43         unsigned char __dummy[sizeof(long double)];
44         long double __val;
45 };
46
47 #include <machine/math.h>
48
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 */
64
65 /*
66  * ANSI/POSIX
67  */
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
75
76 /*
77  * ISO C99
78  */
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
87
88 extern const union __long_double_u __infinityl;
89 #ifdef __MATH_BUILTIN_CONSTANTS
90 #define HUGE_VALL       __builtin_huge_vall()
91 #else
92 #define HUGE_VALL       __infinityl.__val
93 #endif
94
95 /* 7.12#4 INFINITY */
96 #ifdef __MATH_BUILTIN_CONSTANTS
97 #define INFINITY        __builtin_inf()
98 #elif defined(__INFINITY)
99 #define INFINITY        __INFINITY      /* float constant which overflows */
100 #else
101 #define INFINITY        HUGE_VALF       /* positive infinity */
102 #endif /* __INFINITY */
103
104 /* 7.12#5 NAN: a quiet NaN, if supported */
105 #ifdef __MATH_BUILTIN_CONSTANTS
106 #define NAN             __builtin_nan("")
107 #elif defined(__HAVE_NANF)
108 extern const union __float_u __nanf;
109 #define NAN             __nanf.__val
110 #endif /* __HAVE_NANF */
111
112 /* 7.12#6 number classification macros */
113 #define FP_INFINITE     0x00
114 #define FP_NAN          0x01
115 #define FP_NORMAL       0x02
116 #define FP_SUBNORMAL    0x03
117 #define FP_ZERO         0x04
118 /* NetBSD extensions */
119 #define _FP_LOMD        0x80            /* range for machine-specific classes */
120 #define _FP_HIMD        0xff
121
122 #endif /* ISO C99 */
123
124 /*
125  * XOPEN/SVID
126  */
127 #if __XSI_VISIBLE > 0
128 #define M_E             2.7182818284590452354   /* e */
129 #define M_LOG2E         1.4426950408889634074   /* log 2e */
130 #define M_LOG10E        0.43429448190325182765  /* log 10e */
131 #define M_LN2           0.69314718055994530942  /* log e2 */
132 #define M_LN10          2.30258509299404568402  /* log e10 */
133 #define M_PI            3.14159265358979323846  /* pi */
134 #define M_PI_2          1.57079632679489661923  /* pi/2 */
135 #define M_PI_4          0.78539816339744830962  /* pi/4 */
136 #define M_1_PI          0.31830988618379067154  /* 1/pi */
137 #define M_2_PI          0.63661977236758134308  /* 2/pi */
138 #define M_2_SQRTPI      1.12837916709551257390  /* 2/sqrt(pi) */
139 #define M_SQRT2         1.41421356237309504880  /* sqrt(2) */
140 #define M_SQRT1_2       0.70710678118654752440  /* 1/sqrt(2) */
141
142 #define MAXFLOAT        ((float)3.40282346638528860e+38)
143 extern int signgam;
144 #endif /* _XSI_VISIBLE */
145
146 #if __DF_VISIBLE
147 #define HUGE            MAXFLOAT
148
149 /*
150  * set X_TLOSS = pi*2**52, which is possibly defined in <values.h>
151  * (one may replace the following line by "#include <values.h>")
152  */
153
154 #define X_TLOSS         1.41484755040568800000e+16
155
156 #define DOMAIN          1
157 #define SING            2
158 #define OVERFLOW        3
159 #define UNDERFLOW       4
160 #define TLOSS           5
161 #define PLOSS           6
162
163 #endif /* __DF_VISIBLE */
164
165 __BEGIN_DECLS
166 /*
167  * ANSI/POSIX
168  */
169 double  acos(double);
170 double  asin(double);
171 double  atan(double);
172 double  atan2(double, double);
173 double  cos(double);
174 double  sin(double);
175 double  tan(double);
176
177 double  cosh(double);
178 double  sinh(double);
179 double  tanh(double);
180
181 double  exp(double);
182 double  exp2(double);
183 double  frexp(double, int *);
184 double  ldexp(double, int);
185 double  log(double);
186 double  log2(double);
187 double  log10(double);
188 double  modf(double, double *);
189
190 double  pow(double, double);
191 double  sqrt(double);
192
193 double  ceil(double);
194 double  fabs(double);
195 double  floor(double);
196 double  fmod(double, double);
197
198 #if __XSI_VISIBLE > 0
199 double  erf(double);
200 double  erfc(double);
201 double  gamma(double);
202 double  hypot(double, double);
203 int     finite(double);
204 double  j0(double);
205 double  j1(double);
206 double  jn(int, double);
207 double  lgamma(double);
208 double  tgamma(double);
209 double  y0(double);
210 double  y1(double);
211 double  yn(int, double);
212 #endif /* __XSI_VISIBLE */
213
214 #if __XSI_VISIBLE >= 500
215 double  acosh(double);
216 double  asinh(double);
217 double  atanh(double);
218 double  cbrt(double);
219 double  expm1(double);
220 int     ilogb(double);
221 double  log1p(double);
222 double  logb(double);
223 double  nextafter(double, double);
224 double  remainder(double, double);
225 double  rint(double);
226 double  scalb(double, double);
227 #endif /* __XSI_VISIBLE >= 500 */
228
229 /*
230  * ISO C99
231  */
232 #if __ISO_C_VISIBLE >= 1999
233 /* 7.12.3.1 int fpclassify(real-floating x) */
234 #define fpclassify(__x) __fpmacro_unary_floating(fpclassify, __x)
235
236 /* 7.12.3.2 int isfinite(real-floating x) */
237 #define isfinite(__x)   __fpmacro_unary_floating(isfinite, __x)
238
239 /* 7.12.3.5 int isnormal(real-floating x) */
240 #define isnormal(__x)   (fpclassify(__x) == FP_NORMAL)
241
242 /* 7.12.3.6 int signbit(real-floating x) */
243 #define signbit(__x)    __fpmacro_unary_floating(signbit, __x)
244
245 /* 7.12.4 trigonometric */
246
247 float   acosf(float);
248 float   asinf(float);
249 float   atanf(float);
250 float   atan2f(float, float);
251 float   cosf(float);
252 float   sinf(float);
253 float   tanf(float);
254
255 /* 7.12.5 hyperbolic */
256
257 float   acoshf(float);
258 float   asinhf(float);
259 float   atanhf(float);
260 float   coshf(float);
261 float   sinhf(float);
262 float   tanhf(float);
263
264 /* 7.12.6 exp / log */
265
266 float   expf(float);
267 float   exp2f(float);
268 float   expm1f(float);
269 float   frexpf(float, int *);
270 int     ilogbf(float);
271 float   ldexpf(float, int);
272 float   logf(float);
273 float   log2f(float);
274 float   log10f(float);
275 float   log1pf(float);
276 float   logbf(float);
277 float   modff(float, float *);
278 float   scalblnf(float, long);
279 float   scalbnf(float, int);
280
281 /* 7.12.7 power / absolute */
282
283 float   cbrtf(float);
284 float   fabsf(float);
285 float   hypotf(float, float);
286 float   powf(float, float);
287 float   sqrtf(float);
288
289 /* 7.12.8 error / gamma */
290
291 float   erff(float);
292 float   erfcf(float);
293 float   lgammaf(float);
294 float   tgammaf(float);
295
296 /* 7.12.9 nearest integer */
297
298 float   ceilf(float);
299 float   floorf(float);
300 float   nearbyintf(float);
301 double  nearbyint(double);
302 float   rintf(float);
303 double  round(double);
304 float   roundf(float);
305 double  trunc(double);
306 float   truncf(float);
307 long int        lrint(double);
308 long int        lrintf(float);
309 /* LONGLONG */
310 long long int   llrint(double);
311 /* LONGLONG */
312 long long int   llrintf(float);
313 long int        lround(double);
314 long int        lroundf(float);
315 /* LONGLONG */
316 long long int   llround(double);
317 /* LONGLONG */
318 long long int   llroundf(float);
319
320 /* 7.12.10 remainder */
321
322 float   fmodf(float, float);
323 float   remainderf(float, float);
324
325 /* 7.12.10.3 The remquo functions */
326 double remquo(double, double, int *);
327 float  remquof(float, float, int *);
328
329 /* 7.12.11 manipulation */
330
331 float   copysignf(float, float);
332 double  nan(const char *);
333 float   nanf(const char *);
334 float   nextafterf(float, float);
335
336 /* 7.12.12 maximum, minimum, positive difference */
337 double  fdim(double, double);
338 float   fdimf(float, float);
339
340 double  fmax(double, double);
341 float   fmaxf(float, float);
342
343 double  fmin(double, double);
344 float   fminf(float, float);
345
346
347 /* isoC99 */
348 double fma  (double, double, double);
349 float  fmaf (float,  float,  float);
350
351
352
353
354 #endif /* __ISO_C_VISIBLE >= 1999 */
355
356 #if __ISO_C_VISIBLE >= 1999
357 /* 7.12.3.3 int isinf(real-floating x) */
358 #ifdef __isinf
359 #define isinf(__x)      __isinf(__x)
360 #else
361 #define isinf(__x)      __fpmacro_unary_floating(isinf, __x)
362 #endif
363
364 /* 7.12.3.4 int isnan(real-floating x) */
365 #ifdef __isnan
366 #define isnan(__x)      __isnan(__x)
367 #else
368 #define isnan(__x)      __fpmacro_unary_floating(isnan, __x)
369 #endif
370
371 /* 7.12.14 Comparision macros */
372 #ifdef __MATH_BUILTIN_RELOPS
373 #define isgreater(x, y)         __builtin_isgreater((x), (y))
374 #define isgreaterequal(x, y)    __builtin_isgreaterequal((x), (y))
375 #define isless(x, y)            __builtin_isless((x), (y))
376 #define islessequal(x, y)       __builtin_islessequal((x), (y))
377 #define islessgreater(x, y)     __builtin_islessgreater((x), (y))
378 #define isunordered(x, y)       __builtin_isunordered((x), (y))
379 #else
380 #define isgreater(x, y)         (!isunordered((x), (y)) && (x) > (y))
381 #define isgreaterequal(x, y)    (!isunordered((x), (y)) && (x) >= (y))
382 #define isless(x, y)            (!isunordered((x), (y)) && (x) < (y))
383 #define islessequal(x, y)       (!isunordered((x), (y)) && (x) <= (y))
384 #define islessgreater(x, y)     (!isunordered((x), (y)) && \
385                                         ((x) > (y) || (y) > (x)))
386 #define isunordered(x, y)       (isnan(x) || isnan(y))
387 #endif /* __MATH_BUILTIN_RELOPS */
388
389 #endif /* __ISO_C_VISIBLE >= 1999 */
390
391 #if __DF_VISIBLE
392 /*
393  * IEEE Test Vector
394  */
395 double  significand(double);
396
397 /*
398  * Functions callable from C, intended to support IEEE arithmetic.
399  */
400 double  copysign(double, double);
401 double  scalbln(double, long);
402 double  scalbn(double, int);
403
404 /*
405  * BSD math library entry points
406  */
407 double  drem(double, double);
408
409 /*
410  * Reentrant version of gamma & lgamma; passes signgam back by reference
411  * as the second argument; user must allocate space for signgam.
412  */
413 double  gamma_r(double, int *);
414 double  lgamma_r(double, int *);
415 #endif /* __DF_VISIBLE */
416
417
418 #if __DF_VISIBLE
419
420 /* float versions of ANSI/POSIX functions */
421
422 float   gammaf(float);
423 int     finitef(float);
424 float   j0f(float);
425 float   j1f(float);
426 float   jnf(int, float);
427 float   y0f(float);
428 float   y1f(float);
429 float   ynf(int, float);
430
431 float   scalbf(float, float);
432
433 /*
434  * float version of IEEE Test Vector
435  */
436 float   significandf(float);
437
438 /*
439  * float versions of BSD math library entry points
440  */
441 float   dremf(float, float);
442
443 /*
444  * Float versions of reentrant version of gamma & lgamma; passes
445  * signgam back by reference as the second argument; user must
446  * allocate space for signgam.
447  */
448 float   gammaf_r(float, int *);
449 float   lgammaf_r(float, int *);
450 #endif /* __DF_VISIBLE */
451
452 /*
453  * Library implementation
454  */
455 int     __fpclassifyf(float);
456 int     __fpclassifyd(double);
457 int     __isfinitef(float);
458 int     __isfinited(double);
459 int     __isinff(float);
460 int     __isinfd(double);
461 int     __isnanf(float);
462 int     __isnand(double);
463 int     __signbitf(float);
464 int     __signbitd(double);
465
466 #ifdef __HAVE_LONG_DOUBLE
467 int     __fpclassifyl       (long double);
468 int     __isfinitel         (long double);
469 int     __isinfl            (long double);
470 int     __isnanl            (long double);
471 int     __signbitl          (long double);
472
473 long double     acosl       (long double);
474 long double     asinl       (long double);
475 long double     atan2l      (long double, long double);
476 long double     atanl       (long double);
477 long double     ceill       (long double);
478 long double     cosl        (long double);
479 long double     cbrtl       (long double);
480 long double     copysignl   (long double, long double);
481 long double     fdiml       (long double, long double);
482 long double     exp2l       (long double);
483 long double     fabsl       (long double);
484 long double     floorl      (long double);
485 long double     fmal        (long double, long double, long double);
486 long double     frexpl      (long double, int *);
487 long double     fmaxl       (long double, long double);
488 long double     fminl       (long double, long double);
489 long double     fmodl       (long double, long double);
490 long double     hypotl      (long double, long double);
491 int             ilogbl      (long double);
492 long double     ldexpl      (long double, int);
493 long long       llroundl    (long double);
494 long double     logbl       (long double);
495 long            lrintl      (long double);
496 long            lroundl     (long double);
497 long double     modfl       (long double, long double *);
498 long double     nanl        (const char *);
499 long double     nextafterl  (long double, long double);
500 double          nexttoward  (double,      long double);
501 float           nexttowardf (float,       long double);
502 long double     remainderl  (long double, long double);
503 long double     remquol     (long double, long double, int *);
504 long double     rintl       (long double);
505 long double     roundl      (long double);
506 long double     scalblnl    (long double, long);
507 long double     scalbnl     (long double, int);
508 long double     sinl        (long double);
509 long double     sqrtl       (long double);
510 long double     tanl        (long double);
511 long double     truncl      (long double);
512 #endif
513 __END_DECLS
514
515 #endif /* _MATH_H_ */