xref: /freebsd/lib/msun/src/math.h (revision 6af83ee0d2941d18880b6aaa2b4facd1d30c6106)
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 #if __GNUC_PREREQ__(3, 3) || (defined(__INTEL_COMPILER) && __INTEL_COMPILER >= 800)
38 #define	__MATH_BUILTIN_CONSTANTS
39 #endif
40 
41 #if __GNUC_PREREQ__(3, 0) && !defined(__INTEL_COMPILER)
42 #define	__MATH_BUILTIN_RELOPS
43 #endif
44 
45 #ifdef __MATH_BUILTIN_CONSTANTS
46 #define	HUGE_VAL	__builtin_huge_val()
47 #else
48 #define	HUGE_VAL	(__infinity.__ud)
49 #endif
50 
51 #if __ISO_C_VISIBLE >= 1999
52 #define	FP_ILOGB0	(-__INT_MAX)
53 #define	FP_ILOGBNAN	__INT_MAX
54 
55 #ifdef __MATH_BUILTIN_CONSTANTS
56 #define	HUGE_VALF	__builtin_huge_valf()
57 #define	HUGE_VALL	__builtin_huge_vall()
58 #define	INFINITY	__builtin_inf()
59 #define	NAN		__builtin_nan("")
60 #else
61 #define	HUGE_VALF	(float)HUGE_VAL
62 #define	HUGE_VALL	(long double)HUGE_VAL
63 #define	INFINITY	HUGE_VALF
64 #define	NAN		(__nan.__uf)
65 #endif /* __MATH_BUILTIN_CONSTANTS */
66 
67 #define	MATH_ERRNO	1
68 #define	MATH_ERREXCEPT	2
69 #define	math_errhandling	MATH_ERREXCEPT
70 
71 #ifdef	__ia64__
72 #define	FP_FAST_FMA
73 #endif
74 #define	FP_FAST_FMAF
75 
76 /* Symbolic constants to classify floating point numbers. */
77 #define	FP_INFINITE	0x01
78 #define	FP_NAN		0x02
79 #define	FP_NORMAL	0x04
80 #define	FP_SUBNORMAL	0x08
81 #define	FP_ZERO		0x10
82 #define	fpclassify(x) \
83     ((sizeof (x) == sizeof (float)) ? __fpclassifyf(x) \
84     : (sizeof (x) == sizeof (double)) ? __fpclassifyd(x) \
85     : __fpclassifyl(x))
86 
87 #define	isfinite(x)					\
88     ((sizeof (x) == sizeof (float)) ? __isfinitef(x)	\
89     : (sizeof (x) == sizeof (double)) ? __isfinite(x)	\
90     : __isfinitel(x))
91 #define	isinf(x)					\
92     ((sizeof (x) == sizeof (float)) ? __isinff(x)	\
93     : (sizeof (x) == sizeof (double)) ? isinf(x)	\
94     : __isinfl(x))
95 #define	isnan(x)					\
96     ((sizeof (x) == sizeof (float)) ? isnanf(x)		\
97     : (sizeof (x) == sizeof (double)) ? isnan(x)	\
98     : __isnanl(x))
99 #define	isnormal(x)					\
100     ((sizeof (x) == sizeof (float)) ? __isnormalf(x)	\
101     : (sizeof (x) == sizeof (double)) ? __isnormal(x)	\
102     : __isnormall(x))
103 
104 #ifdef __MATH_BUILTIN_RELOPS
105 #define	isgreater(x, y)		__builtin_isgreater((x), (y))
106 #define	isgreaterequal(x, y)	__builtin_isgreaterequal((x), (y))
107 #define	isless(x, y)		__builtin_isless((x), (y))
108 #define	islessequal(x, y)	__builtin_islessequal((x), (y))
109 #define	islessgreater(x, y)	__builtin_islessgreater((x), (y))
110 #define	isunordered(x, y)	__builtin_isunordered((x), (y))
111 #else
112 #define	isgreater(x, y)		(!isunordered((x), (y)) && (x) > (y))
113 #define	isgreaterequal(x, y)	(!isunordered((x), (y)) && (x) >= (y))
114 #define	isless(x, y)		(!isunordered((x), (y)) && (x) < (y))
115 #define	islessequal(x, y)	(!isunordered((x), (y)) && (x) <= (y))
116 #define	islessgreater(x, y)	(!isunordered((x), (y)) && \
117 					((x) > (y) || (y) > (x)))
118 #define	isunordered(x, y)	(isnan(x) || isnan(y))
119 #endif /* __MATH_BUILTIN_RELOPS */
120 
121 #define	signbit(x)					\
122     ((sizeof (x) == sizeof (float)) ? __signbitf(x)	\
123     : (sizeof (x) == sizeof (double)) ? __signbit(x)	\
124     : __signbitl(x))
125 
126 typedef	__double_t	double_t;
127 typedef	__float_t	float_t;
128 #endif /* __ISO_C_VISIBLE >= 1999 */
129 
130 /*
131  * XOPEN/SVID
132  */
133 #if __BSD_VISIBLE || __XSI_VISIBLE
134 #define	M_E		2.7182818284590452354	/* e */
135 #define	M_LOG2E		1.4426950408889634074	/* log 2e */
136 #define	M_LOG10E	0.43429448190325182765	/* log 10e */
137 #define	M_LN2		0.69314718055994530942	/* log e2 */
138 #define	M_LN10		2.30258509299404568402	/* log e10 */
139 #define	M_PI		3.14159265358979323846	/* pi */
140 #define	M_PI_2		1.57079632679489661923	/* pi/2 */
141 #define	M_PI_4		0.78539816339744830962	/* pi/4 */
142 #define	M_1_PI		0.31830988618379067154	/* 1/pi */
143 #define	M_2_PI		0.63661977236758134308	/* 2/pi */
144 #define	M_2_SQRTPI	1.12837916709551257390	/* 2/sqrt(pi) */
145 #define	M_SQRT2		1.41421356237309504880	/* sqrt(2) */
146 #define	M_SQRT1_2	0.70710678118654752440	/* 1/sqrt(2) */
147 
148 #define	MAXFLOAT	((float)3.40282346638528860e+38)
149 extern int signgam;
150 #endif /* __BSD_VISIBLE || __XSI_VISIBLE */
151 
152 #if __BSD_VISIBLE
153 #if 0
154 /* Old value from 4.4BSD-Lite math.h; this is probably better. */
155 #define	HUGE		HUGE_VAL
156 #else
157 #define	HUGE		MAXFLOAT
158 #endif
159 #endif /* __BSD_VISIBLE */
160 
161 /*
162  * Most of these functions depend on the rounding mode and have the side
163  * effect of raising floating-point exceptions, so they are not declared
164  * as __pure2.  In C99, FENV_ACCESS affects the purity of these functions.
165  */
166 __BEGIN_DECLS
167 /*
168  * ANSI/POSIX
169  */
170 int	__fpclassifyd(double) __pure2;
171 int	__fpclassifyf(float) __pure2;
172 int	__fpclassifyl(long double) __pure2;
173 int	__isfinitef(float) __pure2;
174 int	__isfinite(double) __pure2;
175 int	__isfinitel(long double) __pure2;
176 int	__isinff(float) __pure2;
177 int	__isinfl(long double) __pure2;
178 int	__isnanl(long double) __pure2;
179 int	__isnormalf(float) __pure2;
180 int	__isnormal(double) __pure2;
181 int	__isnormall(long double) __pure2;
182 int	__signbit(double) __pure2;
183 int	__signbitf(float) __pure2;
184 int	__signbitl(long double) __pure2;
185 
186 double	acos(double);
187 double	asin(double);
188 double	atan(double);
189 double	atan2(double, double);
190 double	cos(double);
191 double	sin(double);
192 double	tan(double);
193 
194 double	cosh(double);
195 double	sinh(double);
196 double	tanh(double);
197 
198 double	exp(double);
199 double	frexp(double, int *);	/* fundamentally !__pure2 */
200 double	ldexp(double, int);
201 double	log(double);
202 double	log10(double);
203 double	modf(double, double *);	/* fundamentally !__pure2 */
204 
205 double	pow(double, double);
206 double	sqrt(double);
207 
208 double	ceil(double);
209 double	fabs(double) __pure2;
210 double	floor(double);
211 double	fmod(double, double);
212 
213 /*
214  * These functions are not in C90.
215  */
216 #if __BSD_VISIBLE || __ISO_C_VISIBLE >= 1999 || __XSI_VISIBLE
217 double	acosh(double);
218 double	asinh(double);
219 double	atanh(double);
220 double	cbrt(double);
221 double	erf(double);
222 double	erfc(double);
223 double	expm1(double);
224 double	hypot(double, double);
225 /* Our ilogb raises no exceptions; we side with IEEE-754R and C99, not POSIX */
226 int	ilogb(double) __pure2;
227 int	(isinf)(double) __pure2;
228 int	(isnan)(double) __pure2;
229 double	lgamma(double);
230 long long llrint(double);
231 long long llround(double);
232 double	log1p(double);
233 double	logb(double);
234 long	lrint(double);
235 long	lround(double);
236 double	nextafter(double, double);
237 double	remainder(double, double);
238 double	rint(double);
239 #endif /* __BSD_VISIBLE || __ISO_C_VISIBLE >= 1999 || __XSI_VISIBLE */
240 
241 #if __BSD_VISIBLE || __XSI_VISIBLE
242 double	j0(double);
243 double	j1(double);
244 double	jn(int, double);
245 double	scalb(double, double);
246 double	y0(double);
247 double	y1(double);
248 double	yn(int, double);
249 
250 #if __XSI_VISIBLE <= 500 || __BSD_VISIBLE
251 double	gamma(double);
252 #endif
253 #endif /* __BSD_VISIBLE || __XSI_VISIBLE */
254 
255 #if __BSD_VISIBLE || __ISO_C_VISIBLE >= 1999
256 double	copysign(double, double) __pure2;
257 double	fdim(double, double);
258 double	fmax(double, double) __pure2;
259 double	fmin(double, double) __pure2;
260 double	nearbyint(double);
261 double	round(double);
262 double	scalbln(double, long);
263 double	scalbn(double, int);
264 double	tgamma(double);
265 double	trunc(double);
266 #endif
267 
268 /*
269  * BSD math library entry points
270  */
271 #if __BSD_VISIBLE
272 double	drem(double, double);
273 int	finite(double) __pure2;
274 int	isnanf(float) __pure2;
275 
276 /*
277  * Reentrant version of gamma & lgamma; passes signgam back by reference
278  * as the second argument; user must allocate space for signgam.
279  */
280 double	gamma_r(double, int *);
281 double	lgamma_r(double, int *);
282 
283 /*
284  * IEEE Test Vector
285  */
286 double	significand(double);
287 #endif /* __BSD_VISIBLE */
288 
289 /* float versions of ANSI/POSIX functions */
290 #if __ISO_C_VISIBLE >= 1999
291 float	acosf(float);
292 float	asinf(float);
293 float	atanf(float);
294 float	atan2f(float, float);
295 float	cosf(float);
296 float	sinf(float);
297 float	tanf(float);
298 
299 float	coshf(float);
300 float	sinhf(float);
301 float	tanhf(float);
302 
303 float	expf(float);
304 float	expm1f(float);
305 float	frexpf(float, int *);	/* fundamentally !__pure2 */
306 int	ilogbf(float) __pure2;
307 float	ldexpf(float, int);
308 float	log10f(float);
309 float	log1pf(float);
310 float	logf(float);
311 float	modff(float, float *);	/* fundamentally !__pure2 */
312 
313 float	powf(float, float);
314 float	sqrtf(float);
315 
316 float	ceilf(float);
317 float	fabsf(float) __pure2;
318 float	floorf(float);
319 float	fmodf(float, float);
320 float	roundf(float);
321 
322 float	erff(float);
323 float	erfcf(float);
324 float	hypotf(float, float);
325 float	lgammaf(float);
326 
327 float	acoshf(float);
328 float	asinhf(float);
329 float	atanhf(float);
330 float	cbrtf(float);
331 float	logbf(float);
332 float	copysignf(float, float) __pure2;
333 long long llrintf(float);
334 long long llroundf(float);
335 long	lrintf(float);
336 long	lroundf(float);
337 float	nearbyintf(float);
338 float	nextafterf(float, float);
339 float	remainderf(float, float);
340 float	rintf(float);
341 float	scalblnf(float, long);
342 float	scalbnf(float, int);
343 float	truncf(float);
344 
345 float	fdimf(float, float);
346 float	fmaxf(float, float) __pure2;
347 float	fminf(float, float) __pure2;
348 #endif
349 
350 /*
351  * float versions of BSD math library entry points
352  */
353 #if __BSD_VISIBLE
354 float	dremf(float, float);
355 int	finitef(float) __pure2;
356 float	gammaf(float);
357 float	j0f(float);
358 float	j1f(float);
359 float	jnf(int, float);
360 float	scalbf(float, float);
361 float	y0f(float);
362 float	y1f(float);
363 float	ynf(int, float);
364 
365 /*
366  * Float versions of reentrant version of gamma & lgamma; passes
367  * signgam back by reference as the second argument; user must
368  * allocate space for signgam.
369  */
370 float	gammaf_r(float, int *);
371 float	lgammaf_r(float, int *);
372 
373 /*
374  * float version of IEEE Test Vector
375  */
376 float	significandf(float);
377 #endif	/* __BSD_VISIBLE */
378 
379 /*
380  * long double versions of ISO/POSIX math functions
381  */
382 #if __ISO_C_VISIBLE >= 1999
383 #if 0
384 long double	acoshl(long double);
385 long double	acosl(long double);
386 long double	asinhl(long double);
387 long double	asinl(long double);
388 long double	atan2l(long double, long double);
389 long double	atanhl(long double);
390 long double	atanl(long double);
391 long double	cbrtl(long double);
392 #endif
393 long double	ceill(long double);
394 long double	copysignl(long double, long double) __pure2;
395 #if 0
396 long double	coshl(long double);
397 long double	cosl(long double);
398 long double	erfcl(long double);
399 long double	erfl(long double);
400 long double	exp2l(long double);
401 long double	expl(long double);
402 long double	expm1l(long double);
403 #endif
404 long double	fabsl(long double) __pure2;
405 long double	fdiml(long double, long double);
406 long double	floorl(long double);
407 #if 0
408 long double	fmal(long double, long double, long double);
409 #endif
410 long double	fmaxl(long double, long double) __pure2;
411 long double	fminl(long double, long double) __pure2;
412 #if 0
413 long double	fmodl(long double, long double);
414 long double	frexpl(long double value, int *); /* fundamentally !__pure2 */
415 long double	hypotl(long double, long double);
416 #endif
417 int		ilogbl(long double) __pure2;
418 #if 0
419 long double	ldexpl(long double, int);
420 long double	lgammal(long double);
421 long long	llrintl(long double);
422 long long	llroundl(long double);
423 long double	log10l(long double);
424 long double	log1pl(long double);
425 long double	log2l(long double);
426 long double	logbl(long double);
427 long double	logl(long double);
428 long		lrintl(long double);
429 long		lroundl(long double);
430 long double	modfl(long double, long double *); /* fundamentally !__pure2 */
431 long double	nanl(const char *) __pure2;
432 long double	nearbyintl(long double);
433 long double	nextafterl(long double, long double);
434 double		nexttoward(double, long double);
435 float		nexttowardf(float, long double);
436 long double	nexttowardl(long double, long double);
437 long double	powl(long double, long double);
438 long double	remainderl(long double, long double);
439 long double	remquol(long double, long double, int *);
440 long double	rintl(long double);
441 long double	roundl(long double);
442 long double	scalblnl(long double, long);
443 long double	scalbnl(long double, int);
444 long double	sinhl(long double);
445 long double	sinl(long double);
446 long double	sqrtl(long double);
447 long double	tanhl(long double);
448 long double	tanl(long double);
449 long double	tgammal(long double);
450 long double	truncl(long double);
451 #endif
452 
453 #endif /* __ISO_C_VISIBLE >= 1999 */
454 __END_DECLS
455 
456 #endif /* !_MATH_H_ */
457