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
14 * $FreeBSD: src/lib/msun/src/math.h,v 1.61 2005/04/16 21:12:47 das Exp $
20 #include <sys/cdefs.h>
21 #include <sys/types.h>
29 extern const union __infinity_un {
30 unsigned char __uc[8];
34 extern const union __nan_un {
35 unsigned char __uc[sizeof(float)];
39 /* #if __GNUC_PREREQ__(3, 3) || (defined(__INTEL_COMPILER) && __INTEL_COMPILER >= 800) */
41 #define __MATH_BUILTIN_CONSTANTS
44 /* #if __GNUC_PREREQ__(3, 0) && !defined(__INTEL_COMPILER) */
46 #define __MATH_BUILTIN_RELOPS
49 /* #ifdef __MATH_BUILTIN_CONSTANTS */
51 #define HUGE_VAL __builtin_huge_val()
53 #define HUGE_VAL (__infinity.__ud)
56 /* #if __ISO_C_VISIBLE >= 1999 */
58 #define FP_ILOGB0 (-__INT_MAX)
59 #define FP_ILOGBNAN __INT_MAX
61 #define FP_ILOGB0 (-INT_MAX)
62 #define FP_ILOGBNAN INT_MAX
65 #ifdef __MATH_BUILTIN_CONSTANTS
66 #define HUGE_VALF __builtin_huge_valf()
67 #define HUGE_VALL __builtin_huge_vall()
68 #define INFINITY __builtin_inf()
69 #define NAN __builtin_nan("")
71 #define HUGE_VALF (float)HUGE_VAL
72 #define HUGE_VALL (long double)HUGE_VAL
73 #define INFINITY HUGE_VALF
74 #define NAN (__nan.__uf)
75 #endif /* __MATH_BUILTIN_CONSTANTS */
78 #define MATH_ERREXCEPT 2
79 #define math_errhandling MATH_ERREXCEPT
81 /* XXX We need a <machine/math.h>. */
82 #if defined(__ia64__) || defined(__sparc64__)
90 /* Symbolic constants to classify floating point numbers. */
91 #define FP_INFINITE 0x01
93 #define FP_NORMAL 0x04
94 #define FP_SUBNORMAL 0x08
96 #define fpclassify(x) \
97 ((sizeof (x) == sizeof (float)) ? __fpclassifyf(x) \
98 : (sizeof (x) == sizeof (double)) ? __fpclassifyd(x) \
101 #define isfinite(x) \
102 ((sizeof (x) == sizeof (float)) ? __isfinitef(x) \
103 : (sizeof (x) == sizeof (double)) ? __isfinite(x) \
106 ((sizeof (x) == sizeof (float)) ? __isinff(x) \
107 : (sizeof (x) == sizeof (double)) ? __isinf(x) \
110 ((sizeof (x) == sizeof (float)) ? isnanf(x) \
111 : (sizeof (x) == sizeof (double)) ? isnan(x) \
113 #define isnormal(x) \
114 ((sizeof (x) == sizeof (float)) ? __isnormalf(x) \
115 : (sizeof (x) == sizeof (double)) ? __isnormal(x) \
118 #ifdef __MATH_BUILTIN_RELOPS
119 #define isgreater(x, y) __builtin_isgreater((x), (y))
120 #define isgreaterequal(x, y) __builtin_isgreaterequal((x), (y))
121 #define isless(x, y) __builtin_isless((x), (y))
122 #define islessequal(x, y) __builtin_islessequal((x), (y))
123 #define islessgreater(x, y) __builtin_islessgreater((x), (y))
124 #define isunordered(x, y) __builtin_isunordered((x), (y))
126 #define isgreater(x, y) (!isunordered((x), (y)) && (x) > (y))
127 #define isgreaterequal(x, y) (!isunordered((x), (y)) && (x) >= (y))
128 #define isless(x, y) (!isunordered((x), (y)) && (x) < (y))
129 #define islessequal(x, y) (!isunordered((x), (y)) && (x) <= (y))
130 #define islessgreater(x, y) (!isunordered((x), (y)) && \
131 ((x) > (y) || (y) > (x)))
132 #define isunordered(x, y) (isnan(x) || isnan(y))
133 #endif /* __MATH_BUILTIN_RELOPS */
136 ((sizeof (x) == sizeof (float)) ? __signbitf(x) \
137 : (sizeof (x) == sizeof (double)) ? __signbit(x) \
141 typedef __double_t double_t;
142 typedef __float_t float_t;
144 /* #endif */ /* __ISO_C_VISIBLE >= 1999 */
149 /* #if __BSD_VISIBLE || __XSI_VISIBLE */
150 #define M_E 2.7182818284590452354 /* e */
151 #define M_LOG2E 1.4426950408889634074 /* log 2e */
152 #define M_LOG10E 0.43429448190325182765 /* log 10e */
153 #define M_LN2 0.69314718055994530942 /* log e2 */
154 #define M_LN10 2.30258509299404568402 /* log e10 */
155 #define M_PI 3.14159265358979323846 /* pi */
156 #define M_PI_2 1.57079632679489661923 /* pi/2 */
157 #define M_PI_4 0.78539816339744830962 /* pi/4 */
158 #define M_1_PI 0.31830988618379067154 /* 1/pi */
159 #define M_2_PI 0.63661977236758134308 /* 2/pi */
160 #define M_2_SQRTPI 1.12837916709551257390 /* 2/sqrt(pi) */
161 #define M_SQRT2 1.41421356237309504880 /* sqrt(2) */
162 #define M_SQRT1_2 0.70710678118654752440 /* 1/sqrt(2) */
164 #define MAXFLOAT ((float)3.40282346638528860e+38)
166 /* #endif */ /* __BSD_VISIBLE || __XSI_VISIBLE */
170 /* Old value from 4.4BSD-Lite math.h; this is probably better. */
171 #define HUGE HUGE_VAL
173 #define HUGE MAXFLOAT
175 #endif /* __BSD_VISIBLE */
178 * Most of these functions depend on the rounding mode and have the side
179 * effect of raising floating-point exceptions, so they are not declared
180 * as __pure2. In C99, FENV_ACCESS affects the purity of these functions.
186 int __fpclassifyd(double) __pure2;
187 int __fpclassifyf(float) __pure2;
188 int __fpclassifyl(long double) __pure2;
189 int __isfinitef(float) __pure2;
190 int __isfinite(double) __pure2;
191 int __isfinitel(long double) __pure2;
192 int __isinff(float) __pure2;
193 int __isinf(double) __pure2;
194 int __isinfl(long double) __pure2;
195 int __isnanl(long double) __pure2;
196 int __isnormalf(float) __pure2;
197 int __isnormal(double) __pure2;
198 int __isnormall(long double) __pure2;
199 int __signbit(double) __pure2;
200 int __signbitf(float) __pure2;
201 int __signbitl(long double) __pure2;
206 double atan2(double, double);
216 double frexp(double, int *); /* fundamentally !__pure2 */
217 double ldexp(double, int);
219 double log10(double);
220 double modf(double, double *); /* fundamentally !__pure2 */
222 double pow(double, double);
226 double fabs(double) __pure2;
227 double floor(double);
228 double fmod(double, double);
231 * These functions are not in C90.
233 /* #if __BSD_VISIBLE || __ISO_C_VISIBLE >= 1999 || __XSI_VISIBLE */
234 double acosh(double);
235 double asinh(double);
236 double atanh(double);
241 double expm1(double);
242 double fma(double, double, double);
243 double hypot(double, double);
244 int ilogb(double) __pure2;
245 /* int (isinf)(double) __pure2; */
246 int (isnan)(double) __pure2;
247 double lgamma(double);
248 long long llrint(double);
249 long long llround(double);
250 double log1p(double);
254 double nextafter(double, double);
255 double remainder(double, double);
256 double remquo(double, double, int *);
258 /* #endif */ /* __BSD_VISIBLE || __ISO_C_VISIBLE >= 1999 || __XSI_VISIBLE */
260 /* #if __BSD_VISIBLE || __XSI_VISIBLE */
263 double jn(int, double);
264 double scalb(double, double);
267 double yn(int, double);
269 /* #if __XSI_VISIBLE <= 500 || __BSD_VISIBLE */
270 double gamma(double);
272 /* #endif */ /* __BSD_VISIBLE || __XSI_VISIBLE */
274 /* #if __BSD_VISIBLE || __ISO_C_VISIBLE >= 1999 */
275 double copysign(double, double) __pure2;
276 double fdim(double, double);
277 double fmax(double, double) __pure2;
278 double fmin(double, double) __pure2;
279 double nearbyint(double);
280 double round(double);
281 double scalbln(double, long);
282 double scalbn(double, int);
283 double tgamma(double);
284 double trunc(double);
288 * BSD math library entry points
290 /* #if __BSD_VISIBLE */
291 double drem(double, double);
292 int finite(double) __pure2;
293 int isnanf(float) __pure2;
296 * Reentrant version of gamma & lgamma; passes signgam back by reference
297 * as the second argument; user must allocate space for signgam.
299 double gamma_r(double, int *);
300 double lgamma_r(double, int *);
305 double significand(double);
306 /* #endif */ /* __BSD_VISIBLE */
308 /* float versions of ANSI/POSIX functions */
309 /*#if __ISO_C_VISIBLE >= 1999 */
313 float atan2f(float, float);
325 float frexpf(float, int *); /* fundamentally !__pure2 */
326 int ilogbf(float) __pure2;
327 float ldexpf(float, int);
331 float modff(float, float *); /* fundamentally !__pure2 */
333 float powf(float, float);
337 float fabsf(float) __pure2;
339 float fmodf(float, float);
344 float hypotf(float, float);
345 float lgammaf(float);
352 float copysignf(float, float) __pure2;
353 long long llrintf(float);
354 long long llroundf(float);
357 float nearbyintf(float);
358 float nextafterf(float, float);
359 float remainderf(float, float);
360 float remquof(float, float, int *);
362 float scalblnf(float, long);
363 float scalbnf(float, int);
366 float fdimf(float, float);
367 float fmaf(float, float, float);
368 float fmaxf(float, float) __pure2;
369 float fminf(float, float) __pure2;
373 * float versions of BSD math library entry points
375 /* #if __BSD_VISIBLE */
376 float dremf(float, float);
377 int finitef(float) __pure2;
381 float jnf(int, float);
382 float scalbf(float, float);
385 float ynf(int, float);
388 * Float versions of reentrant version of gamma & lgamma; passes
389 * signgam back by reference as the second argument; user must
390 * allocate space for signgam.
392 float gammaf_r(float, int *);
393 float lgammaf_r(float, int *);
396 * float version of IEEE Test Vector
398 float significandf(float);
399 /* #endif */ /* __BSD_VISIBLE */
402 * long double versions of ISO/POSIX math functions
404 /* #if __ISO_C_VISIBLE >= 1999 */
406 long double acoshl(long double);
407 long double acosl(long double);
408 long double asinhl(long double);
409 long double asinl(long double);
410 long double atan2l(long double, long double);
411 long double atanhl(long double);
412 long double atanl(long double);
413 long double cbrtl(long double);
415 long double ceill(long double);
416 long double copysignl(long double, long double) __pure2;
418 long double coshl(long double);
419 long double cosl(long double);
420 long double erfcl(long double);
421 long double erfl(long double);
422 long double exp2l(long double);
423 long double expl(long double);
424 long double expm1l(long double);
426 long double fabsl(long double) __pure2;
427 long double fdiml(long double, long double);
428 long double floorl(long double);
429 long double fmal(long double, long double, long double);
430 long double fmaxl(long double, long double) __pure2;
431 long double fminl(long double, long double) __pure2;
433 long double fmodl(long double, long double);
435 long double frexpl(long double value, int *); /* fundamentally !__pure2 */
437 long double hypotl(long double, long double);
439 int ilogbl(long double) __pure2;
440 long double ldexpl(long double, int);
442 long double lgammal(long double);
443 long long llrintl(long double);
445 long long llroundl(long double);
447 long double log10l(long double);
448 long double log1pl(long double);
449 long double log2l(long double);
450 long double logbl(long double);
451 long double logl(long double);
452 long lrintl(long double);
454 long lroundl(long double);
456 long double modfl(long double, long double *); /* fundamentally !__pure2 */
457 long double nanl(const char *) __pure2;
458 long double nearbyintl(long double);
460 long double nextafterl(long double, long double);
461 double nexttoward(double, long double);
462 float nexttowardf(float, long double);
463 long double nexttowardl(long double, long double);
465 long double powl(long double, long double);
466 long double remainderl(long double, long double);
467 long double remquol(long double, long double, int *);
468 long double rintl(long double);
470 long double roundl(long double);
471 long double scalblnl(long double, long);
472 long double scalbnl(long double, int);
474 long double sinhl(long double);
475 long double sinl(long double);
476 long double sqrtl(long double);
477 long double tanhl(long double);
478 long double tanl(long double);
479 long double tgammal(long double);
481 long double truncl(long double);
483 /* #endif */ /* __ISO_C_VISIBLE >= 1999 */
486 #endif /* !_MATH_H_ */