1 /* $NetBSD: math.h,v 1.58 2012/05/05 22:07:57 christos Exp $ */
4 * ====================================================
5 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
7 * Developed at SunPro, a Sun Microsystems, Inc. business.
8 * Permission to use, copy, modify, and distribute this
9 * software is freely granted, provided that this notice
11 * ====================================================
15 * @(#)fdlibm.h 5.1 93/09/24
21 #include <sys/cdefs.h>
22 #include <sys/featuretest.h>
25 unsigned char __dummy
[sizeof(float)];
30 unsigned char __dummy
[sizeof(double)];
34 union __long_double_u
{
35 unsigned char __dummy
[sizeof(long double)];
39 #include <machine/math.h> /* may use __float_u, __double_u,
42 #ifdef __HAVE_LONG_DOUBLE
43 #define __fpmacro_unary_floating(__name, __arg0) \
45 ((sizeof (__arg0) == sizeof (float)) \
46 ? __ ## __name ## f (__arg0) \
47 : (sizeof (__arg0) == sizeof (double)) \
48 ? __ ## __name ## d (__arg0) \
49 : __ ## __name ## l (__arg0))
51 #define __fpmacro_unary_floating(__name, __arg0) \
53 ((sizeof (__arg0) == sizeof (float)) \
54 ? __ ## __name ## f (__arg0) \
55 : __ ## __name ## d (__arg0))
56 #endif /* __HAVE_LONG_DOUBLE */
61 /* 7.12#3 HUGE_VAL, HUGELF, HUGE_VALL */
62 #if __GNUC_PREREQ__(3, 3)
63 #define HUGE_VAL __builtin_huge_val()
65 extern const union __double_u __infinity
;
66 #define HUGE_VAL __infinity.__val
72 #if !defined(_ANSI_SOURCE) && !defined(_POSIX_C_SOURCE) && \
73 !defined(_XOPEN_SOURCE) || \
74 ((__STDC_VERSION__ - 0) >= 199901L) || \
75 ((_POSIX_C_SOURCE - 0) >= 200112L) || \
76 ((_XOPEN_SOURCE - 0) >= 600) || \
77 defined(_ISOC99_SOURCE) || defined(_NETBSD_SOURCE)
78 /* 7.12#3 HUGE_VAL, HUGELF, HUGE_VALL */
79 #if __GNUC_PREREQ__(3, 3)
80 #define HUGE_VALF __builtin_huge_valf()
81 #define HUGE_VALL __builtin_huge_vall()
83 extern const union __float_u __infinityf
;
84 #define HUGE_VALF __infinityf.__val
86 extern const union __long_double_u __infinityl
;
87 #define HUGE_VALL __infinityl.__val
91 #if defined(__INFINITY)
92 #define INFINITY __INFINITY /* float constant which overflows */
93 #elif __GNUC_PREREQ__(3, 3)
94 #define INFINITY __builtin_inff()
96 #define INFINITY HUGE_VALF /* positive infinity */
97 #endif /* __INFINITY */
99 /* 7.12#5 NAN: a quiet NaN, if supported */
101 #if __GNUC_PREREQ__(3,3)
102 #define NAN __builtin_nanf("")
104 extern const union __float_u __nanf
;
105 #define NAN __nanf.__val
107 #endif /* __HAVE_NANF */
109 /* 7.12#6 number classification macros */
110 #define FP_INFINITE 0x00
112 #define FP_NORMAL 0x02
113 #define FP_SUBNORMAL 0x03
115 /* NetBSD extensions */
116 #define _FP_LOMD 0x80 /* range for machine-specific classes */
117 #define _FP_HIMD 0xff
119 #endif /* !_ANSI_SOURCE && ... */
124 #if defined(_XOPEN_SOURCE) || defined(_NETBSD_SOURCE)
125 #define M_E 2.7182818284590452354 /* e */
126 #define M_LOG2E 1.4426950408889634074 /* log 2e */
127 #define M_LOG10E 0.43429448190325182765 /* log 10e */
128 #define M_LN2 0.69314718055994530942 /* log e2 */
129 #define M_LN10 2.30258509299404568402 /* log e10 */
130 #define M_PI 3.14159265358979323846 /* pi */
131 #define M_PI_2 1.57079632679489661923 /* pi/2 */
132 #define M_PI_4 0.78539816339744830962 /* pi/4 */
133 #define M_1_PI 0.31830988618379067154 /* 1/pi */
134 #define M_2_PI 0.63661977236758134308 /* 2/pi */
135 #define M_2_SQRTPI 1.12837916709551257390 /* 2/sqrt(pi) */
136 #define M_SQRT2 1.41421356237309504880 /* sqrt(2) */
137 #define M_SQRT1_2 0.70710678118654752440 /* 1/sqrt(2) */
139 #define MAXFLOAT ((float)3.40282346638528860e+38)
141 #endif /* _XOPEN_SOURCE || _NETBSD_SOURCE */
143 #if defined(_NETBSD_SOURCE)
144 enum fdversion
{fdlibm_ieee
= -1, fdlibm_svid
, fdlibm_xopen
, fdlibm_posix
};
146 #define _LIB_VERSION_TYPE enum fdversion
147 #define _LIB_VERSION _fdlib_version
149 /* if global variable _LIB_VERSION is not desirable, one may
150 * change the following to be a constant by:
151 * #define _LIB_VERSION_TYPE const enum version
152 * In that case, after one initializes the value _LIB_VERSION (see
153 * s_lib_version.c) during compile time, it cannot be modified
154 * in the middle of a program
156 extern _LIB_VERSION_TYPE _LIB_VERSION
;
158 #define _IEEE_ fdlibm_ieee
159 #define _SVID_ fdlibm_svid
160 #define _XOPEN_ fdlibm_xopen
161 #define _POSIX_ fdlibm_posix
173 #define HUGE MAXFLOAT
176 * set X_TLOSS = pi*2**52, which is possibly defined in <values.h>
177 * (one may replace the following line by "#include <values.h>")
180 #define X_TLOSS 1.41484755040568800000e+16
189 #endif /* _NETBSD_SOURCE */
198 double atan2(double, double);
209 double frexp(double, int *);
210 double ldexp(double, int);
213 double log10(double);
214 double modf(double, double *);
216 double pow(double, double);
221 double floor(double);
222 double fmod(double, double);
224 #if defined(_XOPEN_SOURCE) || defined(_NETBSD_SOURCE)
227 double gamma(double);
228 double hypot(double, double);
232 double jn(int, double);
233 double lgamma(double);
236 double yn(int, double);
238 #if (_XOPEN_SOURCE - 0) >= 500 || defined(_NETBSD_SOURCE)
239 double acosh(double);
240 double asinh(double);
241 double atanh(double);
243 double expm1(double);
245 double log1p(double);
247 double nextafter(double, double);
248 double remainder(double, double);
250 double scalb(double, double);
251 #endif /* (_XOPEN_SOURCE - 0) >= 500 || defined(_NETBSD_SOURCE)*/
252 #endif /* _XOPEN_SOURCE || _NETBSD_SOURCE */
257 #if !defined(_ANSI_SOURCE) && !defined(_POSIX_C_SOURCE) && \
258 !defined(_XOPEN_SOURCE) || \
259 ((__STDC_VERSION__ - 0) >= 199901L) || \
260 ((_POSIX_C_SOURCE - 0) >= 200112L) || \
261 ((_XOPEN_SOURCE - 0) >= 600) || \
262 defined(_ISOC99_SOURCE) || defined(_NETBSD_SOURCE)
263 /* 7.12.3.1 int fpclassify(real-floating x) */
264 #define fpclassify(__x) __fpmacro_unary_floating(fpclassify, __x)
266 /* 7.12.3.2 int isfinite(real-floating x) */
267 #define isfinite(__x) __fpmacro_unary_floating(isfinite, __x)
269 /* 7.12.3.5 int isnormal(real-floating x) */
270 #define isnormal(__x) (fpclassify(__x) == FP_NORMAL)
272 /* 7.12.3.6 int signbit(real-floating x) */
273 #define signbit(__x) __fpmacro_unary_floating(signbit, __x)
275 /* 7.12.4 trigonometric */
280 float atan2f(float, float);
285 /* 7.12.5 hyperbolic */
294 /* 7.12.6 exp / log */
299 float frexpf(float, int *);
301 float ldexpf(float, int);
307 float modff(float, float *);
308 float scalbnf(float, int);
310 /* 7.12.7 power / absolute */
314 long double fabsl(long double);
315 float hypotf(float, float);
316 float powf(float, float);
319 /* 7.12.8 error / gamma */
323 float lgammaf(float);
324 float tgammaf(float);
325 double tgamma(double);
327 /* 7.12.9 nearest integer */
332 double round(double);
334 double trunc(double);
336 long int lrint(double);
337 long int lrintf(float);
339 long long int llrint(double);
341 long long int llrintf(float);
342 long int lround(double);
343 long int lroundf(float);
345 long long int llround(double);
347 long long int llroundf(float);
349 /* 7.12.10 remainder */
351 float fmodf(float, float);
352 float remainderf(float, float);
354 /* 7.12.10.3 The remquo functions */
355 double remquo(double, double, int *);
356 float remquof(float, float, int *);
358 /* 7.12.11 manipulation */
360 float copysignf(float, float);
361 long double copysignl(long double, long double);
362 double nan(const char *);
363 float nanf(const char *);
364 long double nanl(const char *);
365 float nextafterf(float, float);
366 long double nextafterl(long double, long double);
367 double nexttoward(double, long double);
369 /* 7.12.14 comparison */
371 #define isunordered(x, y) (isnan(x) || isnan(y))
372 #define isgreater(x, y) (!isunordered((x), (y)) && (x) > (y))
373 #define isgreaterequal(x, y) (!isunordered((x), (y)) && (x) >= (y))
374 #define isless(x, y) (!isunordered((x), (y)) && (x) < (y))
375 #define islessequal(x, y) (!isunordered((x), (y)) && (x) <= (y))
376 #define islessgreater(x, y) (!isunordered((x), (y)) && \
377 ((x) > (y) || (y) > (x)))
378 double fdim(double, double);
379 double fmax(double, double);
380 double fmin(double, double);
381 float fdimf(float, float);
382 float fmaxf(float, float);
383 float fminf(float, float);
384 long double fdiml(long double, long double);
385 long double fmaxl(long double, long double);
386 long double fminl(long double, long double);
388 #endif /* !_ANSI_SOURCE && ... */
390 #if !defined(_ANSI_SOURCE) && !defined(_POSIX_C_SOURCE) || \
391 !defined(_XOPEN_SOURCE) || \
392 ((__STDC_VERSION__ - 0) >= 199901L) || \
393 ((_POSIX_C_SOURCE - 0) >= 200112L) || \
394 defined(_ISOC99_SOURCE) || defined(_NETBSD_SOURCE)
395 /* 7.12.3.3 int isinf(real-floating x) */
397 #define isinf(__x) __isinf(__x)
399 #define isinf(__x) __fpmacro_unary_floating(isinf, __x)
402 /* 7.12.3.4 int isnan(real-floating x) */
404 #define isnan(__x) __isnan(__x)
406 #define isnan(__x) __fpmacro_unary_floating(isnan, __x)
408 #endif /* !_ANSI_SOURCE && ... */
410 #if defined(_NETBSD_SOURCE)
412 int matherr(struct exception
*);
418 double significand(double);
421 * Functions callable from C, intended to support IEEE arithmetic.
423 double copysign(double, double);
424 double scalbn(double, int);
427 * BSD math library entry points
429 double drem(double, double);
431 #endif /* _NETBSD_SOURCE */
433 #if defined(_NETBSD_SOURCE) || defined(_REENTRANT)
435 * Reentrant version of gamma & lgamma; passes signgam back by reference
436 * as the second argument; user must allocate space for signgam.
438 double gamma_r(double, int *);
439 double lgamma_r(double, int *);
440 #endif /* _NETBSD_SOURCE || _REENTRANT */
443 #if defined(_NETBSD_SOURCE)
445 /* float versions of ANSI/POSIX functions */
453 float jnf(int, float);
456 float ynf(int, float);
458 float scalbf(float, float);
461 * float version of IEEE Test Vector
463 float significandf(float);
466 * float versions of BSD math library entry points
468 float dremf(float, float);
469 #endif /* _NETBSD_SOURCE */
471 #if defined(_NETBSD_SOURCE) || defined(_REENTRANT)
473 * Float versions of reentrant version of gamma & lgamma; passes
474 * signgam back by reference as the second argument; user must
475 * allocate space for signgam.
477 float gammaf_r(float, int *);
478 float lgammaf_r(float, int *);
479 #endif /* !... || _REENTRANT */
482 * Library implementation
484 int __fpclassifyf(float);
485 int __fpclassifyd(double);
486 int __isfinitef(float);
487 int __isfinited(double);
489 int __isinfd(double);
491 int __isnand(double);
492 int __signbitf(float);
493 int __signbitd(double);
495 #ifdef __HAVE_LONG_DOUBLE
496 int __fpclassifyl(long double);
497 int __isfinitel(long double);
498 int __isinfl(long double);
499 int __isnanl(long double);
500 int __signbitl(long double);
503 int ilogbl(long double);
504 long double logbl(long double);
505 long double scalbnl(long double, int);
509 #endif /* _MATH_H_ */