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)
38 #define __MATH_BUILTIN_CONSTANTS
41 #if __GNUC_PREREQ__(3, 0)
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 || __has_extension(c_generic_selections)
81 #define __fp_type_select(x, f, d, ld) __extension__ _Generic((x), \
85 #elif __GNUC_PREREQ__(3, 1) && !defined(__cplusplus)
86 #define __fp_type_select(x, f, d, ld) __builtin_choose_expr( \
87 __builtin_types_compatible_p(__typeof(x), long double), ld(x), \
88 __builtin_choose_expr( \
89 __builtin_types_compatible_p(__typeof(x), double), d(x), \
90 __builtin_choose_expr( \
91 __builtin_types_compatible_p(__typeof(x), float), f(x), (void)0)))
93 #define __fp_type_select(x, f, d, ld) \
94 ((sizeof(x) == sizeof(float)) ? f(x) \
95 : (sizeof(x) == sizeof(double)) ? d(x) \
99 #define fpclassify(x) \
100 __fp_type_select(x, __fpclassifyf, __fpclassifyd, __fpclassifyl)
101 #define isfinite(x) __fp_type_select(x, __isfinitef, __isfinite, __isfinitel)
102 #define isinf(x) __fp_type_select(x, __isinff, __isinf, __isinfl)
104 __fp_type_select(x, __inline_isnanf, __inline_isnan, __inline_isnanl)
105 #define isnormal(x) __fp_type_select(x, __isnormalf, __isnormal, __isnormall)
107 #ifdef __MATH_BUILTIN_RELOPS
108 #define isgreater(x, y) __builtin_isgreater((x), (y))
109 #define isgreaterequal(x, y) __builtin_isgreaterequal((x), (y))
110 #define isless(x, y) __builtin_isless((x), (y))
111 #define islessequal(x, y) __builtin_islessequal((x), (y))
112 #define islessgreater(x, y) __builtin_islessgreater((x), (y))
113 #define isunordered(x, y) __builtin_isunordered((x), (y))
115 #define isgreater(x, y) (!isunordered((x), (y)) && (x) > (y))
116 #define isgreaterequal(x, y) (!isunordered((x), (y)) && (x) >= (y))
117 #define isless(x, y) (!isunordered((x), (y)) && (x) < (y))
118 #define islessequal(x, y) (!isunordered((x), (y)) && (x) <= (y))
119 #define islessgreater(x, y) (!isunordered((x), (y)) && \
120 ((x) > (y) || (y) > (x)))
121 #define isunordered(x, y) (isnan(x) || isnan(y))
122 #endif /* __MATH_BUILTIN_RELOPS */
124 #define signbit(x) __fp_type_select(x, __signbitf, __signbit, __signbitl)
126 typedef __double_t double_t;
127 typedef __float_t float_t;
128 #endif /* __ISO_C_VISIBLE >= 1999 */
133 #if __BSD_VISIBLE || __XSI_VISIBLE
134 #define M_E 2.7182818284590452354 /* e */
135 #define M_LOG2E 1.4426950408889634074 /* log 2e */
136 #define M_LOG10E 0.43429448190325182765 /* log 10e */
137 #define M_LN2 0.69314718055994530942 /* log e2 */
138 #define M_LN10 2.30258509299404568402 /* log e10 */
139 #define M_PI 3.14159265358979323846 /* pi */
140 #define M_PI_2 1.57079632679489661923 /* pi/2 */
141 #define M_PI_4 0.78539816339744830962 /* pi/4 */
142 #define M_1_PI 0.31830988618379067154 /* 1/pi */
143 #define M_2_PI 0.63661977236758134308 /* 2/pi */
144 #define M_2_SQRTPI 1.12837916709551257390 /* 2/sqrt(pi) */
145 #define M_SQRT2 1.41421356237309504880 /* sqrt(2) */
146 #define M_SQRT1_2 0.70710678118654752440 /* 1/sqrt(2) */
148 #define MAXFLOAT ((float)3.40282346638528860e+38)
150 #endif /* __BSD_VISIBLE || __XSI_VISIBLE */
154 /* Old value from 4.4BSD-Lite math.h; this is probably better. */
155 #define HUGE HUGE_VAL
157 #define HUGE MAXFLOAT
159 #endif /* __BSD_VISIBLE */
162 * Most of these functions depend on the rounding mode and have the side
163 * effect of raising floating-point exceptions, so they are not declared
164 * as __pure2. In C99, FENV_ACCESS affects the purity of these functions.
170 int __fpclassifyd(double) __pure2;
171 int __fpclassifyf(float) __pure2;
172 int __fpclassifyl(long double) __pure2;
173 int __isfinitef(float) __pure2;
174 int __isfinite(double) __pure2;
175 int __isfinitel(long double) __pure2;
176 int __isinff(float) __pure2;
177 int __isinf(double) __pure2;
178 int __isinfl(long double) __pure2;
179 int __isnormalf(float) __pure2;
180 int __isnormal(double) __pure2;
181 int __isnormall(long double) __pure2;
182 int __signbit(double) __pure2;
183 int __signbitf(float) __pure2;
184 int __signbitl(long double) __pure2;
187 __inline_isnan(__const double __x)
194 __inline_isnanf(__const float __x)
201 __inline_isnanl(__const long double __x)
208 * Define the following aliases, for compatibility with glibc and CUDA.
210 #define __isnan __inline_isnan
211 #define __isnanf __inline_isnanf
214 * Version 2 of the Single UNIX Specification (UNIX98) defined isnan() and
215 * isinf() as functions taking double. C99, and the subsequent POSIX revisions
216 * (SUSv3, POSIX.1-2001, define it as a macro that accepts any real floating
217 * point type. If we are targeting SUSv2 and C99 or C11 (or C++11) then we
218 * expose the newer definition, assuming that the language spec takes
219 * precedence over the operating system interface spec.
221 #if __XSI_VISIBLE > 0 && __XSI_VISIBLE < 600 && __ISO_C_VISIBLE < 1999
231 double atan2(double, double);
241 double frexp(double, int *); /* fundamentally !__pure2 */
242 double ldexp(double, int);
244 double log10(double);
245 double modf(double, double *); /* fundamentally !__pure2 */
247 double pow(double, double);
251 double fabs(double) __pure2;
252 double floor(double);
253 double fmod(double, double);
256 * These functions are not in C90.
258 #if __BSD_VISIBLE || __ISO_C_VISIBLE >= 1999 || __XSI_VISIBLE
259 double acosh(double);
260 double asinh(double);
261 double atanh(double);
266 double expm1(double);
267 double fma(double, double, double);
268 double hypot(double, double);
269 int ilogb(double) __pure2;
270 double lgamma(double);
271 long long llrint(double);
272 long long llround(double);
273 double log1p(double);
278 double nan(const char *) __pure2;
279 double nextafter(double, double);
280 double remainder(double, double);
281 double remquo(double, double, int *);
283 #endif /* __BSD_VISIBLE || __ISO_C_VISIBLE >= 1999 || __XSI_VISIBLE */
285 #if __BSD_VISIBLE || __XSI_VISIBLE
288 double jn(int, double);
291 double yn(int, double);
293 #if __XSI_VISIBLE <= 500 || __BSD_VISIBLE
294 double gamma(double);
297 #if __XSI_VISIBLE <= 600 || __BSD_VISIBLE
298 double scalb(double, double);
300 #endif /* __BSD_VISIBLE || __XSI_VISIBLE */
302 #if __BSD_VISIBLE || __ISO_C_VISIBLE >= 1999
303 double copysign(double, double) __pure2;
304 double fdim(double, double);
305 double fmax(double, double) __pure2;
306 double fmin(double, double) __pure2;
307 double nearbyint(double);
308 double round(double);
309 double scalbln(double, long);
310 double scalbn(double, int);
311 double tgamma(double);
312 double trunc(double);
316 * BSD math library entry points
319 double drem(double, double);
320 int finite(double) __pure2;
321 int isnanf(float) __pure2;
324 * Reentrant version of gamma & lgamma; passes signgam back by reference
325 * as the second argument; user must allocate space for signgam.
327 double gamma_r(double, int *);
328 double lgamma_r(double, int *);
333 double significand(double);
334 #endif /* __BSD_VISIBLE */
336 /* float versions of ANSI/POSIX functions */
337 #if __ISO_C_VISIBLE >= 1999
341 float atan2f(float, float);
353 float frexpf(float, int *); /* fundamentally !__pure2 */
354 int ilogbf(float) __pure2;
355 float ldexpf(float, int);
360 float modff(float, float *); /* fundamentally !__pure2 */
362 float powf(float, float);
366 float fabsf(float) __pure2;
368 float fmodf(float, float);
373 float hypotf(float, float);
374 float lgammaf(float);
375 float tgammaf(float);
382 float copysignf(float, float) __pure2;
383 long long llrintf(float);
384 long long llroundf(float);
387 float nanf(const char *) __pure2;
388 float nearbyintf(float);
389 float nextafterf(float, float);
390 float remainderf(float, float);
391 float remquof(float, float, int *);
393 float scalblnf(float, long);
394 float scalbnf(float, int);
397 float fdimf(float, float);
398 float fmaf(float, float, float);
399 float fmaxf(float, float) __pure2;
400 float fminf(float, float) __pure2;
404 * float versions of BSD math library entry points
407 float dremf(float, float);
408 int finitef(float) __pure2;
412 float jnf(int, float);
413 float scalbf(float, float);
416 float ynf(int, float);
419 * Float versions of reentrant version of gamma & lgamma; passes
420 * signgam back by reference as the second argument; user must
421 * allocate space for signgam.
423 float gammaf_r(float, int *);
424 float lgammaf_r(float, int *);
427 * float version of IEEE Test Vector
429 float significandf(float);
430 #endif /* __BSD_VISIBLE */
433 * long double versions of ISO/POSIX math functions
435 #if __ISO_C_VISIBLE >= 1999
436 long double acoshl(long double);
437 long double acosl(long double);
438 long double asinhl(long double);
439 long double asinl(long double);
440 long double atan2l(long double, long double);
441 long double atanhl(long double);
442 long double atanl(long double);
443 long double cbrtl(long double);
444 long double ceill(long double);
445 long double copysignl(long double, long double) __pure2;
446 long double coshl(long double);
447 long double cosl(long double);
448 long double erfcl(long double);
449 long double erfl(long double);
450 long double exp2l(long double);
451 long double expl(long double);
452 long double expm1l(long double);
453 long double fabsl(long double) __pure2;
454 long double fdiml(long double, long double);
455 long double floorl(long double);
456 long double fmal(long double, long double, long double);
457 long double fmaxl(long double, long double) __pure2;
458 long double fminl(long double, long double) __pure2;
459 long double fmodl(long double, long double);
460 long double frexpl(long double, int *); /* fundamentally !__pure2 */
461 long double hypotl(long double, long double);
462 int ilogbl(long double) __pure2;
463 long double ldexpl(long double, int);
464 long double lgammal(long double);
465 long long llrintl(long double);
466 long long llroundl(long double);
467 long double log10l(long double);
468 long double log1pl(long double);
469 long double log2l(long double);
470 long double logbl(long double);
471 long double logl(long double);
472 long lrintl(long double);
473 long lroundl(long double);
474 long double modfl(long double, long double *); /* fundamentally !__pure2 */
475 long double nanl(const char *) __pure2;
476 long double nearbyintl(long double);
477 long double nextafterl(long double, long double);
478 double nexttoward(double, long double);
479 float nexttowardf(float, long double);
480 long double nexttowardl(long double, long double);
481 long double powl(long double, long double);
482 long double remainderl(long double, long double);
483 long double remquol(long double, long double, int *);
484 long double rintl(long double);
485 long double roundl(long double);
486 long double scalblnl(long double, long);
487 long double scalbnl(long double, int);
488 long double sinhl(long double);
489 long double sinl(long double);
490 long double sqrtl(long double);
491 long double tanhl(long double);
492 long double tanl(long double);
493 long double tgammal(long double);
494 long double truncl(long double);
495 #endif /* __ISO_C_VISIBLE >= 1999 */
498 long double lgammal_r(long double, int *);
499 void sincos(double, double *, double *);
500 void sincosf(float, float *, float *);
501 void sincosl(long double, long double *, long double *);
502 double cospi(double);
504 long double cospil(long double);
505 double sinpi(double);
507 long double sinpil(long double);
508 double tanpi(double);
510 long double tanpil(long double);
515 #endif /* !_MATH_H_ */