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
9 * ====================================================
13 * from: @(#)fdlibm.h 5.1 93/09/24
20 #include <sys/cdefs.h>
21 #include <sys/_types.h>
22 #include <machine/_limits.h>
27 extern const union __infinity_un {
28 unsigned char __uc[8];
32 extern const union __nan_un {
33 unsigned char __uc[sizeof(float)];
37 #if (defined(__GNUC__) && ((__GNUC__ >= 3 && __GNUC_MINOR__ >= 3) || __GNUC__ >= 4)) || defined(__INTEL_COMPILER)
38 #define __MATH_BUILTIN_CONSTANTS
41 #if (defined(__GNUC__) && __GNUC__ >= 3 && !defined(__INTEL_COMPILER))
42 #define __MATH_BUILTIN_RELOPS
45 #ifdef __MATH_BUILTIN_CONSTANTS
46 #define HUGE_VAL __builtin_huge_val()
48 #define HUGE_VAL (__infinity.__ud)
51 #if __ISO_C_VISIBLE >= 1999
52 #define FP_ILOGB0 (-__INT_MAX)
53 #define FP_ILOGBNAN __INT_MAX
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("")
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 */
68 #define MATH_ERREXCEPT 2
69 #define math_errhandling 0
71 /* Symbolic constants to classify floating point numbers. */
72 #define FP_INFINITE 0x01
74 #define FP_NORMAL 0x04
75 #define FP_SUBNORMAL 0x08
77 #define fpclassify(x) \
78 ((sizeof (x) == sizeof (float)) ? __fpclassifyf(x) \
79 : (sizeof (x) == sizeof (double)) ? __fpclassifyd(x) \
83 ((sizeof (x) == sizeof (float)) ? __isfinitef(x) \
84 : (sizeof (x) == sizeof (double)) ? __isfinite(x) \
87 ((sizeof (x) == sizeof (float)) ? __isinff(x) \
88 : (sizeof (x) == sizeof (double)) ? isinf(x) \
91 ((sizeof (x) == sizeof (float)) ? isnanf(x) \
92 : (sizeof (x) == sizeof (double)) ? isnan(x) \
95 ((sizeof (x) == sizeof (float)) ? __isnormalf(x) \
96 : (sizeof (x) == sizeof (double)) ? __isnormal(x) \
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))
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 */
117 ((sizeof (x) == sizeof (float)) ? __signbitf(x) \
118 : (sizeof (x) == sizeof (double)) ? __signbit(x) \
121 typedef __double_t double_t;
122 typedef __float_t float_t;
123 #endif /* __ISO_C_VISIBLE >= 1999 */
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) */
143 #define MAXFLOAT ((float)3.40282346638528860e+38)
145 #endif /* __BSD_VISIBLE || __XSI_VISIBLE */
148 enum fdversion {fdlibm_ieee = -1, fdlibm_svid, fdlibm_xopen, fdlibm_posix};
150 #define _LIB_VERSION_TYPE enum fdversion
151 #define _LIB_VERSION _fdlib_version
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
160 extern _LIB_VERSION_TYPE _LIB_VERSION;
162 #define _IEEE_ fdlibm_ieee
163 #define _SVID_ fdlibm_svid
164 #define _XOPEN_ fdlibm_xopen
165 #define _POSIX_ fdlibm_posix
167 /* We have a problem when using C++ since `exception' is a reserved
180 /* Old value from 4.4BSD-Lite math.h; this is probably better. */
181 #define HUGE HUGE_VAL
183 #define HUGE MAXFLOAT
186 #define X_TLOSS 1.41484755040568800000e+16 /* pi*2**52 */
195 #endif /* __BSD_VISIBLE */
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.)
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;
227 double atan2(double, double);
237 double frexp(double, int *); /* fundamentally !__pure2 */
238 double ldexp(double, int);
240 double log10(double);
241 double modf(double, double *); /* fundamentally !__pure2 */
243 double pow(double, double);
248 double floor(double);
249 double fmod(double, double);
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.
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;
261 double erfc(double) __pure2;
262 double expm1(double) __pure2;
263 double hypot(double, 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 */
275 #if __BSD_VISIBLE || __XSI_VISIBLE
278 double jn(int, double);
279 double scalb(double, double);
282 double yn(int, double);
284 #if __XSI_VISIBLE <= 500 || __BSD_VISIBLE
285 double gamma(double);
287 #endif /* __BSD_VISIBLE || __XSI_VISIBLE */
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);
303 * BSD math library entry points
306 double drem(double, double);
307 int finite(double) __pure2;
308 int isnanf(float) __pure2;
311 * Reentrant version of gamma & lgamma; passes signgam back by reference
312 * as the second argument; user must allocate space for signgam.
314 double gamma_r(double, int *);
315 double lgamma_r(double, int *);
320 double significand(double);
323 int matherr(struct exception *);
325 #endif /* __BSD_VISIBLE */
327 /* float versions of ANSI/POSIX functions */
328 #if __ISO_C_VISIBLE >= 1999
332 float atan2f(float, float);
342 float expm1f(float) __pure2;
343 float frexpf(float, int *); /* fundamentally !__pure2 */
345 float ldexpf(float, int);
347 float log1pf(float) __pure2;
349 float modff(float, float *); /* fundamentally !__pure2 */
351 float powf(float, float);
357 float fmodf(float, float);
361 float erfcf(float) __pure2;
362 float hypotf(float, float) __pure2;
363 float lgammaf(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);
375 float scalblnf(float, long);
376 float scalbnf(float, int);
379 float fdimf(float, float);
380 float fmaxf(float, float) __pure2;
381 float fminf(float, float) __pure2;
385 * float versions of BSD math library entry points
388 float dremf(float, float);
389 int finitef(float) __pure2;
393 float jnf(int, float);
394 float scalbf(float, float);
397 float ynf(int, float);
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.
404 float gammaf_r(float, int *);
405 float lgammaf_r(float, int *);
408 * float version of IEEE Test Vector
410 float significandf(float);
411 #endif /* __BSD_VISIBLE */
414 * long double versions of ISO/POSIX math functions
416 #if __ISO_C_VISIBLE >= 1999
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);
428 long double copysignl(long double, long double);
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);
438 long double fabsl(long double);
439 long double fdiml(long double, long double);
441 long double floorl(long double);
442 long double fmal(long double, long double, long double);
444 long double fmaxl(long double, long double) __pure2;
445 long double fminl(long double, long double) __pure2;
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 int ilogbl(long double);
451 long double ldexpl(long double, int);
452 long double lgammal(long double);
453 long long llrintl(long double);
454 long long llroundl(long double);
455 long double log10l(long double);
456 long double log1pl(long double);
457 long double log2l(long double);
458 long double logbl(long double);
459 long double logl(long double);
460 long lrintl(long double);
461 long lroundl(long double);
462 long double modfl(long double, long double *);
463 long double nanl(const char *);
464 long double nearbyintl(long double);
465 long double nextafterl(long double, long double);
466 double nexttoward(double, long double);
467 float nexttowardf(float, long double);
468 long double nexttowardl(long double, long double);
469 long double powl(long double, long double);
470 long double remainderl(long double, long double);
471 long double remquol(long double, long double, int *);
472 long double rintl(long double);
473 long double roundl(long double);
474 long double scalblnl(long double, long);
475 long double scalbnl(long double, int);
476 long double sinhl(long double);
477 long double sinl(long double);
478 long double sqrtl(long double);
479 long double tanhl(long double);
480 long double tanl(long double);
481 long double tgammal(long double);
482 long double truncl(long double);
485 #endif /* __ISO_C_VISIBLE >= 1999 */
488 #endif /* !_MATH_H_ */