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