]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - lib/msun/src/math.h
Set math_errhandling to MATH_ERREXCEPT. Now that we have fenv.h, we
[FreeBSD/FreeBSD.git] / lib / msun / src / 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
12 /*
13  * from: @(#)fdlibm.h 5.1 93/09/24
14  * $FreeBSD$
15  */
16
17 #ifndef _MATH_H_
18 #define _MATH_H_
19
20 #include <sys/cdefs.h>
21 #include <sys/_types.h>
22 #include <machine/_limits.h>
23
24 /*
25  * ANSI/POSIX
26  */
27 extern const union __infinity_un {
28         unsigned char   __uc[8];
29         double          __ud;
30 } __infinity;
31
32 extern const union __nan_un {
33         unsigned char   __uc[sizeof(float)];
34         float           __uf;
35 } __nan;
36
37 #if __GNUC_PREREQ__(3, 3) || (defined(__INTEL_COMPILER) && __INTEL_COMPILER >= 800)
38 #define __MATH_BUILTIN_CONSTANTS
39 #endif
40
41 #if __GNUC_PREREQ__(3, 0) && !defined(__INTEL_COMPILER)
42 #define __MATH_BUILTIN_RELOPS
43 #endif
44
45 #ifdef __MATH_BUILTIN_CONSTANTS
46 #define HUGE_VAL        __builtin_huge_val()
47 #else
48 #define HUGE_VAL        (__infinity.__ud)
49 #endif
50
51 #if __ISO_C_VISIBLE >= 1999
52 #define FP_ILOGB0       (-__INT_MAX)
53 #define FP_ILOGBNAN     __INT_MAX
54
55 #ifdef __MATH_BUILTIN_CONSTANTS
56 #define HUGE_VALF       __builtin_huge_valf()
57 #define HUGE_VALL       __builtin_huge_vall()
58 #define INFINITY        __builtin_inf()
59 #define NAN             __builtin_nan("")
60 #else
61 #define HUGE_VALF       (float)HUGE_VAL
62 #define HUGE_VALL       (long double)HUGE_VAL
63 #define INFINITY        HUGE_VALF
64 #define NAN             (__nan.__uf)
65 #endif /* __MATH_BUILTIN_CONSTANTS */
66
67 #define MATH_ERRNO      1
68 #define MATH_ERREXCEPT  2
69 #define math_errhandling        MATH_ERREXCEPT
70
71 /* Symbolic constants to classify floating point numbers. */
72 #define FP_INFINITE     0x01
73 #define FP_NAN          0x02
74 #define FP_NORMAL       0x04
75 #define FP_SUBNORMAL    0x08
76 #define FP_ZERO         0x10
77 #define fpclassify(x) \
78     ((sizeof (x) == sizeof (float)) ? __fpclassifyf(x) \
79     : (sizeof (x) == sizeof (double)) ? __fpclassifyd(x) \
80     : __fpclassifyl(x))
81
82 #define isfinite(x)                                     \
83     ((sizeof (x) == sizeof (float)) ? __isfinitef(x)    \
84     : (sizeof (x) == sizeof (double)) ? __isfinite(x)   \
85     : __isfinitel(x))
86 #define isinf(x)                                        \
87     ((sizeof (x) == sizeof (float)) ? __isinff(x)       \
88     : (sizeof (x) == sizeof (double)) ? isinf(x)        \
89     : __isinfl(x))
90 #define isnan(x)                                        \
91     ((sizeof (x) == sizeof (float)) ? isnanf(x)         \
92     : (sizeof (x) == sizeof (double)) ? isnan(x)        \
93     : __isnanl(x))
94 #define isnormal(x)                                     \
95     ((sizeof (x) == sizeof (float)) ? __isnormalf(x)    \
96     : (sizeof (x) == sizeof (double)) ? __isnormal(x)   \
97     : __isnormall(x))
98
99 #ifdef __MATH_BUILTIN_RELOPS
100 #define isgreater(x, y)         __builtin_isgreater((x), (y))
101 #define isgreaterequal(x, y)    __builtin_isgreaterequal((x), (y))
102 #define isless(x, y)            __builtin_isless((x), (y))
103 #define islessequal(x, y)       __builtin_islessequal((x), (y))
104 #define islessgreater(x, y)     __builtin_islessgreater((x), (y))
105 #define isunordered(x, y)       __builtin_isunordered((x), (y))
106 #else
107 #define isgreater(x, y)         (!isunordered((x), (y)) && (x) > (y))
108 #define isgreaterequal(x, y)    (!isunordered((x), (y)) && (x) >= (y))
109 #define isless(x, y)            (!isunordered((x), (y)) && (x) < (y))
110 #define islessequal(x, y)       (!isunordered((x), (y)) && (x) <= (y))
111 #define islessgreater(x, y)     (!isunordered((x), (y)) && \
112                                         ((x) > (y) || (y) > (x)))
113 #define isunordered(x, y)       (isnan(x) || isnan(y))
114 #endif /* __MATH_BUILTIN_RELOPS */
115
116 #define signbit(x)                                      \
117     ((sizeof (x) == sizeof (float)) ? __signbitf(x)     \
118     : (sizeof (x) == sizeof (double)) ? __signbit(x)    \
119     : __signbitl(x))
120
121 typedef __double_t      double_t;
122 typedef __float_t       float_t;
123 #endif /* __ISO_C_VISIBLE >= 1999 */
124
125 /*
126  * XOPEN/SVID
127  */
128 #if __BSD_VISIBLE || __XSI_VISIBLE
129 #define M_E             2.7182818284590452354   /* e */
130 #define M_LOG2E         1.4426950408889634074   /* log 2e */
131 #define M_LOG10E        0.43429448190325182765  /* log 10e */
132 #define M_LN2           0.69314718055994530942  /* log e2 */
133 #define M_LN10          2.30258509299404568402  /* log e10 */
134 #define M_PI            3.14159265358979323846  /* pi */
135 #define M_PI_2          1.57079632679489661923  /* pi/2 */
136 #define M_PI_4          0.78539816339744830962  /* pi/4 */
137 #define M_1_PI          0.31830988618379067154  /* 1/pi */
138 #define M_2_PI          0.63661977236758134308  /* 2/pi */
139 #define M_2_SQRTPI      1.12837916709551257390  /* 2/sqrt(pi) */
140 #define M_SQRT2         1.41421356237309504880  /* sqrt(2) */
141 #define M_SQRT1_2       0.70710678118654752440  /* 1/sqrt(2) */
142
143 #define MAXFLOAT        ((float)3.40282346638528860e+38)
144 extern int signgam;
145 #endif /* __BSD_VISIBLE || __XSI_VISIBLE */
146
147 #if __BSD_VISIBLE
148 enum fdversion {fdlibm_ieee = -1, fdlibm_svid, fdlibm_xopen, fdlibm_posix};
149
150 #define _LIB_VERSION_TYPE enum fdversion
151 #define _LIB_VERSION _fdlib_version
152
153 /* if global variable _LIB_VERSION is not desirable, one may
154  * change the following to be a constant by:
155  *      #define _LIB_VERSION_TYPE const enum version
156  * In that case, after one initializes the value _LIB_VERSION (see
157  * s_lib_version.c) during compile time, it cannot be modified
158  * in the middle of a program
159  */
160 extern  _LIB_VERSION_TYPE  _LIB_VERSION;
161
162 #define _IEEE_  fdlibm_ieee
163 #define _SVID_  fdlibm_svid
164 #define _XOPEN_ fdlibm_xopen
165 #define _POSIX_ fdlibm_posix
166
167 /* We have a problem when using C++ since `exception' is a reserved
168    name in C++.  */
169 #ifndef __cplusplus
170 struct exception {
171         int type;
172         char *name;
173         double arg1;
174         double arg2;
175         double retval;
176 };
177 #endif
178
179 #define X_TLOSS         1.41484755040568800000e+16      /* pi*2**52 */
180
181 #define DOMAIN          1
182 #define SING            2
183 #define OVERFLOW        3
184 #define UNDERFLOW       4
185 #define TLOSS           5
186 #define PLOSS           6
187
188 #endif /* __BSD_VISIBLE */
189
190 /*
191  * Most of these functions have the side effect of setting errno, so they
192  * are not declared as __pure2.  (XXX: this point needs to be revisited,
193  * since C99 doesn't require the mistake of setting errno, and we mostly
194  * don't set it anyway.  In C99, pragmas and functions for changing the
195  * rounding mode affect the purity of these functions.)
196  */
197 __BEGIN_DECLS
198 /*
199  * ANSI/POSIX
200  */
201 int     __fpclassifyd(double) __pure2;
202 int     __fpclassifyf(float) __pure2;
203 int     __fpclassifyl(long double) __pure2;
204 int     __isfinitef(float) __pure2;
205 int     __isfinite(double) __pure2;
206 int     __isfinitel(long double) __pure2;
207 int     __isinff(float) __pure2;
208 int     __isinfl(long double) __pure2;
209 int     __isnanl(long double) __pure2;
210 int     __isnormalf(float) __pure2;
211 int     __isnormal(double) __pure2;
212 int     __isnormall(long double) __pure2;
213 int     __signbit(double) __pure2;
214 int     __signbitf(float) __pure2;
215 int     __signbitl(long double) __pure2;
216
217 double  acos(double);
218 double  asin(double);
219 double  atan(double);
220 double  atan2(double, double);
221 double  cos(double);
222 double  sin(double);
223 double  tan(double);
224
225 double  cosh(double);
226 double  sinh(double);
227 double  tanh(double);
228
229 double  exp(double);
230 double  frexp(double, int *);   /* fundamentally !__pure2 */
231 double  ldexp(double, int);
232 double  log(double);
233 double  log10(double);
234 double  modf(double, double *); /* fundamentally !__pure2 */
235
236 double  pow(double, double);
237 double  sqrt(double);
238
239 double  ceil(double);
240 double  fabs(double);
241 double  floor(double);
242 double  fmod(double, double);
243
244 /*
245  * These functions are not in C90 so they can be "right".  The ones that
246  * never set errno in lib/msun are declared as __pure2.
247  */
248 #if __BSD_VISIBLE || __ISO_C_VISIBLE >= 1999 || __XSI_VISIBLE
249 double  acosh(double);
250 double  asinh(double);
251 double  atanh(double);
252 double  cbrt(double) __pure2;
253 double  erf(double);
254 double  erfc(double) __pure2;
255 double  expm1(double) __pure2;
256 double  hypot(double, double);
257 int     ilogb(double);
258 int     (isinf)(double) __pure2;
259 int     (isnan)(double) __pure2;
260 double  lgamma(double);
261 long long llrint(double);
262 long long llround(double);
263 double  log1p(double) __pure2;
264 double  logb(double) __pure2;
265 long    lrint(double);
266 long    lround(double);
267 double  nextafter(double, double);
268 double  remainder(double, double);
269 double  rint(double) __pure2;
270 #endif /* __BSD_VISIBLE || __ISO_C_VISIBLE >= 1999 || __XSI_VISIBLE */
271
272 #if __BSD_VISIBLE || __XSI_VISIBLE
273 double  j0(double);
274 double  j1(double);
275 double  jn(int, double);
276 double  scalb(double, double);
277 double  y0(double);
278 double  y1(double);
279 double  yn(int, double);
280
281 #if __XSI_VISIBLE <= 500 || __BSD_VISIBLE
282 double  gamma(double);
283 #endif
284 #endif /* __BSD_VISIBLE || __XSI_VISIBLE */
285
286 #if __BSD_VISIBLE || __ISO_C_VISIBLE >= 1999
287 double  copysign(double, double) __pure2;
288 double  fdim(double, double);
289 double  fmax(double, double) __pure2;
290 double  fmin(double, double) __pure2;
291 double  nearbyint(double) __pure2;
292 double  round(double);
293 double  scalbln(double, long);
294 double  scalbn(double, int);
295 double  tgamma(double);
296 double  trunc(double);
297 #endif
298
299 /*
300  * BSD math library entry points
301  */
302 #if __BSD_VISIBLE
303 double  drem(double, double);
304 int     finite(double) __pure2;
305 int     isnanf(float) __pure2;
306
307 /*
308  * Reentrant version of gamma & lgamma; passes signgam back by reference
309  * as the second argument; user must allocate space for signgam.
310  */
311 double  gamma_r(double, int *);
312 double  lgamma_r(double, int *);
313
314 /*
315  * IEEE Test Vector
316  */
317 double  significand(double);
318
319 #ifndef __cplusplus
320 int     matherr(struct exception *);
321 #endif
322 #endif /* __BSD_VISIBLE */
323
324 /* float versions of ANSI/POSIX functions */
325 #if __ISO_C_VISIBLE >= 1999
326 float   acosf(float);
327 float   asinf(float);
328 float   atanf(float);
329 float   atan2f(float, float);
330 float   cosf(float);
331 float   sinf(float);
332 float   tanf(float);
333
334 float   coshf(float);
335 float   sinhf(float);
336 float   tanhf(float);
337
338 float   expf(float);
339 float   expm1f(float) __pure2;
340 float   frexpf(float, int *);   /* fundamentally !__pure2 */
341 int     ilogbf(float);
342 float   ldexpf(float, int);
343 float   log10f(float);
344 float   log1pf(float) __pure2;
345 float   logf(float);
346 float   modff(float, float *);  /* fundamentally !__pure2 */
347
348 float   powf(float, float);
349 float   sqrtf(float);
350
351 float   ceilf(float);
352 float   fabsf(float);
353 float   floorf(float);
354 float   fmodf(float, float);
355 float   roundf(float);
356
357 float   erff(float);
358 float   erfcf(float) __pure2;
359 float   hypotf(float, float) __pure2;
360 float   lgammaf(float);
361
362 float   acoshf(float);
363 float   asinhf(float);
364 float   atanhf(float);
365 float   cbrtf(float) __pure2;
366 float   logbf(float) __pure2;
367 float   copysignf(float, float) __pure2;
368 long long llrintf(float);
369 long long llroundf(float);
370 long    lrintf(float);
371 long    lroundf(float);
372 float   nearbyintf(float) __pure2;
373 float   nextafterf(float, float);
374 float   remainderf(float, float);
375 float   rintf(float);
376 float   scalblnf(float, long);
377 float   scalbnf(float, int);
378 float   truncf(float);
379
380 float   fdimf(float, float);
381 float   fmaxf(float, float) __pure2;
382 float   fminf(float, float) __pure2;
383 #endif
384
385 /*
386  * float versions of BSD math library entry points
387  */
388 #if __BSD_VISIBLE
389 float   dremf(float, float);
390 int     finitef(float) __pure2;
391 float   gammaf(float);
392 float   j0f(float);
393 float   j1f(float);
394 float   jnf(int, float);
395 float   scalbf(float, float);
396 float   y0f(float);
397 float   y1f(float);
398 float   ynf(int, float);
399
400 /*
401  * Float versions of reentrant version of gamma & lgamma; passes
402  * signgam back by reference as the second argument; user must
403  * allocate space for signgam.
404  */
405 float   gammaf_r(float, int *);
406 float   lgammaf_r(float, int *);
407
408 /*
409  * float version of IEEE Test Vector
410  */
411 float   significandf(float);
412 #endif  /* __BSD_VISIBLE */
413
414 /*
415  * long double versions of ISO/POSIX math functions
416  */
417 #if __ISO_C_VISIBLE >= 1999
418 #if 0
419 long double     acoshl(long double);
420 long double     acosl(long double);
421 long double     asinhl(long double);
422 long double     asinl(long double);
423 long double     atan2l(long double, long double);
424 long double     atanhl(long double);
425 long double     atanl(long double);
426 long double     cbrtl(long double);
427 #endif
428 long double     ceill(long double);
429 long double     copysignl(long double, long double);
430 #if 0
431 long double     coshl(long double);
432 long double     cosl(long double);
433 long double     erfcl(long double);
434 long double     erfl(long double);
435 long double     exp2l(long double);
436 long double     expl(long double);
437 long double     expm1l(long double);
438 #endif
439 long double     fabsl(long double);
440 long double     fdiml(long double, long double);
441 long double     floorl(long double);
442 #if 0
443 long double     fmal(long double, long double, long double);
444 #endif
445 long double     fmaxl(long double, long double) __pure2;
446 long double     fminl(long double, long double) __pure2;
447 #if 0
448 long double     fmodl(long double, long double);
449 long double     frexpl(long double value, int *);
450 long double     hypotl(long double, long double);
451 #endif
452 int             ilogbl(long double);
453 #if 0
454 long double     ldexpl(long double, int);
455 long double     lgammal(long double);
456 long long       llrintl(long double);
457 long long       llroundl(long double);
458 long double     log10l(long double);
459 long double     log1pl(long double);
460 long double     log2l(long double);
461 long double     logbl(long double);
462 long double     logl(long double);
463 long            lrintl(long double);
464 long            lroundl(long double);
465 long double     modfl(long double, long double  *);
466 long double     nanl(const char *);
467 long double     nearbyintl(long double);
468 long double     nextafterl(long double, long double);
469 double          nexttoward(double, long double);
470 float           nexttowardf(float, long double);
471 long double     nexttowardl(long double, long double);
472 long double     powl(long double, long double);
473 long double     remainderl(long double, long double);
474 long double     remquol(long double, long double, int *);
475 long double     rintl(long double);
476 long double     roundl(long double);
477 long double     scalblnl(long double, long);
478 long double     scalbnl(long double, int);
479 long double     sinhl(long double);
480 long double     sinl(long double);
481 long double     sqrtl(long double);
482 long double     tanhl(long double);
483 long double     tanl(long double);
484 long double     tgammal(long double);
485 long double     truncl(long double);
486 #endif
487
488 #endif /* __ISO_C_VISIBLE >= 1999 */
489 __END_DECLS
490
491 #endif /* !_MATH_H_ */