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 __GNUC_PREREQ__(3, 3) || (defined(__INTEL_COMPILER) && __INTEL_COMPILER >= 800)
38 #define __MATH_BUILTIN_CONSTANTS
41 #if __GNUC_PREREQ__(3, 0) && !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 MATH_ERREXCEPT
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
179 #define X_TLOSS 1.41484755040568800000e+16 /* pi*2**52 */
188 #endif /* __BSD_VISIBLE */
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.)
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;
220 double atan2(double, double);
230 double frexp(double, int *); /* fundamentally !__pure2 */
231 double ldexp(double, int);
233 double log10(double);
234 double modf(double, double *); /* fundamentally !__pure2 */
236 double pow(double, double);
241 double floor(double);
242 double fmod(double, double);
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.
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;
254 double erfc(double) __pure2;
255 double expm1(double) __pure2;
256 double hypot(double, 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;
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 */
272 #if __BSD_VISIBLE || __XSI_VISIBLE
275 double jn(int, double);
276 double scalb(double, double);
279 double yn(int, double);
281 #if __XSI_VISIBLE <= 500 || __BSD_VISIBLE
282 double gamma(double);
284 #endif /* __BSD_VISIBLE || __XSI_VISIBLE */
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);
300 * BSD math library entry points
303 double drem(double, double);
304 int finite(double) __pure2;
305 int isnanf(float) __pure2;
308 * Reentrant version of gamma & lgamma; passes signgam back by reference
309 * as the second argument; user must allocate space for signgam.
311 double gamma_r(double, int *);
312 double lgamma_r(double, int *);
317 double significand(double);
320 int matherr(struct exception *);
322 #endif /* __BSD_VISIBLE */
324 /* float versions of ANSI/POSIX functions */
325 #if __ISO_C_VISIBLE >= 1999
329 float atan2f(float, float);
339 float expm1f(float) __pure2;
340 float frexpf(float, int *); /* fundamentally !__pure2 */
342 float ldexpf(float, int);
344 float log1pf(float) __pure2;
346 float modff(float, float *); /* fundamentally !__pure2 */
348 float powf(float, float);
354 float fmodf(float, float);
358 float erfcf(float) __pure2;
359 float hypotf(float, float) __pure2;
360 float lgammaf(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);
372 float nearbyintf(float) __pure2;
373 float nextafterf(float, float);
374 float remainderf(float, float);
376 float scalblnf(float, long);
377 float scalbnf(float, int);
380 float fdimf(float, float);
381 float fmaxf(float, float) __pure2;
382 float fminf(float, float) __pure2;
386 * float versions of BSD math library entry points
389 float dremf(float, float);
390 int finitef(float) __pure2;
394 float jnf(int, float);
395 float scalbf(float, float);
398 float ynf(int, float);
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.
405 float gammaf_r(float, int *);
406 float lgammaf_r(float, int *);
409 * float version of IEEE Test Vector
411 float significandf(float);
412 #endif /* __BSD_VISIBLE */
415 * long double versions of ISO/POSIX math functions
417 #if __ISO_C_VISIBLE >= 1999
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);
428 long double ceill(long double);
429 long double copysignl(long double, long double);
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);
439 long double fabsl(long double);
440 long double fdiml(long double, long double);
441 long double floorl(long double);
443 long double fmal(long double, long double, long double);
445 long double fmaxl(long double, long double) __pure2;
446 long double fminl(long double, long double) __pure2;
448 long double fmodl(long double, long double);
449 long double frexpl(long double value, int *);
450 long double hypotl(long double, long double);
452 int ilogbl(long double);
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);
488 #endif /* __ISO_C_VISIBLE >= 1999 */
491 #endif /* !_MATH_H_ */