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.62 2007/01/07 07:54:21 das Exp $
20 #include <sys/cdefs.h>
23 #include <sys/_types.h>
24 #include <machine/_limits.h>
26 #include <sys/types.h>
29 /* AROS doesn't define __INT_MAX, but INT_MAX will do just as well */
30 #define __INT_MAX INT_MAX
32 #define __GNUC_PREREQ__ __GNUC_PREREQ
39 extern const union __infinity_un
{
40 unsigned char __uc
[8];
44 extern const union __nan_un
{
45 unsigned char __uc
[sizeof(float)];
49 #if __GNUC_PREREQ__(3, 3) || (defined(__INTEL_COMPILER) && __INTEL_COMPILER >= 800)
50 #define __MATH_BUILTIN_CONSTANTS
53 #if __GNUC_PREREQ__(3, 0) && !defined(__INTEL_COMPILER)
54 #define __MATH_BUILTIN_RELOPS
57 #ifdef __MATH_BUILTIN_CONSTANTS
58 #define HUGE_VAL __builtin_huge_val()
60 #define HUGE_VAL (__infinity.__ud)
63 #if __ISO_C_VISIBLE >= 1999
64 #define FP_ILOGB0 (-__INT_MAX)
65 #define FP_ILOGBNAN __INT_MAX
67 #ifdef __MATH_BUILTIN_CONSTANTS
68 #define HUGE_VALF __builtin_huge_valf()
69 #define HUGE_VALL __builtin_huge_vall()
70 #define INFINITY __builtin_inf()
71 #define NAN __builtin_nan("")
73 #define HUGE_VALF (float)HUGE_VAL
74 #define HUGE_VALL (long double)HUGE_VAL
75 #define INFINITY HUGE_VALF
76 #define NAN (__nan.__uf)
77 #endif /* __MATH_BUILTIN_CONSTANTS */
80 #define MATH_ERREXCEPT 2
81 #define math_errhandling MATH_ERREXCEPT
83 /* XXX We need a <machine/math.h>. */
84 #if defined(__ia64__) || defined(__sparc64__)
92 /* Symbolic constants to classify floating point numbers. */
93 #define FP_INFINITE 0x01
95 #define FP_NORMAL 0x04
96 #define FP_SUBNORMAL 0x08
98 #define fpclassify(x) \
99 ((sizeof (x) == sizeof (float)) ? __fpclassifyf(x) \
100 : (sizeof (x) == sizeof (double)) ? __fpclassifyd(x) \
103 #define isfinite(x) \
104 ((sizeof (x) == sizeof (float)) ? __isfinitef(x) \
105 : (sizeof (x) == sizeof (double)) ? __isfinite(x) \
108 ((sizeof (x) == sizeof (float)) ? __isinff(x) \
109 : (sizeof (x) == sizeof (double)) ? isinf(x) \
113 ((sizeof (x) == sizeof (float)) ? isnanf(x) \
114 : (sizeof (x) == sizeof (double)) ? isnan(x) \
118 ((sizeof (x) == sizeof (float)) ? isnanf(x) \
119 : (sizeof (x) == sizeof (double)) ? __isnan(x) \
122 #define isnormal(x) \
123 ((sizeof (x) == sizeof (float)) ? __isnormalf(x) \
124 : (sizeof (x) == sizeof (double)) ? __isnormal(x) \
127 #ifdef __MATH_BUILTIN_RELOPS
128 #define isgreater(x, y) __builtin_isgreater((x), (y))
129 #define isgreaterequal(x, y) __builtin_isgreaterequal((x), (y))
130 #define isless(x, y) __builtin_isless((x), (y))
131 #define islessequal(x, y) __builtin_islessequal((x), (y))
132 #define islessgreater(x, y) __builtin_islessgreater((x), (y))
133 #define isunordered(x, y) __builtin_isunordered((x), (y))
135 #define isgreater(x, y) (!isunordered((x), (y)) && (x) > (y))
136 #define isgreaterequal(x, y) (!isunordered((x), (y)) && (x) >= (y))
137 #define isless(x, y) (!isunordered((x), (y)) && (x) < (y))
138 #define islessequal(x, y) (!isunordered((x), (y)) && (x) <= (y))
139 #define islessgreater(x, y) (!isunordered((x), (y)) && \
140 ((x) > (y) || (y) > (x)))
141 #define isunordered(x, y) (isnan(x) || isnan(y))
142 #endif /* __MATH_BUILTIN_RELOPS */
145 ((sizeof (x) == sizeof (float)) ? __signbitf(x) \
146 : (sizeof (x) == sizeof (double)) ? __signbit(x) \
149 typedef __double_t double_t
;
150 typedef __float_t float_t
;
151 #endif /* __ISO_C_VISIBLE >= 1999 */
156 #if __BSD_VISIBLE || __XSI_VISIBLE
157 #define M_E 2.7182818284590452354 /* e */
158 #define M_LOG2E 1.4426950408889634074 /* log 2e */
159 #define M_LOG10E 0.43429448190325182765 /* log 10e */
160 #define M_LN2 0.69314718055994530942 /* log e2 */
161 #define M_LN10 2.30258509299404568402 /* log e10 */
162 #define M_PI 3.14159265358979323846 /* pi */
163 #define M_PI_2 1.57079632679489661923 /* pi/2 */
164 #define M_PI_4 0.78539816339744830962 /* pi/4 */
165 #define M_1_PI 0.31830988618379067154 /* 1/pi */
166 #define M_2_PI 0.63661977236758134308 /* 2/pi */
167 #define M_2_SQRTPI 1.12837916709551257390 /* 2/sqrt(pi) */
168 #define M_SQRT2 1.41421356237309504880 /* sqrt(2) */
169 #define M_SQRT1_2 0.70710678118654752440 /* 1/sqrt(2) */
171 #define MAXFLOAT ((float)3.40282346638528860e+38)
173 #endif /* __BSD_VISIBLE || __XSI_VISIBLE */
177 /* Old value from 4.4BSD-Lite math.h; this is probably better. */
178 #define HUGE HUGE_VAL
180 #define HUGE MAXFLOAT
182 #endif /* __BSD_VISIBLE */
185 * Most of these functions depend on the rounding mode and have the side
186 * effect of raising floating-point exceptions, so they are not declared
187 * as __pure2. In C99, FENV_ACCESS affects the purity of these functions.
193 int __fpclassifyd(double) __pure2
;
194 int __fpclassifyf(float) __pure2
;
195 int __fpclassifyl(long double) __pure2
;
196 int __isfinitef(float) __pure2
;
197 int __isfinite(double) __pure2
;
198 int __isfinitel(long double) __pure2
;
199 int __isinff(float) __pure2
;
200 int __isinfl(long double) __pure2
;
202 int __isnan(double) __pure2
;
204 int __isnanl(long double) __pure2
;
205 int __isnormalf(float) __pure2
;
206 int __isnormal(double) __pure2
;
207 int __isnormall(long double) __pure2
;
208 int __signbit(double) __pure2
;
209 int __signbitf(float) __pure2
;
210 int __signbitl(long double) __pure2
;
215 double atan2(double, double);
225 double frexp(double, int *); /* fundamentally !__pure2 */
226 double ldexp(double, int);
228 double log10(double);
229 double modf(double, double *); /* fundamentally !__pure2 */
231 double pow(double, double);
235 double fabs(double) __pure2
;
236 double floor(double);
237 double fmod(double, double);
240 * These functions are not in C90.
242 #if __BSD_VISIBLE || __ISO_C_VISIBLE >= 1999 || __XSI_VISIBLE
243 double acosh(double);
244 double asinh(double);
245 double atanh(double);
250 double expm1(double);
251 double fma(double, double, double);
252 double hypot(double, double);
253 int ilogb(double) __pure2
;
254 int (isinf
)(double) __pure2
;
255 int (isnan
)(double) __pure2
;
256 double lgamma(double);
257 long long llrint(double);
258 long long llround(double);
259 double log1p(double);
263 double nextafter(double, double);
264 double remainder(double, double);
265 double remquo(double, double, int *);
267 #endif /* __BSD_VISIBLE || __ISO_C_VISIBLE >= 1999 || __XSI_VISIBLE */
269 #if __BSD_VISIBLE || __XSI_VISIBLE
272 double jn(int, double);
273 double scalb(double, double);
276 double yn(int, double);
278 #if __XSI_VISIBLE <= 500 || __BSD_VISIBLE
279 double gamma(double);
281 #endif /* __BSD_VISIBLE || __XSI_VISIBLE */
283 #if __BSD_VISIBLE || __ISO_C_VISIBLE >= 1999
284 double copysign(double, double) __pure2
;
285 double fdim(double, double);
286 double fmax(double, double) __pure2
;
287 double fmin(double, double) __pure2
;
288 double nearbyint(double);
289 double round(double);
290 double scalbln(double, long);
291 double scalbn(double, int);
292 double tgamma(double);
293 double trunc(double);
297 * BSD math library entry points
300 double drem(double, double);
301 int finite(double) __pure2
;
302 int isnanf(float) __pure2
;
305 * Reentrant version of gamma & lgamma; passes signgam back by reference
306 * as the second argument; user must allocate space for signgam.
308 double gamma_r(double, int *);
309 double lgamma_r(double, int *);
314 double significand(double);
315 #endif /* __BSD_VISIBLE */
317 /* float versions of ANSI/POSIX functions */
318 #if __ISO_C_VISIBLE >= 1999
322 float atan2f(float, float);
334 float frexpf(float, int *); /* fundamentally !__pure2 */
335 int ilogbf(float) __pure2
;
336 float ldexpf(float, int);
340 float modff(float, float *); /* fundamentally !__pure2 */
342 float powf(float, float);
346 float fabsf(float) __pure2
;
348 float fmodf(float, float);
353 float hypotf(float, float);
354 float lgammaf(float);
361 float copysignf(float, float) __pure2
;
362 long long llrintf(float);
363 long long llroundf(float);
366 float nearbyintf(float);
367 float nextafterf(float, float);
368 float remainderf(float, float);
369 float remquof(float, float, int *);
371 float scalblnf(float, long);
372 float scalbnf(float, int);
375 float fdimf(float, float);
376 float fmaf(float, float, float);
377 float fmaxf(float, float) __pure2
;
378 float fminf(float, float) __pure2
;
382 * float versions of BSD math library entry points
385 float dremf(float, float);
386 int finitef(float) __pure2
;
390 float jnf(int, float);
391 float scalbf(float, float);
394 float ynf(int, float);
397 * Float versions of reentrant version of gamma & lgamma; passes
398 * signgam back by reference as the second argument; user must
399 * allocate space for signgam.
401 float gammaf_r(float, int *);
402 float lgammaf_r(float, int *);
405 * float version of IEEE Test Vector
407 float significandf(float);
408 #endif /* __BSD_VISIBLE */
411 * long double versions of ISO/POSIX math functions
413 #if __ISO_C_VISIBLE >= 1999
415 long double acoshl(long double);
416 long double acosl(long double);
417 long double asinhl(long double);
418 long double asinl(long double);
419 long double atan2l(long double, long double);
420 long double atanhl(long double);
421 long double atanl(long double);
422 long double cbrtl(long double);
424 long double ceill(long double);
425 long double copysignl(long double, long double) __pure2
;
427 long double coshl(long double);
428 long double cosl(long double);
429 long double erfcl(long double);
430 long double erfl(long double);
431 long double exp2l(long double);
432 long double expl(long double);
433 long double expm1l(long double);
435 long double fabsl(long double) __pure2
;
436 long double fdiml(long double, long double);
437 long double floorl(long double);
438 long double fmal(long double, long double, long double);
439 long double fmaxl(long double, long double) __pure2
;
440 long double fminl(long double, long double) __pure2
;
442 long double fmodl(long double, long double);
444 long double frexpl(long double value
, int *); /* fundamentally !__pure2 */
446 long double hypotl(long double, long double);
448 int ilogbl(long double) __pure2
;
449 long double ldexpl(long double, int);
451 long double lgammal(long double);
452 long long llrintl(long double);
454 long long llroundl(long double);
456 long double log10l(long double);
457 long double log1pl(long double);
458 long double log2l(long double);
459 long double logbl(long double);
460 long double logl(long double);
461 long lrintl(long double);
463 long lroundl(long double);
464 long double modfl(long double, long double *); /* fundamentally !__pure2 */
466 long double nanl(const char *) __pure2
;
467 long double nearbyintl(long double);
469 long double nextafterl(long double, long double);
470 double nexttoward(double, long double);
471 float nexttowardf(float, long double);
472 long double nexttowardl(long double, long double);
474 long double powl(long double, long double);
475 long double remainderl(long double, long double);
476 long double remquol(long double, long double, int *);
477 long double rintl(long double);
479 long double roundl(long double);
480 long double scalblnl(long double, long);
481 long double scalbnl(long double, int);
483 long double sinhl(long double);
484 long double sinl(long double);
485 long double sqrtl(long double);
486 long double tanhl(long double);
487 long double tanl(long double);
488 long double tgammal(long double);
490 long double truncl(long double);
492 #endif /* __ISO_C_VISIBLE >= 1999 */
495 #endif /* !_MATH_H_ */