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