xref: /freebsd/lib/msun/src/math.h (revision 4b2eaea43fec8e8792be611dea204071a10b655a)
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$
15  */
16 
17 #ifndef _MATH_H_
18 #define	_MATH_H_
19 
20 /*
21  * ANSI/POSIX
22  */
23 extern const union __infinity_un {
24 	unsigned char	__uc[8];
25 	double		__ud;
26 } __infinity;
27 #define HUGE_VAL	(__infinity.__ud)
28 
29 /*
30  * XOPEN/SVID
31  */
32 #if !defined(_ANSI_SOURCE) && !defined(_POSIX_SOURCE)
33 #define	M_E		2.7182818284590452354	/* e */
34 #define	M_LOG2E		1.4426950408889634074	/* log 2e */
35 #define	M_LOG10E	0.43429448190325182765	/* log 10e */
36 #define	M_LN2		0.69314718055994530942	/* log e2 */
37 #define	M_LN10		2.30258509299404568402	/* log e10 */
38 #define	M_PI		3.14159265358979323846	/* pi */
39 #define	M_PI_2		1.57079632679489661923	/* pi/2 */
40 #define	M_PI_4		0.78539816339744830962	/* pi/4 */
41 #define	M_1_PI		0.31830988618379067154	/* 1/pi */
42 #define	M_2_PI		0.63661977236758134308	/* 2/pi */
43 #define	M_2_SQRTPI	1.12837916709551257390	/* 2/sqrt(pi) */
44 #define	M_SQRT2		1.41421356237309504880	/* sqrt(2) */
45 #define	M_SQRT1_2	0.70710678118654752440	/* 1/sqrt(2) */
46 
47 #define	MAXFLOAT	((float)3.40282346638528860e+38)
48 extern int signgam;
49 
50 #if !defined(_XOPEN_SOURCE)
51 enum fdversion {fdlibm_ieee = -1, fdlibm_svid, fdlibm_xopen, fdlibm_posix};
52 
53 #define _LIB_VERSION_TYPE enum fdversion
54 #define _LIB_VERSION _fdlib_version
55 
56 /* if global variable _LIB_VERSION is not desirable, one may
57  * change the following to be a constant by:
58  *	#define _LIB_VERSION_TYPE const enum version
59  * In that case, after one initializes the value _LIB_VERSION (see
60  * s_lib_version.c) during compile time, it cannot be modified
61  * in the middle of a program
62  */
63 extern  _LIB_VERSION_TYPE  _LIB_VERSION;
64 
65 #define _IEEE_  fdlibm_ieee
66 #define _SVID_  fdlibm_svid
67 #define _XOPEN_ fdlibm_xopen
68 #define _POSIX_ fdlibm_posix
69 
70 /* We have a problem when using C++ since `exception' is a reserved
71    name in C++.  */
72 #ifndef __cplusplus
73 struct exception {
74 	int type;
75 	char *name;
76 	double arg1;
77 	double arg2;
78 	double retval;
79 };
80 #endif
81 
82 #if 0
83 /* Old value from 4.4BSD-Lite math.h; this is probably better. */
84 #define	HUGE		HUGE_VAL
85 #else
86 #define	HUGE		MAXFLOAT
87 #endif
88 
89 /*
90  * set X_TLOSS = pi*2**52, which is possibly defined in <values.h>
91  * (one may replace the following line by "#include <values.h>")
92  */
93 
94 #define X_TLOSS		1.41484755040568800000e+16
95 
96 #define	DOMAIN		1
97 #define	SING		2
98 #define	OVERFLOW	3
99 #define	UNDERFLOW	4
100 #define	TLOSS		5
101 #define	PLOSS		6
102 
103 #endif /* !_XOPEN_SOURCE */
104 #endif /* !_ANSI_SOURCE && !_POSIX_SOURCE */
105 
106 #include <sys/cdefs.h>
107 
108 /*
109  * Most of these functions have the side effect of setting errno, so they
110  * are not declared as __pure2.  (XXX: this point needs to be revisited,
111  * since C99 doesn't require the mistake of setting errno, and we mostly
112  * don't set it anyway.  In C99, pragmas and functions for changing the
113  * rounding mode affect the purity of these functions.)
114  */
115 __BEGIN_DECLS
116 /*
117  * ANSI/POSIX
118  */
119 double	acos(double);
120 double	asin(double);
121 double	atan(double);
122 double	atan2(double, double);
123 double	cos(double);
124 double	sin(double);
125 double	tan(double);
126 
127 double	cosh(double);
128 double	sinh(double);
129 double	tanh(double);
130 
131 double	exp(double);
132 double	frexp(double, int *);	/* fundamentally !__pure2 */
133 double	ldexp(double, int);
134 double	log(double);
135 double	log10(double);
136 double	modf(double, double *);	/* fundamentally !__pure2 */
137 
138 double	pow(double, double);
139 double	sqrt(double);
140 
141 double	ceil(double);
142 double	fabs(double);
143 double	floor(double);
144 double	fmod(double, double);
145 
146 /*
147  * These functions are not in C90 so they can be "right".  The ones that
148  * never set errno in lib/msun are declared as __pure2.
149  */
150 #if !defined(_ANSI_SOURCE) && !defined(_POSIX_SOURCE)
151 double	erf(double);
152 double	erfc(double) __pure2;
153 int	finite(double) __pure2;
154 double	gamma(double);
155 double	hypot(double, double);
156 int	isinf(double) __pure2;
157 int	isnan(double) __pure2;
158 double	j0(double);
159 double	j1(double);
160 double	jn(int, double);
161 double	lgamma(double);
162 double	y0(double);
163 double	y1(double);
164 double	yn(int, double);
165 
166 #if !defined(_XOPEN_SOURCE)
167 double	acosh(double);
168 double	asinh(double);
169 double	atanh(double);
170 double	cbrt(double) __pure2;
171 double	logb(double) __pure2;
172 double	nextafter(double, double);
173 double	remainder(double, double);
174 double	scalb(double, double);
175 double	tgamma(double);
176 
177 #ifndef __cplusplus
178 int	matherr(struct exception *);
179 #endif
180 
181 /*
182  * IEEE Test Vector
183  */
184 double	significand(double);
185 
186 /*
187  * Functions callable from C, intended to support IEEE arithmetic.
188  */
189 double	copysign(double, double) __pure2;
190 int	ilogb(double);
191 double	rint(double) __pure2;
192 double	scalbn(double, int);
193 
194 /*
195  * BSD math library entry points
196  */
197 double	drem(double, double);
198 double	expm1(double) __pure2;
199 double	log1p(double) __pure2;
200 
201 /*
202  * Reentrant version of gamma & lgamma; passes signgam back by reference
203  * as the second argument; user must allocate space for signgam.
204  */
205 #ifdef _REENTRANT
206 double	gamma_r(double, int *);
207 double	lgamma_r(double, int *);
208 #endif /* _REENTRANT */
209 
210 /* float versions of ANSI/POSIX functions */
211 float	acosf(float);
212 float	asinf(float);
213 float	atanf(float);
214 float	atan2f(float, float);
215 float	cosf(float);
216 float	sinf(float);
217 float	tanf(float);
218 
219 float	coshf(float);
220 float	sinhf(float);
221 float	tanhf(float);
222 
223 float	expf(float);
224 float	frexpf(float, int *);	/* fundamentally !__pure2 */
225 float	ldexpf(float, int);
226 float	logf(float);
227 float	log10f(float);
228 float	modff(float, float *);	/* fundamentally !__pure2 */
229 
230 float	powf(float, float);
231 float	sqrtf(float);
232 
233 float	ceilf(float);
234 float	fabsf(float);
235 float	floorf(float);
236 float	fmodf(float, float);
237 
238 float	erff(float);
239 float	erfcf(float) __pure2;
240 int	finitef(float) __pure2;
241 float	gammaf(float);
242 float	hypotf(float, float) __pure2;
243 int	isnanf(float) __pure2;
244 float	j0f(float);
245 float	j1f(float);
246 float	jnf(int, float);
247 float	lgammaf(float);
248 float	y0f(float);
249 float	y1f(float);
250 float	ynf(int, float);
251 
252 float	acoshf(float);
253 float	asinhf(float);
254 float	atanhf(float);
255 float	cbrtf(float) __pure2;
256 float	logbf(float) __pure2;
257 float	nextafterf(float, float);
258 float	remainderf(float, float);
259 float	scalbf(float, float);
260 
261 /*
262  * float version of IEEE Test Vector
263  */
264 float	significandf(float);
265 
266 /*
267  * Float versions of functions callable from C, intended to support
268  * IEEE arithmetic.
269  */
270 float	copysignf(float, float) __pure2;
271 int	ilogbf(float);
272 float	rintf(float);
273 float	scalbnf(float, int);
274 
275 /*
276  * float versions of BSD math library entry points
277  */
278 float	dremf(float, float);
279 float	expm1f(float) __pure2;
280 float	log1pf(float) __pure2;
281 
282 /*
283  * Float versions of reentrant version of gamma & lgamma; passes
284  * signgam back by reference as the second argument; user must
285  * allocate space for signgam.
286  */
287 #ifdef _REENTRANT
288 float	gammaf_r(float, int *);
289 float	lgammaf_r(float, int *);
290 #endif	/* _REENTRANT */
291 
292 #endif /* !_XOPEN_SOURCE */
293 #endif /* !_ANSI_SOURCE && !_POSIX_SOURCE */
294 __END_DECLS
295 
296 #endif /* !_MATH_H_ */
297