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