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