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_inff()
59 #define NAN __builtin_nanf("")
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 #define FP_FAST_FMAF 1
74 #define FP_FAST_FMAL 1
77 /* Symbolic constants to classify floating point numbers. */
78 #define FP_INFINITE 0x01
80 #define FP_NORMAL 0x04
81 #define FP_SUBNORMAL 0x08
83 #define fpclassify(x) \
84 ((sizeof (x) == sizeof (float)) ? __fpclassifyf(x) \
85 : (sizeof (x) == sizeof (double)) ? __fpclassifyd(x) \
89 ((sizeof (x) == sizeof (float)) ? __isfinitef(x) \
90 : (sizeof (x) == sizeof (double)) ? __isfinite(x) \
93 ((sizeof (x) == sizeof (float)) ? __isinff(x) \
94 : (sizeof (x) == sizeof (double)) ? isinf(x) \
97 ((sizeof (x) == sizeof (float)) ? __isnanf(x) \
98 : (sizeof (x) == sizeof (double)) ? isnan(x) \
100 #define isnormal(x) \
101 ((sizeof (x) == sizeof (float)) ? __isnormalf(x) \
102 : (sizeof (x) == sizeof (double)) ? __isnormal(x) \
105 #ifdef __MATH_BUILTIN_RELOPS
106 #define isgreater(x, y) __builtin_isgreater((x), (y))
107 #define isgreaterequal(x, y) __builtin_isgreaterequal((x), (y))
108 #define isless(x, y) __builtin_isless((x), (y))
109 #define islessequal(x, y) __builtin_islessequal((x), (y))
110 #define islessgreater(x, y) __builtin_islessgreater((x), (y))
111 #define isunordered(x, y) __builtin_isunordered((x), (y))
113 #define isgreater(x, y) (!isunordered((x), (y)) && (x) > (y))
114 #define isgreaterequal(x, y) (!isunordered((x), (y)) && (x) >= (y))
115 #define isless(x, y) (!isunordered((x), (y)) && (x) < (y))
116 #define islessequal(x, y) (!isunordered((x), (y)) && (x) <= (y))
117 #define islessgreater(x, y) (!isunordered((x), (y)) && \
118 ((x) > (y) || (y) > (x)))
119 #define isunordered(x, y) (isnan(x) || isnan(y))
120 #endif /* __MATH_BUILTIN_RELOPS */
123 ((sizeof (x) == sizeof (float)) ? __signbitf(x) \
124 : (sizeof (x) == sizeof (double)) ? __signbit(x) \
127 typedef __double_t double_t;
128 typedef __float_t float_t;
129 #endif /* __ISO_C_VISIBLE >= 1999 */
134 #if __BSD_VISIBLE || __XSI_VISIBLE
135 #define M_E 2.7182818284590452354 /* e */
136 #define M_LOG2E 1.4426950408889634074 /* log 2e */
137 #define M_LOG10E 0.43429448190325182765 /* log 10e */
138 #define M_LN2 0.69314718055994530942 /* log e2 */
139 #define M_LN10 2.30258509299404568402 /* log e10 */
140 #define M_PI 3.14159265358979323846 /* pi */
141 #define M_PI_2 1.57079632679489661923 /* pi/2 */
142 #define M_PI_4 0.78539816339744830962 /* pi/4 */
143 #define M_1_PI 0.31830988618379067154 /* 1/pi */
144 #define M_2_PI 0.63661977236758134308 /* 2/pi */
145 #define M_2_SQRTPI 1.12837916709551257390 /* 2/sqrt(pi) */
146 #define M_SQRT2 1.41421356237309504880 /* sqrt(2) */
147 #define M_SQRT1_2 0.70710678118654752440 /* 1/sqrt(2) */
149 #define MAXFLOAT ((float)3.40282346638528860e+38)
151 #endif /* __BSD_VISIBLE || __XSI_VISIBLE */
155 /* Old value from 4.4BSD-Lite math.h; this is probably better. */
156 #define HUGE HUGE_VAL
158 #define HUGE MAXFLOAT
160 #endif /* __BSD_VISIBLE */
163 * Most of these functions depend on the rounding mode and have the side
164 * effect of raising floating-point exceptions, so they are not declared
165 * as __pure2. In C99, FENV_ACCESS affects the purity of these functions.
171 int __fpclassifyd(double) __pure2;
172 int __fpclassifyf(float) __pure2;
173 int __fpclassifyl(long double) __pure2;
174 int __isfinitef(float) __pure2;
175 int __isfinite(double) __pure2;
176 int __isfinitel(long double) __pure2;
177 int __isinff(float) __pure2;
178 int __isinfl(long double) __pure2;
179 int __isnanf(float) __pure2;
180 int __isnanl(long double) __pure2;
181 int __isnormalf(float) __pure2;
182 int __isnormal(double) __pure2;
183 int __isnormall(long double) __pure2;
184 int __signbit(double) __pure2;
185 int __signbitf(float) __pure2;
186 int __signbitl(long double) __pure2;
191 double atan2(double, double);
201 double frexp(double, int *); /* fundamentally !__pure2 */
202 double ldexp(double, int);
204 double log10(double);
205 double modf(double, double *); /* fundamentally !__pure2 */
207 double pow(double, double);
211 double fabs(double) __pure2;
212 double floor(double);
213 double fmod(double, double);
216 * These functions are not in C90.
218 #if __BSD_VISIBLE || __ISO_C_VISIBLE >= 1999 || __XSI_VISIBLE
219 double acosh(double);
220 double asinh(double);
221 double atanh(double);
226 double expm1(double);
227 double fma(double, double, double);
228 double hypot(double, double);
229 int ilogb(double) __pure2;
230 int (isinf)(double) __pure2;
231 int (isnan)(double) __pure2;
232 double lgamma(double);
233 long long llrint(double);
234 long long llround(double);
235 double log1p(double);
240 double nan(const char *) __pure2;
241 double nextafter(double, double);
242 double remainder(double, double);
243 double remquo(double, double, int *);
245 #endif /* __BSD_VISIBLE || __ISO_C_VISIBLE >= 1999 || __XSI_VISIBLE */
247 #if __BSD_VISIBLE || __XSI_VISIBLE
250 double jn(int, double);
253 double yn(int, double);
255 #if __XSI_VISIBLE <= 500 || __BSD_VISIBLE
256 double gamma(double);
259 #if __XSI_VISIBLE <= 600 || __BSD_VISIBLE
260 double scalb(double, double);
262 #endif /* __BSD_VISIBLE || __XSI_VISIBLE */
264 #if __BSD_VISIBLE || __ISO_C_VISIBLE >= 1999
265 double copysign(double, double) __pure2;
266 double fdim(double, double);
267 double fmax(double, double) __pure2;
268 double fmin(double, double) __pure2;
269 double nearbyint(double);
270 double round(double);
271 double scalbln(double, long);
272 double scalbn(double, int);
273 double tgamma(double);
274 double trunc(double);
278 * BSD math library entry points
281 double drem(double, double);
282 int finite(double) __pure2;
283 int isnanf(float) __pure2;
286 * Reentrant version of gamma & lgamma; passes signgam back by reference
287 * as the second argument; user must allocate space for signgam.
289 double gamma_r(double, int *);
290 double lgamma_r(double, int *);
295 double significand(double);
296 #endif /* __BSD_VISIBLE */
298 /* float versions of ANSI/POSIX functions */
299 #if __ISO_C_VISIBLE >= 1999
303 float atan2f(float, float);
315 float frexpf(float, int *); /* fundamentally !__pure2 */
316 int ilogbf(float) __pure2;
317 float ldexpf(float, int);
322 float modff(float, float *); /* fundamentally !__pure2 */
324 float powf(float, float);
328 float fabsf(float) __pure2;
330 float fmodf(float, float);
335 float hypotf(float, float);
336 float lgammaf(float);
337 float tgammaf(float);
344 float copysignf(float, float) __pure2;
345 long long llrintf(float);
346 long long llroundf(float);
349 float nanf(const char *) __pure2;
350 float nearbyintf(float);
351 float nextafterf(float, float);
352 float remainderf(float, float);
353 float remquof(float, float, int *);
355 float scalblnf(float, long);
356 float scalbnf(float, int);
359 float fdimf(float, float);
360 float fmaf(float, float, float);
361 float fmaxf(float, float) __pure2;
362 float fminf(float, float) __pure2;
366 * float versions of BSD math library entry points
369 float dremf(float, float);
370 int finitef(float) __pure2;
374 float jnf(int, float);
375 float scalbf(float, float);
378 float ynf(int, float);
381 * Float versions of reentrant version of gamma & lgamma; passes
382 * signgam back by reference as the second argument; user must
383 * allocate space for signgam.
385 float gammaf_r(float, int *);
386 float lgammaf_r(float, int *);
389 * float version of IEEE Test Vector
391 float significandf(float);
392 #endif /* __BSD_VISIBLE */
395 * long double versions of ISO/POSIX math functions
397 #if __ISO_C_VISIBLE >= 1999
398 long double acosl(long double);
399 long double asinl(long double);
400 long double atan2l(long double, long double);
401 long double atanl(long double);
402 long double cbrtl(long double);
403 long double ceill(long double);
404 long double copysignl(long double, long double) __pure2;
405 long double cosl(long double);
406 long double exp2l(long double);
407 long double fabsl(long double) __pure2;
408 long double fdiml(long double, long double);
409 long double floorl(long double);
410 long double fmal(long double, long double, long double);
411 long double fmaxl(long double, long double) __pure2;
412 long double fminl(long double, long double) __pure2;
413 long double fmodl(long double, long double);
414 long double frexpl(long double value, int *); /* fundamentally !__pure2 */
415 long double hypotl(long double, long double);
416 int ilogbl(long double) __pure2;
417 long double ldexpl(long double, int);
418 long long llrintl(long double);
419 long long llroundl(long double);
420 long double logbl(long double);
421 long lrintl(long double);
422 long lroundl(long double);
423 long double modfl(long double, long double *); /* fundamentally !__pure2 */
424 long double nanl(const char *) __pure2;
425 long double nearbyintl(long double);
426 long double nextafterl(long double, long double);
427 double nexttoward(double, long double);
428 float nexttowardf(float, long double);
429 long double nexttowardl(long double, long double);
430 long double remainderl(long double, long double);
431 long double remquol(long double, long double, int *);
432 long double rintl(long double);
433 long double roundl(long double);
434 long double scalblnl(long double, long);
435 long double scalbnl(long double, int);
436 long double sinl(long double);
437 long double sqrtl(long double);
438 long double tanl(long double);
439 long double truncl(long double);
441 #endif /* __ISO_C_VISIBLE >= 1999 */
444 #endif /* !_MATH_H_ */
446 /* separate header for cmath */
447 #ifndef _MATH_EXTRA_H_
448 #if __ISO_C_VISIBLE >= 1999
449 #if _DECLARE_C99_LDBL_MATH
451 #define _MATH_EXTRA_H_
454 * extra long double versions of math functions for C99 and cmath
458 long double acoshl(long double);
459 long double asinhl(long double);
460 long double atanhl(long double);
461 long double coshl(long double);
462 long double erfcl(long double);
463 long double erfl(long double);
464 long double expl(long double);
465 long double expm1l(long double);
466 long double lgammal(long double);
467 long double log10l(long double);
468 long double log1pl(long double);
469 long double log2l(long double);
470 long double logl(long double);
471 long double powl(long double, long double);
472 long double sinhl(long double);
473 long double tanhl(long double);
474 long double tgammal(long double);
478 #endif /* !_DECLARE_C99_LDBL_MATH */
479 #endif /* __ISO_C_VISIBLE >= 1999 */
480 #endif /* !_MATH_EXTRA_H_ */