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