math.h revision 130264
1/*
2 * ====================================================
3 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
4 *
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
8 * is preserved.
9 * ====================================================
10 */
11
12/*
13 * from: @(#)fdlibm.h 5.1 93/09/24
14 * $FreeBSD: head/lib/msun/src/math.h 130264 2004-06-09 10:32:05Z das $
15 */
16
17#ifndef _MATH_H_
18#define	_MATH_H_
19
20#include <sys/cdefs.h>
21#include <sys/_types.h>
22
23/*
24 * ANSI/POSIX
25 */
26extern const union __infinity_un {
27	unsigned char	__uc[8];
28	double		__ud;
29} __infinity;
30
31extern const union __nan_un {
32	unsigned char	__uc[sizeof(float)];
33	float		__uf;
34} __nan;
35
36#define	HUGE_VAL	(__infinity.__ud)
37
38#if __ISO_C_VISIBLE >= 1999
39#define	FP_ILOGB0	(-0x7fffffff - 1)	/* INT_MIN */
40#define	FP_ILOGBNAN	0x7fffffff		/* INT_MAX */
41#define	HUGE_VALF	(float)HUGE_VAL
42#define	HUGE_VALL	(long double)HUGE_VAL
43#define	INFINITY	HUGE_VALF
44#define	NAN		(__nan.__uf)
45
46#define	MATH_ERRNO	1
47#define	MATH_ERREXCEPT	2
48#define	math_errhandling	0
49
50/* Symbolic constants to classify floating point numbers. */
51#define	FP_INFINITE	0x01
52#define	FP_NAN		0x02
53#define	FP_NORMAL	0x04
54#define	FP_SUBNORMAL	0x08
55#define	FP_ZERO		0x10
56#define	fpclassify(x) \
57    ((sizeof (x) == sizeof (float)) ? __fpclassifyf(x) \
58    : (sizeof (x) == sizeof (double)) ? __fpclassifyd(x) \
59    : __fpclassifyl(x))
60
61#define	isfinite(x)	((fpclassify(x) & (FP_INFINITE|FP_NAN)) == 0)
62#define	isinf(x)	(fpclassify(x) == FP_INFINITE)
63#define	isnan(x)	(fpclassify(x) == FP_NAN)
64#define	isnormal(x)	(fpclassify(x) == FP_NORMAL)
65
66#define	isgreater(x, y)		(!isunordered((x), (y)) && (x) > (y))
67#define	isgreaterequal(x, y)	(!isunordered((x), (y)) && (x) >= (y))
68#define	isless(x, y)		(!isunordered((x), (y)) && (x) < (y))
69#define	islessequal(x, y)	(!isunordered((x), (y)) && (x) <= (y))
70#define	islessgreater(x, y)	(!isunordered((x), (y)) && \
71					((x) > (y) || (y) > (x)))
72#define	isunordered(x, y)	(isnan(x) || isnan(y))
73
74#define	signbit(x)	__signbit(x)
75
76typedef	__double_t	double_t;
77typedef	__float_t	float_t;
78#endif /* __ISO_C_VISIBLE >= 1999 */
79
80/*
81 * XOPEN/SVID
82 */
83#if __BSD_VISIBLE || __XSI_VISIBLE
84#define	M_E		2.7182818284590452354	/* e */
85#define	M_LOG2E		1.4426950408889634074	/* log 2e */
86#define	M_LOG10E	0.43429448190325182765	/* log 10e */
87#define	M_LN2		0.69314718055994530942	/* log e2 */
88#define	M_LN10		2.30258509299404568402	/* log e10 */
89#define	M_PI		3.14159265358979323846	/* pi */
90#define	M_PI_2		1.57079632679489661923	/* pi/2 */
91#define	M_PI_4		0.78539816339744830962	/* pi/4 */
92#define	M_1_PI		0.31830988618379067154	/* 1/pi */
93#define	M_2_PI		0.63661977236758134308	/* 2/pi */
94#define	M_2_SQRTPI	1.12837916709551257390	/* 2/sqrt(pi) */
95#define	M_SQRT2		1.41421356237309504880	/* sqrt(2) */
96#define	M_SQRT1_2	0.70710678118654752440	/* 1/sqrt(2) */
97
98#define	MAXFLOAT	((float)3.40282346638528860e+38)
99extern int signgam;
100#endif /* __BSD_VISIBLE || __XSI_VISIBLE */
101
102#if __BSD_VISIBLE
103enum fdversion {fdlibm_ieee = -1, fdlibm_svid, fdlibm_xopen, fdlibm_posix};
104
105#define _LIB_VERSION_TYPE enum fdversion
106#define _LIB_VERSION _fdlib_version
107
108/* if global variable _LIB_VERSION is not desirable, one may
109 * change the following to be a constant by:
110 *	#define _LIB_VERSION_TYPE const enum version
111 * In that case, after one initializes the value _LIB_VERSION (see
112 * s_lib_version.c) during compile time, it cannot be modified
113 * in the middle of a program
114 */
115extern  _LIB_VERSION_TYPE  _LIB_VERSION;
116
117#define _IEEE_  fdlibm_ieee
118#define _SVID_  fdlibm_svid
119#define _XOPEN_ fdlibm_xopen
120#define _POSIX_ fdlibm_posix
121
122/* We have a problem when using C++ since `exception' is a reserved
123   name in C++.  */
124#ifndef __cplusplus
125struct exception {
126	int type;
127	char *name;
128	double arg1;
129	double arg2;
130	double retval;
131};
132#endif
133
134#define	isnanf(x)      	isnan(x)
135
136#if 0
137/* Old value from 4.4BSD-Lite math.h; this is probably better. */
138#define	HUGE		HUGE_VAL
139#else
140#define	HUGE		MAXFLOAT
141#endif
142
143#define X_TLOSS		1.41484755040568800000e+16	/* pi*2**52 */
144
145#define	DOMAIN		1
146#define	SING		2
147#define	OVERFLOW	3
148#define	UNDERFLOW	4
149#define	TLOSS		5
150#define	PLOSS		6
151
152#endif /* __BSD_VISIBLE */
153
154/*
155 * Most of these functions have the side effect of setting errno, so they
156 * are not declared as __pure2.  (XXX: this point needs to be revisited,
157 * since C99 doesn't require the mistake of setting errno, and we mostly
158 * don't set it anyway.  In C99, pragmas and functions for changing the
159 * rounding mode affect the purity of these functions.)
160 */
161__BEGIN_DECLS
162/*
163 * ANSI/POSIX
164 */
165int	__fpclassifyd(double) __pure2;
166int	__fpclassifyf(float) __pure2;
167int	__fpclassifyl(long double) __pure2;
168int	__signbit(double) __pure2;
169
170double	acos(double);
171double	asin(double);
172double	atan(double);
173double	atan2(double, double);
174double	cos(double);
175double	sin(double);
176double	tan(double);
177
178double	cosh(double);
179double	sinh(double);
180double	tanh(double);
181
182double	exp(double);
183double	frexp(double, int *);	/* fundamentally !__pure2 */
184double	ldexp(double, int);
185double	log(double);
186double	log10(double);
187double	modf(double, double *);	/* fundamentally !__pure2 */
188
189double	pow(double, double);
190double	sqrt(double);
191
192double	ceil(double);
193double	fabs(double);
194double	floor(double);
195double	fmod(double, double);
196
197/*
198 * These functions are not in C90 so they can be "right".  The ones that
199 * never set errno in lib/msun are declared as __pure2.
200 */
201#if __BSD_VISIBLE || __ISO_C_VISIBLE >= 1999 || __XSI_VISIBLE
202double	acosh(double);
203double	asinh(double);
204double	atanh(double);
205double	cbrt(double) __pure2;
206double	erf(double);
207double	erfc(double) __pure2;
208double	expm1(double) __pure2;
209double	hypot(double, double);
210int	ilogb(double);
211double	lgamma(double);
212double	log1p(double) __pure2;
213double	logb(double) __pure2;
214double	nextafter(double, double);
215double	remainder(double, double);
216double	rint(double) __pure2;
217double	round(double);
218#endif /* __BSD_VISIBLE || __ISO_C_VISIBLE >= 1999 || __XSI_VISIBLE */
219
220#if __BSD_VISIBLE || __XSI_VISIBLE
221double	j0(double);
222double	j1(double);
223double	jn(int, double);
224double	scalb(double, double);
225double	y0(double);
226double	y1(double);
227double	yn(int, double);
228
229#if __XSI_VISIBLE <= 500 || __BSD_VISIBLE
230double	gamma(double);
231#endif
232#endif /* __BSD_VISIBLE || __XSI_VISIBLE */
233
234#if __BSD_VISIBLE || __ISO_C_VISIBLE >= 1999
235double	copysign(double, double) __pure2;
236double	scalbn(double, int);
237double	tgamma(double);
238#endif
239
240/*
241 * BSD math library entry points
242 */
243#if __BSD_VISIBLE
244double	drem(double, double);
245int	finite(double) __pure2;
246
247/*
248 * Reentrant version of gamma & lgamma; passes signgam back by reference
249 * as the second argument; user must allocate space for signgam.
250 */
251double	gamma_r(double, int *);
252double	lgamma_r(double, int *);
253
254/*
255 * IEEE Test Vector
256 */
257double	significand(double);
258
259#ifndef __cplusplus
260int	matherr(struct exception *);
261#endif
262#endif /* __BSD_VISIBLE */
263
264/* float versions of ANSI/POSIX functions */
265#if __ISO_C_VISIBLE >= 1999
266float	acosf(float);
267float	asinf(float);
268float	atanf(float);
269float	atan2f(float, float);
270float	cosf(float);
271float	sinf(float);
272float	tanf(float);
273
274float	coshf(float);
275float	sinhf(float);
276float	tanhf(float);
277
278float	expf(float);
279float	expm1f(float) __pure2;
280float	frexpf(float, int *);	/* fundamentally !__pure2 */
281int	ilogbf(float);
282float	ldexpf(float, int);
283float	log10f(float);
284float	log1pf(float) __pure2;
285float	logf(float);
286float	modff(float, float *);	/* fundamentally !__pure2 */
287
288float	powf(float, float);
289float	sqrtf(float);
290
291float	ceilf(float);
292float	fabsf(float);
293float	floorf(float);
294float	fmodf(float, float);
295float	roundf(float);
296
297float	erff(float);
298float	erfcf(float) __pure2;
299float	hypotf(float, float) __pure2;
300float	lgammaf(float);
301
302float	acoshf(float);
303float	asinhf(float);
304float	atanhf(float);
305float	cbrtf(float) __pure2;
306float	logbf(float) __pure2;
307float	copysignf(float, float) __pure2;
308float	nextafterf(float, float);
309float	remainderf(float, float);
310float	rintf(float);
311float	scalbnf(float, int);
312#endif
313
314/*
315 * float versions of BSD math library entry points
316 */
317#if __BSD_VISIBLE
318float	dremf(float, float);
319int	finitef(float) __pure2;
320float	gammaf(float);
321float	j0f(float);
322float	j1f(float);
323float	jnf(int, float);
324float	scalbf(float, float);
325float	y0f(float);
326float	y1f(float);
327float	ynf(int, float);
328
329/*
330 * Float versions of reentrant version of gamma & lgamma; passes
331 * signgam back by reference as the second argument; user must
332 * allocate space for signgam.
333 */
334float	gammaf_r(float, int *);
335float	lgammaf_r(float, int *);
336
337/*
338 * float version of IEEE Test Vector
339 */
340float	significandf(float);
341#endif	/* __BSD_VISIBLE */
342
343/*
344 * long double versions of ISO/POSIX math functions
345 */
346#if __ISO_C_VISIBLE >= 1999
347#if 0
348long double	acoshl(long double);
349long double	acosl(long double);
350long double	asinhl(long double);
351long double	asinl(long double);
352long double	atan2l(long double, long double);
353long double	atanhl(long double);
354long double	atanl(long double);
355long double	cbrtl(long double);
356long double	ceill(long double);
357#endif
358long double	copysignl(long double, long double);
359#if 0
360long double	coshl(long double);
361long double	cosl(long double);
362long double	erfcl(long double);
363long double	erfl(long double);
364long double	exp2l(long double);
365long double	expl(long double);
366long double	expm1l(long double);
367#endif
368long double	fabsl(long double);
369#if 0
370long double	fdiml(long double, long double);
371long double	floorl(long double);
372long double	fmal(long double, long double, long double);
373long double	fmaxl(long double, long double);
374long double	fminl(long double, long double);
375long double	fmodl(long double, long double);
376long double	frexpl(long double	value, int *);
377long double	hypotl(long double, long double);
378int		ilogbl(long double);
379long double	ldexpl(long double, int);
380long double	lgammal(long double);
381long long	llrintl(long double);
382long long	llroundl(long double);
383long double	log10l(long double);
384long double	log1pl(long double);
385long double	log2l(long double);
386long double	logbl(long double);
387long double	logl(long double);
388long		lrintl(long double);
389long		lroundl(long double);
390long double	modfl(long double, long double	*);
391long double	nanl(const char *);
392long double	nearbyintl(long double);
393long double	nextafterl(long double, long double);
394double		nexttoward(double, long double);
395float		nexttowardf(float, long double);
396long double	nexttowardl(long double, long double);
397long double	powl(long double, long double);
398long double	remainderl(long double, long double);
399long double	remquol(long double, long double, int *);
400long double	rintl(long double);
401long double	roundl(long double);
402long double	scalblnl(long double, long);
403long double	scalbnl(long double, int);
404long double	sinhl(long double);
405long double	sinl(long double);
406long double	sqrtl(long double);
407long double	tanhl(long double);
408long double	tanl(long double);
409long double	tgammal(long double);
410long double	truncl(long double);
411#endif
412
413#endif /* __ISO_C_VISIBLE >= 1999 */
414__END_DECLS
415
416#endif /* !_MATH_H_ */
417