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: head/lib/msun/src/math.h 238722 2012-07-23 19:13:55Z kargl $
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
73 /* Symbolic constants to classify floating point numbers. */
74 #define FP_INFINITE 0x01
76 #define FP_NORMAL 0x04
77 #define FP_SUBNORMAL 0x08
79 #define fpclassify(x) \
80 ((sizeof (x) == sizeof (float)) ? __fpclassifyf(x) \
81 : (sizeof (x) == sizeof (double)) ? __fpclassifyd(x) \
85 ((sizeof (x) == sizeof (float)) ? __isfinitef(x) \
86 : (sizeof (x) == sizeof (double)) ? __isfinite(x) \
89 ((sizeof (x) == sizeof (float)) ? __isinff(x) \
90 : (sizeof (x) == sizeof (double)) ? isinf(x) \
93 ((sizeof (x) == sizeof (float)) ? __isnanf(x) \
94 : (sizeof (x) == sizeof (double)) ? isnan(x) \
97 ((sizeof (x) == sizeof (float)) ? __isnormalf(x) \
98 : (sizeof (x) == sizeof (double)) ? __isnormal(x) \
101 #ifdef __MATH_BUILTIN_RELOPS
102 #define isgreater(x, y) __builtin_isgreater((x), (y))
103 #define isgreaterequal(x, y) __builtin_isgreaterequal((x), (y))
104 #define isless(x, y) __builtin_isless((x), (y))
105 #define islessequal(x, y) __builtin_islessequal((x), (y))
106 #define islessgreater(x, y) __builtin_islessgreater((x), (y))
107 #define isunordered(x, y) __builtin_isunordered((x), (y))
109 #define isgreater(x, y) (!isunordered((x), (y)) && (x) > (y))
110 #define isgreaterequal(x, y) (!isunordered((x), (y)) && (x) >= (y))
111 #define isless(x, y) (!isunordered((x), (y)) && (x) < (y))
112 #define islessequal(x, y) (!isunordered((x), (y)) && (x) <= (y))
113 #define islessgreater(x, y) (!isunordered((x), (y)) && \
114 ((x) > (y) || (y) > (x)))
115 #define isunordered(x, y) (isnan(x) || isnan(y))
116 #endif /* __MATH_BUILTIN_RELOPS */
119 ((sizeof (x) == sizeof (float)) ? __signbitf(x) \
120 : (sizeof (x) == sizeof (double)) ? __signbit(x) \
124 typedef double double_t;
125 typedef float float_t;
127 typedef long double double_t;
128 typedef long double float_t;
129 #endif /* __LP64__ */
130 #endif /* __ISO_C_VISIBLE >= 1999 */
135 #if __BSD_VISIBLE || __XSI_VISIBLE
136 #define M_E 2.7182818284590452354 /* e */
137 #define M_LOG2E 1.4426950408889634074 /* log 2e */
138 #define M_LOG10E 0.43429448190325182765 /* log 10e */
139 #define M_LN2 0.69314718055994530942 /* log e2 */
140 #define M_LN10 2.30258509299404568402 /* log e10 */
141 #define M_PI 3.14159265358979323846 /* pi */
142 #define M_PI_2 1.57079632679489661923 /* pi/2 */
143 #define M_PI_4 0.78539816339744830962 /* pi/4 */
144 #define M_1_PI 0.31830988618379067154 /* 1/pi */
145 #define M_2_PI 0.63661977236758134308 /* 2/pi */
146 #define M_2_SQRTPI 1.12837916709551257390 /* 2/sqrt(pi) */
147 #define M_SQRT2 1.41421356237309504880 /* sqrt(2) */
148 #define M_SQRT1_2 0.70710678118654752440 /* 1/sqrt(2) */
150 #define MAXFLOAT ((float)3.40282346638528860e+38)
152 #endif /* __BSD_VISIBLE || __XSI_VISIBLE */
156 /* Old value from 4.4BSD-Lite math.h; this is probably better. */
157 #define HUGE HUGE_VAL
159 #define HUGE MAXFLOAT
161 #endif /* __BSD_VISIBLE */
164 * Most of these functions depend on the rounding mode and have the side
165 * effect of raising floating-point exceptions, so they are not declared
166 * as __pure2. In C99, FENV_ACCESS affects the purity of these functions.
172 int __fpclassifyd(double) __pure2;
173 int __fpclassifyf(float) __pure2;
174 int __fpclassifyl(long double) __pure2;
175 int __isfinitef(float) __pure2;
176 int __isfinite(double) __pure2;
177 int __isfinitel(long double) __pure2;
178 int __isinff(float) __pure2;
179 int __isinfl(long double) __pure2;
180 int __isnanf(float) __pure2;
181 int __isnanl(long double) __pure2;
182 int __isnormalf(float) __pure2;
183 int __isnormal(double) __pure2;
184 int __isnormall(long double) __pure2;
185 int __signbit(double) __pure2;
186 int __signbitf(float) __pure2;
187 int __signbitl(long double) __pure2;
192 double atan2(double, double);
202 double frexp(double, int *); /* fundamentally !__pure2 */
203 double ldexp(double, int);
205 double log10(double);
206 double modf(double, double *); /* fundamentally !__pure2 */
208 double pow(double, double);
212 double fabs(double) __pure2;
213 double floor(double);
214 double fmod(double, double);
217 * These functions are not in C90.
219 #if __BSD_VISIBLE || __ISO_C_VISIBLE >= 1999 || __XSI_VISIBLE
220 double acosh(double);
221 double asinh(double);
222 double atanh(double);
227 double expm1(double);
228 double fma(double, double, double);
229 double hypot(double, double);
230 int ilogb(double) __pure2;
231 int (isinf)(double) __pure2;
232 int (isnan)(double) __pure2;
233 double lgamma(double);
234 long long llrint(double);
235 long long llround(double);
236 double log1p(double);
241 double nan(const char *) __pure2;
242 double nextafter(double, double);
243 double remainder(double, double);
244 double remquo(double, double, int *);
246 #endif /* __BSD_VISIBLE || __ISO_C_VISIBLE >= 1999 || __XSI_VISIBLE */
248 #if __BSD_VISIBLE || __XSI_VISIBLE
251 double jn(int, double);
254 double yn(int, double);
256 #if __XSI_VISIBLE <= 500 || __BSD_VISIBLE
257 double gamma(double);
260 #if __XSI_VISIBLE <= 600 || __BSD_VISIBLE
261 double scalb(double, double);
263 #endif /* __BSD_VISIBLE || __XSI_VISIBLE */
265 #if __BSD_VISIBLE || __ISO_C_VISIBLE >= 1999
266 double copysign(double, double) __pure2;
267 double fdim(double, double);
268 double fmax(double, double) __pure2;
269 double fmin(double, double) __pure2;
270 double nearbyint(double);
271 double round(double);
272 double scalbln(double, long);
273 double scalbn(double, int);
274 double tgamma(double);
275 double trunc(double);
279 * BSD math library entry points
282 double drem(double, double);
283 int finite(double) __pure2;
284 int isnanf(float) __pure2;
287 * Reentrant version of gamma & lgamma; passes signgam back by reference
288 * as the second argument; user must allocate space for signgam.
290 double gamma_r(double, int *);
291 double lgamma_r(double, int *);
296 double significand(double);
297 #endif /* __BSD_VISIBLE */
299 /* float versions of ANSI/POSIX functions */
300 #if __ISO_C_VISIBLE >= 1999
304 float atan2f(float, float);
316 float frexpf(float, int *); /* fundamentally !__pure2 */
317 int ilogbf(float) __pure2;
318 float ldexpf(float, int);
323 float modff(float, float *); /* fundamentally !__pure2 */
325 float powf(float, float);
329 float fabsf(float) __pure2;
331 float fmodf(float, float);
336 float hypotf(float, float);
337 float lgammaf(float);
338 float tgammaf(float);
345 float copysignf(float, float) __pure2;
346 long long llrintf(float);
347 long long llroundf(float);
350 float nanf(const char *) __pure2;
351 float nearbyintf(float);
352 float nextafterf(float, float);
353 float remainderf(float, float);
354 float remquof(float, float, int *);
356 float scalblnf(float, long);
357 float scalbnf(float, int);
360 float fdimf(float, float);
361 float fmaf(float, float, float);
362 float fmaxf(float, float) __pure2;
363 float fminf(float, float) __pure2;
367 * float versions of BSD math library entry points
370 float dremf(float, float);
371 int finitef(float) __pure2;
375 float jnf(int, float);
376 float scalbf(float, float);
379 float ynf(int, float);
382 * Float versions of reentrant version of gamma & lgamma; passes
383 * signgam back by reference as the second argument; user must
384 * allocate space for signgam.
386 float gammaf_r(float, int *);
387 float lgammaf_r(float, int *);
390 * float version of IEEE Test Vector
392 float significandf(float);
393 #endif /* __BSD_VISIBLE */
396 * long double versions of ISO/POSIX math functions
398 #if __ISO_C_VISIBLE >= 1999
399 long double acosl(long double);
400 long double asinl(long double);
401 long double atan2l(long double, long double);
402 long double atanl(long double);
403 long double cbrtl(long double);
404 long double ceill(long double);
405 long double copysignl(long double, long double) __pure2;
406 long double cosl(long double);
407 long double exp2l(long double);
408 long double expl(long double);
409 long double fabsl(long double) __pure2;
410 long double fdiml(long double, long double);
411 long double floorl(long double);
412 long double fmal(long double, long double, long double);
413 long double fmaxl(long double, long double) __pure2;
414 long double fminl(long double, long double) __pure2;
415 long double fmodl(long double, long double);
416 long double frexpl(long double value, int *); /* fundamentally !__pure2 */
417 long double hypotl(long double, long double);
418 int ilogbl(long double) __pure2;
419 long double ldexpl(long double, int);
420 long long llrintl(long double);
421 long long llroundl(long double);
422 long double logbl(long double);
423 long lrintl(long double);
424 long lroundl(long double);
425 long double modfl(long double, long double *); /* fundamentally !__pure2 */
426 long double nanl(const char *) __pure2;
427 long double nearbyintl(long double);
428 long double nextafterl(long double, long double);
429 double nexttoward(double, long double);
430 float nexttowardf(float, long double);
431 long double nexttowardl(long double, long double);
432 long double remainderl(long double, long double);
433 long double remquol(long double, long double, int *);
434 long double rintl(long double);
435 long double roundl(long double);
436 long double scalblnl(long double, long);
437 long double scalbnl(long double, int);
438 long double sinl(long double);
439 long double sqrtl(long double);
440 long double tanl(long double);
441 long double truncl(long double);
443 #endif /* __ISO_C_VISIBLE >= 1999 */
446 #endif /* !_MATH_H_ */
448 /* separate header for cmath */
449 #ifndef _MATH_EXTRA_H_
450 #if __ISO_C_VISIBLE >= 1999
451 #if _DECLARE_C99_LDBL_MATH
453 #define _MATH_EXTRA_H_
456 * extra long double versions of math functions for C99 and cmath
460 long double acoshl(long double);
461 long double asinhl(long double);
462 long double atanhl(long double);
463 long double coshl(long double);
464 long double erfcl(long double);
465 long double erfl(long double);
466 long double expm1l(long double);
467 long double lgammal(long double);
468 long double log10l(long double);
469 long double log1pl(long double);
470 long double log2l(long double);
471 long double logl(long double);
472 long double powl(long double, long double);
473 long double sinhl(long double);
474 long double tanhl(long double);
475 long double tgammal(long double);
479 #endif /* !_DECLARE_C99_LDBL_MATH */
480 #endif /* __ISO_C_VISIBLE >= 1999 */
481 #endif /* !_MATH_EXTRA_H_ */