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
73 /* Symbolic constants to classify floating point numbers. */
74 #define FP_INFINITE 0x01
76 #define FP_NORMAL 0x04
77 #define FP_SUBNORMAL 0x08
80 #if (__STDC_VERSION__ >= 201112L && defined(__clang__)) || \
81 __has_extension(c_generic_selections)
82 #define __fp_type_select(x, f, d, ld) _Generic((x), \
86 volatile float: f(x), \
87 volatile double: d(x), \
88 volatile long double: ld(x), \
89 volatile const float: f(x), \
90 volatile const double: d(x), \
91 volatile const long double: ld(x), \
94 const long double: ld(x))
95 #elif __GNUC_PREREQ__(3, 1) && !defined(__cplusplus)
96 #define __fp_type_select(x, f, d, ld) __builtin_choose_expr( \
97 __builtin_types_compatible_p(__typeof(x), long double), ld(x), \
98 __builtin_choose_expr( \
99 __builtin_types_compatible_p(__typeof(x), double), d(x), \
100 __builtin_choose_expr( \
101 __builtin_types_compatible_p(__typeof(x), float), f(x), (void)0)))
103 #define __fp_type_select(x, f, d, ld) \
104 ((sizeof(x) == sizeof(float)) ? f(x) \
105 : (sizeof(x) == sizeof(double)) ? d(x) \
109 #define fpclassify(x) \
110 __fp_type_select(x, __fpclassifyf, __fpclassifyd, __fpclassifyl)
111 #define isfinite(x) __fp_type_select(x, __isfinitef, __isfinite, __isfinitel)
112 #define isinf(x) __fp_type_select(x, __isinff, __isinf, __isinfl)
114 __fp_type_select(x, __inline_isnanf, __inline_isnan, __inline_isnanl)
115 #define isnormal(x) __fp_type_select(x, __isnormalf, __isnormal, __isnormall)
117 #ifdef __MATH_BUILTIN_RELOPS
118 #define isgreater(x, y) __builtin_isgreater((x), (y))
119 #define isgreaterequal(x, y) __builtin_isgreaterequal((x), (y))
120 #define isless(x, y) __builtin_isless((x), (y))
121 #define islessequal(x, y) __builtin_islessequal((x), (y))
122 #define islessgreater(x, y) __builtin_islessgreater((x), (y))
123 #define isunordered(x, y) __builtin_isunordered((x), (y))
125 #define isgreater(x, y) (!isunordered((x), (y)) && (x) > (y))
126 #define isgreaterequal(x, y) (!isunordered((x), (y)) && (x) >= (y))
127 #define isless(x, y) (!isunordered((x), (y)) && (x) < (y))
128 #define islessequal(x, y) (!isunordered((x), (y)) && (x) <= (y))
129 #define islessgreater(x, y) (!isunordered((x), (y)) && \
130 ((x) > (y) || (y) > (x)))
131 #define isunordered(x, y) (isnan(x) || isnan(y))
132 #endif /* __MATH_BUILTIN_RELOPS */
134 #define signbit(x) __fp_type_select(x, __signbitf, __signbit, __signbitl)
136 typedef __double_t double_t;
137 typedef __float_t float_t;
138 #endif /* __ISO_C_VISIBLE >= 1999 */
143 #if __BSD_VISIBLE || __XSI_VISIBLE
144 #define M_E 2.7182818284590452354 /* e */
145 #define M_LOG2E 1.4426950408889634074 /* log 2e */
146 #define M_LOG10E 0.43429448190325182765 /* log 10e */
147 #define M_LN2 0.69314718055994530942 /* log e2 */
148 #define M_LN10 2.30258509299404568402 /* log e10 */
149 #define M_PI 3.14159265358979323846 /* pi */
150 #define M_PI_2 1.57079632679489661923 /* pi/2 */
151 #define M_PI_4 0.78539816339744830962 /* pi/4 */
152 #define M_1_PI 0.31830988618379067154 /* 1/pi */
153 #define M_2_PI 0.63661977236758134308 /* 2/pi */
154 #define M_2_SQRTPI 1.12837916709551257390 /* 2/sqrt(pi) */
155 #define M_SQRT2 1.41421356237309504880 /* sqrt(2) */
156 #define M_SQRT1_2 0.70710678118654752440 /* 1/sqrt(2) */
158 #define MAXFLOAT ((float)3.40282346638528860e+38)
160 #endif /* __BSD_VISIBLE || __XSI_VISIBLE */
164 /* Old value from 4.4BSD-Lite math.h; this is probably better. */
165 #define HUGE HUGE_VAL
167 #define HUGE MAXFLOAT
169 #endif /* __BSD_VISIBLE */
172 * Most of these functions depend on the rounding mode and have the side
173 * effect of raising floating-point exceptions, so they are not declared
174 * as __pure2. In C99, FENV_ACCESS affects the purity of these functions.
180 int __fpclassifyd(double) __pure2;
181 int __fpclassifyf(float) __pure2;
182 int __fpclassifyl(long double) __pure2;
183 int __isfinitef(float) __pure2;
184 int __isfinite(double) __pure2;
185 int __isfinitel(long double) __pure2;
186 int __isinff(float) __pure2;
187 int __isinf(double) __pure2;
188 int __isinfl(long double) __pure2;
189 int __isnormalf(float) __pure2;
190 int __isnormal(double) __pure2;
191 int __isnormall(long double) __pure2;
192 int __signbit(double) __pure2;
193 int __signbitf(float) __pure2;
194 int __signbitl(long double) __pure2;
197 __inline_isnan(__const double __x)
204 __inline_isnanf(__const float __x)
211 __inline_isnanl(__const long double __x)
218 * Define the following aliases, for compatibility with glibc and CUDA.
220 #define __isnan __inline_isnan
221 #define __isnanf __inline_isnanf
224 * Version 2 of the Single UNIX Specification (UNIX98) defined isnan() and
225 * isinf() as functions taking double. C99, and the subsequent POSIX revisions
226 * (SUSv3, POSIX.1-2001, define it as a macro that accepts any real floating
227 * point type. If we are targeting SUSv2 and C99 or C11 (or C++11) then we
228 * expose the newer definition, assuming that the language spec takes
229 * precedence over the operating system interface spec.
231 #if __XSI_VISIBLE > 0 && __XSI_VISIBLE < 600 && __ISO_C_VISIBLE < 1999
241 double atan2(double, double);
251 double frexp(double, int *); /* fundamentally !__pure2 */
252 double ldexp(double, int);
254 double log10(double);
255 double modf(double, double *); /* fundamentally !__pure2 */
257 double pow(double, double);
261 double fabs(double) __pure2;
262 double floor(double);
263 double fmod(double, double);
266 * These functions are not in C90.
268 #if __BSD_VISIBLE || __ISO_C_VISIBLE >= 1999 || __XSI_VISIBLE
269 double acosh(double);
270 double asinh(double);
271 double atanh(double);
276 double expm1(double);
277 double fma(double, double, double);
278 double hypot(double, double);
279 int ilogb(double) __pure2;
280 double lgamma(double);
281 long long llrint(double);
282 long long llround(double);
283 double log1p(double);
288 double nan(const char *) __pure2;
289 double nextafter(double, double);
290 double remainder(double, double);
291 double remquo(double, double, int *);
293 #endif /* __BSD_VISIBLE || __ISO_C_VISIBLE >= 1999 || __XSI_VISIBLE */
295 #if __BSD_VISIBLE || __XSI_VISIBLE
298 double jn(int, double);
301 double yn(int, double);
303 #if __XSI_VISIBLE <= 500 || __BSD_VISIBLE
304 double gamma(double);
307 #if __XSI_VISIBLE <= 600 || __BSD_VISIBLE
308 double scalb(double, double);
310 #endif /* __BSD_VISIBLE || __XSI_VISIBLE */
312 #if __BSD_VISIBLE || __ISO_C_VISIBLE >= 1999
313 double copysign(double, double) __pure2;
314 double fdim(double, double);
315 double fmax(double, double) __pure2;
316 double fmin(double, double) __pure2;
317 double nearbyint(double);
318 double round(double);
319 double scalbln(double, long);
320 double scalbn(double, int);
321 double tgamma(double);
322 double trunc(double);
326 * BSD math library entry points
329 double drem(double, double);
330 int finite(double) __pure2;
331 int isnanf(float) __pure2;
334 * Reentrant version of gamma & lgamma; passes signgam back by reference
335 * as the second argument; user must allocate space for signgam.
337 double gamma_r(double, int *);
338 double lgamma_r(double, int *);
343 double significand(double);
344 #endif /* __BSD_VISIBLE */
346 /* float versions of ANSI/POSIX functions */
347 #if __ISO_C_VISIBLE >= 1999
351 float atan2f(float, float);
363 float frexpf(float, int *); /* fundamentally !__pure2 */
364 int ilogbf(float) __pure2;
365 float ldexpf(float, int);
370 float modff(float, float *); /* fundamentally !__pure2 */
372 float powf(float, float);
376 float fabsf(float) __pure2;
378 float fmodf(float, float);
383 float hypotf(float, float);
384 float lgammaf(float);
385 float tgammaf(float);
392 float copysignf(float, float) __pure2;
393 long long llrintf(float);
394 long long llroundf(float);
397 float nanf(const char *) __pure2;
398 float nearbyintf(float);
399 float nextafterf(float, float);
400 float remainderf(float, float);
401 float remquof(float, float, int *);
403 float scalblnf(float, long);
404 float scalbnf(float, int);
407 float fdimf(float, float);
408 float fmaf(float, float, float);
409 float fmaxf(float, float) __pure2;
410 float fminf(float, float) __pure2;
414 * float versions of BSD math library entry points
417 float dremf(float, float);
418 int finitef(float) __pure2;
422 float jnf(int, float);
423 float scalbf(float, float);
426 float ynf(int, float);
429 * Float versions of reentrant version of gamma & lgamma; passes
430 * signgam back by reference as the second argument; user must
431 * allocate space for signgam.
433 float gammaf_r(float, int *);
434 float lgammaf_r(float, int *);
437 * float version of IEEE Test Vector
439 float significandf(float);
440 #endif /* __BSD_VISIBLE */
443 * long double versions of ISO/POSIX math functions
445 #if __ISO_C_VISIBLE >= 1999
446 long double acoshl(long double);
447 long double acosl(long double);
448 long double asinhl(long double);
449 long double asinl(long double);
450 long double atan2l(long double, long double);
451 long double atanhl(long double);
452 long double atanl(long double);
453 long double cbrtl(long double);
454 long double ceill(long double);
455 long double copysignl(long double, long double) __pure2;
456 long double coshl(long double);
457 long double cosl(long double);
458 long double erfcl(long double);
459 long double erfl(long double);
460 long double exp2l(long double);
461 long double expl(long double);
462 long double expm1l(long double);
463 long double fabsl(long double) __pure2;
464 long double fdiml(long double, long double);
465 long double floorl(long double);
466 long double fmal(long double, long double, long double);
467 long double fmaxl(long double, long double) __pure2;
468 long double fminl(long double, long double) __pure2;
469 long double fmodl(long double, long double);
470 long double frexpl(long double, int *); /* fundamentally !__pure2 */
471 long double hypotl(long double, long double);
472 int ilogbl(long double) __pure2;
473 long double ldexpl(long double, int);
474 long double lgammal(long double);
475 long long llrintl(long double);
476 long long llroundl(long double);
477 long double log10l(long double);
478 long double log1pl(long double);
479 long double log2l(long double);
480 long double logbl(long double);
481 long double logl(long double);
482 long lrintl(long double);
483 long lroundl(long double);
484 long double modfl(long double, long double *); /* fundamentally !__pure2 */
485 long double nanl(const char *) __pure2;
486 long double nearbyintl(long double);
487 long double nextafterl(long double, long double);
488 double nexttoward(double, long double);
489 float nexttowardf(float, long double);
490 long double nexttowardl(long double, long double);
491 long double powl(long double, long double);
492 long double remainderl(long double, long double);
493 long double remquol(long double, long double, int *);
494 long double rintl(long double);
495 long double roundl(long double);
496 long double scalblnl(long double, long);
497 long double scalbnl(long double, int);
498 long double sinhl(long double);
499 long double sinl(long double);
500 long double sqrtl(long double);
501 long double tanhl(long double);
502 long double tanl(long double);
503 long double tgammal(long double);
504 long double truncl(long double);
505 #endif /* __ISO_C_VISIBLE >= 1999 */
508 long double lgammal_r(long double, int *);
509 void sincos(double, double *, double *);
510 void sincosf(float, float *, float *);
511 void sincosl(long double, long double *, long double *);
516 #endif /* !_MATH_H_ */