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 * ====================================================
11 * $NetBSD: math.h,v 1.46 2007/02/22 22:08:19 drochner Exp $
12 * $DragonFly: src/include/math.h,v 1.12 2007/06/17 18:00:08 pavalos Exp $
16 * @(#)fdlibm.h 5.1 93/09/24
22 #include <sys/cdefs.h>
24 #if __GNUC_PREREQ__(3, 3) || (defined(__INTEL_COMPILER) && __INTEL_COMPILER >= 800)
25 #define __MATH_BUILTIN_CONSTANTS
28 #if __GNUC_PREREQ__(3, 0) && !defined(__INTEL_COMPILER)
29 #define __MATH_BUILTIN_RELOPS
33 unsigned char __dummy
[sizeof(float)];
38 unsigned char __dummy
[sizeof(double)];
42 union __long_double_u
{
43 unsigned char __dummy
[sizeof(long double)];
47 #include <machine/math.h>
49 #ifdef __HAVE_LONG_DOUBLE
50 #define __fpmacro_unary_floating(__name, __arg0) \
52 ((sizeof (__arg0) == sizeof (float)) \
53 ? __ ## __name ## f (__arg0) \
54 : (sizeof (__arg0) == sizeof (double)) \
55 ? __ ## __name ## d (__arg0) \
56 : __ ## __name ## l (__arg0))
58 #define __fpmacro_unary_floating(__name, __arg0) \
60 ((sizeof (__arg0) == sizeof (float)) \
61 ? __ ## __name ## f (__arg0) \
62 : __ ## __name ## d (__arg0))
63 #endif /* __HAVE_LONG_DOUBLE */
68 /* 7.12#3 HUGE_VAL, HUGELF, HUGE_VALL */
69 extern const union __double_u __infinity
;
70 #ifdef __MATH_BUILTIN_CONSTANTS
71 #define HUGE_VAL __builtin_huge_val()
73 #define HUGE_VAL __infinity.__val
79 #if __ISO_C_VISIBLE >= 1999
80 /* 7.12#3 HUGE_VAL, HUGELF, HUGE_VALL */
81 extern const union __float_u __infinityf
;
82 #ifdef __MATH_BUILTIN_CONSTANTS
83 #define HUGE_VALF __builtin_huge_valf()
85 #define HUGE_VALF __infinityf.__val
88 extern const union __long_double_u __infinityl
;
89 #ifdef __MATH_BUILTIN_CONSTANTS
90 #define HUGE_VALL __builtin_huge_vall()
92 #define HUGE_VALL __infinityl.__val
96 #ifdef __MATH_BUILTIN_CONSTANTS
97 #define INFINITY __builtin_inf()
98 #elif defined(__INFINITY)
99 #define INFINITY __INFINITY /* float constant which overflows */
101 #define INFINITY HUGE_VALF /* positive infinity */
102 #endif /* __INFINITY */
104 /* 7.12#5 NAN: a quiet NaN, if supported */
105 #ifdef __MATH_BUILTIN_CONSTANTS
106 #define NAN __builtin_nan("")
107 #elif defined(__HAVE_NANF)
108 extern const union __float_u __nanf
;
109 #define NAN __nanf.__val
110 #endif /* __HAVE_NANF */
112 /* 7.12#6 number classification macros */
113 #define FP_INFINITE 0x00
115 #define FP_NORMAL 0x02
116 #define FP_SUBNORMAL 0x03
118 /* NetBSD extensions */
119 #define _FP_LOMD 0x80 /* range for machine-specific classes */
120 #define _FP_HIMD 0xff
127 #if __XSI_VISIBLE > 0
128 #define M_E 2.7182818284590452354 /* e */
129 #define M_LOG2E 1.4426950408889634074 /* log 2e */
130 #define M_LOG10E 0.43429448190325182765 /* log 10e */
131 #define M_LN2 0.69314718055994530942 /* log e2 */
132 #define M_LN10 2.30258509299404568402 /* log e10 */
133 #define M_PI 3.14159265358979323846 /* pi */
134 #define M_PI_2 1.57079632679489661923 /* pi/2 */
135 #define M_PI_4 0.78539816339744830962 /* pi/4 */
136 #define M_1_PI 0.31830988618379067154 /* 1/pi */
137 #define M_2_PI 0.63661977236758134308 /* 2/pi */
138 #define M_2_SQRTPI 1.12837916709551257390 /* 2/sqrt(pi) */
139 #define M_SQRT2 1.41421356237309504880 /* sqrt(2) */
140 #define M_SQRT1_2 0.70710678118654752440 /* 1/sqrt(2) */
142 #define MAXFLOAT ((float)3.40282346638528860e+38)
144 #endif /* _XSI_VISIBLE */
147 #define HUGE MAXFLOAT
150 * set X_TLOSS = pi*2**52, which is possibly defined in <values.h>
151 * (one may replace the following line by "#include <values.h>")
154 #define X_TLOSS 1.41484755040568800000e+16
163 #endif /* __DF_VISIBLE */
172 double atan2(double, double);
182 double frexp(double, int *);
183 double ldexp(double, int);
186 double log10(double);
187 double modf(double, double *);
189 double pow(double, double);
194 double floor(double);
195 double fmod(double, double);
197 #if __XSI_VISIBLE > 0
200 double gamma(double);
201 double hypot(double, double);
205 double jn(int, double);
206 double lgamma(double);
209 double yn(int, double);
210 #endif /* __XSI_VISIBLE */
212 #if __XSI_VISIBLE >= 500
213 double acosh(double);
214 double asinh(double);
215 double atanh(double);
217 double expm1(double);
219 double log1p(double);
221 double nextafter(double, double);
222 double remainder(double, double);
224 double scalb(double, double);
225 #endif /* __XSI_VISIBLE >= 500 */
230 #if __ISO_C_VISIBLE >= 1999
231 /* 7.12.3.1 int fpclassify(real-floating x) */
232 #define fpclassify(__x) __fpmacro_unary_floating(fpclassify, __x)
234 /* 7.12.3.2 int isfinite(real-floating x) */
235 #define isfinite(__x) __fpmacro_unary_floating(isfinite, __x)
237 /* 7.12.3.5 int isnormal(real-floating x) */
238 #define isnormal(__x) (fpclassify(__x) == FP_NORMAL)
240 /* 7.12.3.6 int signbit(real-floating x) */
241 #define signbit(__x) __fpmacro_unary_floating(signbit, __x)
243 /* 7.12.4 trigonometric */
248 float atan2f(float, float);
253 /* 7.12.5 hyperbolic */
262 /* 7.12.6 exp / log */
266 float frexpf(float, int *);
267 long double frexpl(long double, int *);
269 float ldexpf(float, int);
275 float modff(float, float *);
276 float scalbnf(float, int);
278 /* 7.12.7 power / absolute */
282 float hypotf(float, float);
283 float powf(float, float);
286 /* 7.12.8 error / gamma */
290 float lgammaf(float);
292 /* 7.12.9 nearest integer */
296 float nearbyintf(float);
297 double nearbyint(double);
299 double round(double);
301 double trunc(double);
303 long int lrint(double);
304 long int lrintf(float);
306 long long int llrint(double);
308 long long int llrintf(float);
309 long int lround(double);
310 long int lroundf(float);
312 long long int llround(double);
314 long long int llroundf(float);
316 /* 7.12.10 remainder */
318 float fmodf(float, float);
319 float remainderf(float, float);
321 /* 7.12.11 manipulation */
323 float copysignf(float, float);
324 long double copysignl(long double x
, long double y
);
326 double nan(const char *);
327 float nanf(const char *);
328 long double nanl(const char *);
329 float nextafterf(float, float);
331 /* 7.12.12 maximum, minimum, positive difference */
332 double fdim(double, double);
333 float fdimf(float, float);
334 long double fdiml(long double, long double);
336 double fmax(double, double);
337 float fmaxf(float, float);
338 long double fmaxl(long double, long double);
340 double fmin(double, double);
341 float fminf(float, float);
342 long double fminl(long double, long double);
344 #endif /* __ISO_C_VISIBLE >= 1999 */
346 #if __ISO_C_VISIBLE >= 1999
347 /* 7.12.3.3 int isinf(real-floating x) */
349 #define isinf(__x) __isinf(__x)
351 #define isinf(__x) __fpmacro_unary_floating(isinf, __x)
354 /* 7.12.3.4 int isnan(real-floating x) */
356 #define isnan(__x) __isnan(__x)
358 #define isnan(__x) __fpmacro_unary_floating(isnan, __x)
361 /* 7.12.14 Comparision macros */
362 #ifdef __MATH_BUILTIN_RELOPS
363 #define isgreater(x, y) __builtin_isgreater((x), (y))
364 #define isgreaterequal(x, y) __builtin_isgreaterequal((x), (y))
365 #define isless(x, y) __builtin_isless((x), (y))
366 #define islessequal(x, y) __builtin_islessequal((x), (y))
367 #define islessgreater(x, y) __builtin_islessgreater((x), (y))
368 #define isunordered(x, y) __builtin_isunordered((x), (y))
370 #define isgreater(x, y) (!isunordered((x), (y)) && (x) > (y))
371 #define isgreaterequal(x, y) (!isunordered((x), (y)) && (x) >= (y))
372 #define isless(x, y) (!isunordered((x), (y)) && (x) < (y))
373 #define islessequal(x, y) (!isunordered((x), (y)) && (x) <= (y))
374 #define islessgreater(x, y) (!isunordered((x), (y)) && \
375 ((x) > (y) || (y) > (x)))
376 #define isunordered(x, y) (isnan(x) || isnan(y))
377 #endif /* __MATH_BUILTIN_RELOPS */
379 #endif /* __ISO_C_VISIBLE >= 1999 */
385 double significand(double);
388 * Functions callable from C, intended to support IEEE arithmetic.
390 double copysign(double, double);
391 double scalbn(double, int);
394 * BSD math library entry points
396 double drem(double, double);
399 * Reentrant version of gamma & lgamma; passes signgam back by reference
400 * as the second argument; user must allocate space for signgam.
402 double gamma_r(double, int *);
403 double lgamma_r(double, int *);
404 #endif /* __DF_VISIBLE */
409 /* float versions of ANSI/POSIX functions */
415 float jnf(int, float);
418 float ynf(int, float);
420 float scalbf(float, float);
423 * float version of IEEE Test Vector
425 float significandf(float);
428 * float versions of BSD math library entry points
430 float dremf(float, float);
433 * Float versions of reentrant version of gamma & lgamma; passes
434 * signgam back by reference as the second argument; user must
435 * allocate space for signgam.
437 float gammaf_r(float, int *);
438 float lgammaf_r(float, int *);
439 #endif /* __DF_VISIBLE */
442 * Library implementation
444 int __fpclassifyf(float);
445 int __fpclassifyd(double);
446 int __isfinitef(float);
447 int __isfinited(double);
449 int __isinfd(double);
451 int __isnand(double);
452 int __signbitf(float);
453 int __signbitd(double);
455 #ifdef __HAVE_LONG_DOUBLE
456 int __fpclassifyl(long double);
457 int __isfinitel(long double);
458 int __isinfl(long double);
459 int __isnanl(long double);
460 int __signbitl(long double);
464 #endif /* _MATH_H_ */