]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - lib/msun/src/math.h
This commit was generated by cvs2svn to compensate for changes in r138287,
[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        0
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 #if 0
180 /* Old value from 4.4BSD-Lite math.h; this is probably better. */
181 #define HUGE            HUGE_VAL
182 #else
183 #define HUGE            MAXFLOAT
184 #endif
185
186 #define X_TLOSS         1.41484755040568800000e+16      /* pi*2**52 */
187
188 #define DOMAIN          1
189 #define SING            2
190 #define OVERFLOW        3
191 #define UNDERFLOW       4
192 #define TLOSS           5
193 #define PLOSS           6
194
195 #endif /* __BSD_VISIBLE */
196
197 /*
198  * Most of these functions have the side effect of setting errno, so they
199  * are not declared as __pure2.  (XXX: this point needs to be revisited,
200  * since C99 doesn't require the mistake of setting errno, and we mostly
201  * don't set it anyway.  In C99, pragmas and functions for changing the
202  * rounding mode affect the purity of these functions.)
203  */
204 __BEGIN_DECLS
205 /*
206  * ANSI/POSIX
207  */
208 int     __fpclassifyd(double) __pure2;
209 int     __fpclassifyf(float) __pure2;
210 int     __fpclassifyl(long double) __pure2;
211 int     __isfinitef(float) __pure2;
212 int     __isfinite(double) __pure2;
213 int     __isfinitel(long double) __pure2;
214 int     __isinff(float) __pure2;
215 int     __isinfl(long double) __pure2;
216 int     __isnanl(long double) __pure2;
217 int     __isnormalf(float) __pure2;
218 int     __isnormal(double) __pure2;
219 int     __isnormall(long double) __pure2;
220 int     __signbit(double) __pure2;
221 int     __signbitf(float) __pure2;
222 int     __signbitl(long double) __pure2;
223
224 double  acos(double);
225 double  asin(double);
226 double  atan(double);
227 double  atan2(double, double);
228 double  cos(double);
229 double  sin(double);
230 double  tan(double);
231
232 double  cosh(double);
233 double  sinh(double);
234 double  tanh(double);
235
236 double  exp(double);
237 double  frexp(double, int *);   /* fundamentally !__pure2 */
238 double  ldexp(double, int);
239 double  log(double);
240 double  log10(double);
241 double  modf(double, double *); /* fundamentally !__pure2 */
242
243 double  pow(double, double);
244 double  sqrt(double);
245
246 double  ceil(double);
247 double  fabs(double);
248 double  floor(double);
249 double  fmod(double, double);
250
251 /*
252  * These functions are not in C90 so they can be "right".  The ones that
253  * never set errno in lib/msun are declared as __pure2.
254  */
255 #if __BSD_VISIBLE || __ISO_C_VISIBLE >= 1999 || __XSI_VISIBLE
256 double  acosh(double);
257 double  asinh(double);
258 double  atanh(double);
259 double  cbrt(double) __pure2;
260 double  erf(double);
261 double  erfc(double) __pure2;
262 double  expm1(double) __pure2;
263 double  hypot(double, double);
264 int     ilogb(double);
265 int     (isinf)(double) __pure2;
266 int     (isnan)(double) __pure2;
267 double  lgamma(double);
268 double  log1p(double) __pure2;
269 double  logb(double) __pure2;
270 double  nextafter(double, double);
271 double  remainder(double, double);
272 double  rint(double) __pure2;
273 #endif /* __BSD_VISIBLE || __ISO_C_VISIBLE >= 1999 || __XSI_VISIBLE */
274
275 #if __BSD_VISIBLE || __XSI_VISIBLE
276 double  j0(double);
277 double  j1(double);
278 double  jn(int, double);
279 double  scalb(double, double);
280 double  y0(double);
281 double  y1(double);
282 double  yn(int, double);
283
284 #if __XSI_VISIBLE <= 500 || __BSD_VISIBLE
285 double  gamma(double);
286 #endif
287 #endif /* __BSD_VISIBLE || __XSI_VISIBLE */
288
289 #if __BSD_VISIBLE || __ISO_C_VISIBLE >= 1999
290 double  copysign(double, double) __pure2;
291 double  fdim(double, double);
292 double  fmax(double, double) __pure2;
293 double  fmin(double, double) __pure2;
294 double  nearbyint(double) __pure2;
295 double  round(double);
296 double  scalbln(double, long);
297 double  scalbn(double, int);
298 double  tgamma(double);
299 double  trunc(double);
300 #endif
301
302 /*
303  * BSD math library entry points
304  */
305 #if __BSD_VISIBLE
306 double  drem(double, double);
307 int     finite(double) __pure2;
308 int     isnanf(float) __pure2;
309
310 /*
311  * Reentrant version of gamma & lgamma; passes signgam back by reference
312  * as the second argument; user must allocate space for signgam.
313  */
314 double  gamma_r(double, int *);
315 double  lgamma_r(double, int *);
316
317 /*
318  * IEEE Test Vector
319  */
320 double  significand(double);
321
322 #ifndef __cplusplus
323 int     matherr(struct exception *);
324 #endif
325 #endif /* __BSD_VISIBLE */
326
327 /* float versions of ANSI/POSIX functions */
328 #if __ISO_C_VISIBLE >= 1999
329 float   acosf(float);
330 float   asinf(float);
331 float   atanf(float);
332 float   atan2f(float, float);
333 float   cosf(float);
334 float   sinf(float);
335 float   tanf(float);
336
337 float   coshf(float);
338 float   sinhf(float);
339 float   tanhf(float);
340
341 float   expf(float);
342 float   expm1f(float) __pure2;
343 float   frexpf(float, int *);   /* fundamentally !__pure2 */
344 int     ilogbf(float);
345 float   ldexpf(float, int);
346 float   log10f(float);
347 float   log1pf(float) __pure2;
348 float   logf(float);
349 float   modff(float, float *);  /* fundamentally !__pure2 */
350
351 float   powf(float, float);
352 float   sqrtf(float);
353
354 float   ceilf(float);
355 float   fabsf(float);
356 float   floorf(float);
357 float   fmodf(float, float);
358 float   roundf(float);
359
360 float   erff(float);
361 float   erfcf(float) __pure2;
362 float   hypotf(float, float) __pure2;
363 float   lgammaf(float);
364
365 float   acoshf(float);
366 float   asinhf(float);
367 float   atanhf(float);
368 float   cbrtf(float) __pure2;
369 float   logbf(float) __pure2;
370 float   copysignf(float, float) __pure2;
371 float   nearbyintf(float) __pure2;
372 float   nextafterf(float, float);
373 float   remainderf(float, float);
374 float   rintf(float);
375 float   scalblnf(float, long);
376 float   scalbnf(float, int);
377 float   truncf(float);
378
379 float   fdimf(float, float);
380 float   fmaxf(float, float) __pure2;
381 float   fminf(float, float) __pure2;
382 #endif
383
384 /*
385  * float versions of BSD math library entry points
386  */
387 #if __BSD_VISIBLE
388 float   dremf(float, float);
389 int     finitef(float) __pure2;
390 float   gammaf(float);
391 float   j0f(float);
392 float   j1f(float);
393 float   jnf(int, float);
394 float   scalbf(float, float);
395 float   y0f(float);
396 float   y1f(float);
397 float   ynf(int, float);
398
399 /*
400  * Float versions of reentrant version of gamma & lgamma; passes
401  * signgam back by reference as the second argument; user must
402  * allocate space for signgam.
403  */
404 float   gammaf_r(float, int *);
405 float   lgammaf_r(float, int *);
406
407 /*
408  * float version of IEEE Test Vector
409  */
410 float   significandf(float);
411 #endif  /* __BSD_VISIBLE */
412
413 /*
414  * long double versions of ISO/POSIX math functions
415  */
416 #if __ISO_C_VISIBLE >= 1999
417 #if 0
418 long double     acoshl(long double);
419 long double     acosl(long double);
420 long double     asinhl(long double);
421 long double     asinl(long double);
422 long double     atan2l(long double, long double);
423 long double     atanhl(long double);
424 long double     atanl(long double);
425 long double     cbrtl(long double);
426 long double     ceill(long double);
427 #endif
428 long double     copysignl(long double, long double);
429 #if 0
430 long double     coshl(long double);
431 long double     cosl(long double);
432 long double     erfcl(long double);
433 long double     erfl(long double);
434 long double     exp2l(long double);
435 long double     expl(long double);
436 long double     expm1l(long double);
437 #endif
438 long double     fabsl(long double);
439 long double     fdiml(long double, long double);
440 #if 0
441 long double     floorl(long double);
442 long double     fmal(long double, long double, long double);
443 #endif
444 long double     fmaxl(long double, long double) __pure2;
445 long double     fminl(long double, long double) __pure2;
446 #if 0
447 long double     fmodl(long double, long double);
448 long double     frexpl(long double      value, int *);
449 long double     hypotl(long double, long double);
450 #endif
451 int             ilogbl(long double);
452 #if 0
453 long double     ldexpl(long double, int);
454 long double     lgammal(long double);
455 long long       llrintl(long double);
456 long long       llroundl(long double);
457 long double     log10l(long double);
458 long double     log1pl(long double);
459 long double     log2l(long double);
460 long double     logbl(long double);
461 long double     logl(long double);
462 long            lrintl(long double);
463 long            lroundl(long double);
464 long double     modfl(long double, long double  *);
465 long double     nanl(const char *);
466 long double     nearbyintl(long double);
467 long double     nextafterl(long double, long double);
468 double          nexttoward(double, long double);
469 float           nexttowardf(float, long double);
470 long double     nexttowardl(long double, long double);
471 long double     powl(long double, long double);
472 long double     remainderl(long double, long double);
473 long double     remquol(long double, long double, int *);
474 long double     rintl(long double);
475 long double     roundl(long double);
476 long double     scalblnl(long double, long);
477 long double     scalbnl(long double, int);
478 long double     sinhl(long double);
479 long double     sinl(long double);
480 long double     sqrtl(long double);
481 long double     tanhl(long double);
482 long double     tanl(long double);
483 long double     tgammal(long double);
484 long double     truncl(long double);
485 #endif
486
487 #endif /* __ISO_C_VISIBLE >= 1999 */
488 __END_DECLS
489
490 #endif /* !_MATH_H_ */