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__BEGIN_DECLS
24
25#define HUGE_VAL	__builtin_huge_val()
26
27#define FP_ILOGB0	(-INT_MAX)
28#define FP_ILOGBNAN	INT_MAX
29
30#define HUGE_VALF	__builtin_huge_valf()
31#define HUGE_VALL	__builtin_huge_vall()
32#define INFINITY	__builtin_inff()
33#define NAN		__builtin_nanf("")
34
35#define MATH_ERRNO	1
36#define MATH_ERREXCEPT	2
37#define math_errhandling	MATH_ERREXCEPT
38
39#if defined(__FP_FAST_FMA)
40#define FP_FAST_FMA 1
41#endif
42#if defined(__FP_FAST_FMAF)
43#define FP_FAST_FMAF 1
44#endif
45#if defined(__FP_FAST_FMAL)
46#define FP_FAST_FMAL 1
47#endif
48
49/* Symbolic constants to classify floating point numbers. */
50#define FP_INFINITE	0x01
51#define FP_NAN		0x02
52#define FP_NORMAL	0x04
53#define FP_SUBNORMAL	0x08
54#define FP_ZERO		0x10
55#define fpclassify(x) \
56    __builtin_fpclassify(FP_NAN, FP_INFINITE, FP_NORMAL, FP_SUBNORMAL, FP_ZERO, x)
57
58#define isfinite(x) __builtin_isfinite(x)
59#define isinf(x) __builtin_isinf(x)
60#define isnan(x) __builtin_isnan(x)
61#define isnormal(x) __builtin_isnormal(x)
62
63#define isgreater(x, y) __builtin_isgreater((x), (y))
64#define isgreaterequal(x, y) __builtin_isgreaterequal((x), (y))
65#define isless(x, y) __builtin_isless((x), (y))
66#define islessequal(x, y) __builtin_islessequal((x), (y))
67#define islessgreater(x, y) __builtin_islessgreater((x), (y))
68#define isunordered(x, y) __builtin_isunordered((x), (y))
69
70#define signbit(x) \
71    ((sizeof(x) == sizeof(float)) ? __builtin_signbitf(x) \
72    : (sizeof(x) == sizeof(double)) ? __builtin_signbit(x) \
73    : __builtin_signbitl(x))
74
75typedef double __double_t;
76typedef __double_t double_t;
77typedef float __float_t;
78typedef __float_t float_t;
79
80#if defined(__USE_BSD)
81#define HUGE MAXFLOAT
82#endif
83
84extern int signgam;
85
86/*
87 * Most of these functions depend on the rounding mode and have the side
88 * effect of raising floating-point exceptions, so they are not declared
89 * as __attribute_const__. In C99, FENV_ACCESS affects the purity of these functions.
90 */
91
92int __fpclassifyd(double) __attribute_const__;
93int __fpclassifyf(float) __attribute_const__;
94int __fpclassifyl(long double) __attribute_const__;
95int __isfinitef(float) __attribute_const__;
96int __isfinite(double) __attribute_const__;
97int __isfinitel(long double) __attribute_const__;
98int __isinff(float) __attribute_const__;
99int __isinfl(long double) __attribute_const__;
100int __isnanf(float) __attribute_const__ __INTRODUCED_IN(21);
101int __isnanl(long double) __attribute_const__;
102int __isnormalf(float) __attribute_const__;
103int __isnormal(double) __attribute_const__;
104int __isnormall(long double) __attribute_const__;
105int __signbit(double) __attribute_const__;
106int __signbitf(float) __attribute_const__;
107int __signbitl(long double) __attribute_const__;
108
109double	acos(double);
110double	asin(double);
111double	atan(double);
112double	atan2(double, double);
113double	cos(double);
114double	sin(double);
115double	tan(double);
116
117double	cosh(double);
118double	sinh(double);
119double	tanh(double);
120
121double	exp(double);
122double	frexp(double, int *);	/* fundamentally !__attribute_const__ */
123double	ldexp(double, int);
124double	log(double);
125double	log10(double);
126double	modf(double, double *);	/* fundamentally !__attribute_const__ */
127
128double	pow(double, double);
129double	sqrt(double);
130
131double	ceil(double);
132double	fabs(double) __attribute_const__;
133double	floor(double);
134double	fmod(double, double);
135
136double	acosh(double);
137double	asinh(double);
138double	atanh(double);
139double	cbrt(double);
140double	erf(double);
141double	erfc(double);
142double	exp2(double);
143double	expm1(double);
144double	fma(double, double, double);
145double	hypot(double, double);
146int	ilogb(double) __attribute_const__;
147double	lgamma(double);
148long long llrint(double);
149long long llround(double);
150double	log1p(double);
151double log2(double) __INTRODUCED_IN(18);
152double	logb(double);
153long	lrint(double);
154long	lround(double);
155
156/*
157 * https://code.google.com/p/android/issues/detail?id=271629
158 * To be fully compliant with C++, we need to not define these (C doesn't
159 * specify them either). Exposing these means that isinf and isnan will have a
160 * return type of int in C++ rather than bool like they're supposed to be.
161 *
162 * GNU libstdc++ 4.9 isn't able to handle a standard compliant C library. Its
163 * <cmath> will `#undef isnan` from math.h and only adds the function overloads
164 * to the std namespace, making it impossible to use both <cmath> (which gets
165 * included by a lot of other standard headers) and ::isnan.
166 */
167int(isinf)(double) __attribute_const__ __INTRODUCED_IN(21);
168int	(isnan)(double) __attribute_const__;
169
170double nan(const char*) __attribute_const__ __INTRODUCED_IN_ARM(13) __INTRODUCED_IN_MIPS(13)
171    __INTRODUCED_IN_X86(9);
172
173double	nextafter(double, double);
174double	remainder(double, double);
175double	remquo(double, double, int*);
176double	rint(double);
177
178double	copysign(double, double) __attribute_const__;
179double	fdim(double, double);
180double	fmax(double, double) __attribute_const__;
181double	fmin(double, double) __attribute_const__;
182double	nearbyint(double);
183double	round(double);
184double scalbln(double, long) __INTRODUCED_IN_X86(18) __VERSIONER_NO_GUARD;
185double scalbn(double, int);
186double	tgamma(double);
187double	trunc(double);
188
189float	acosf(float);
190float	asinf(float);
191float	atanf(float);
192float	atan2f(float, float);
193float	cosf(float);
194float	sinf(float);
195float	tanf(float);
196
197float	coshf(float);
198float	sinhf(float);
199float	tanhf(float);
200
201float	exp2f(float);
202float	expf(float);
203float	expm1f(float);
204float	frexpf(float, int *);	/* fundamentally !__attribute_const__ */
205int	ilogbf(float) __attribute_const__;
206float	ldexpf(float, int);
207float	log10f(float);
208float	log1pf(float);
209float log2f(float) __INTRODUCED_IN(18);
210float	logf(float);
211float	modff(float, float *);	/* fundamentally !__attribute_const__ */
212
213float	powf(float, float);
214float	sqrtf(float);
215
216float	ceilf(float);
217float	fabsf(float) __attribute_const__;
218float	floorf(float);
219float	fmodf(float, float);
220float	roundf(float);
221
222float	erff(float);
223float	erfcf(float);
224float	hypotf(float, float);
225float	lgammaf(float);
226float tgammaf(float) __INTRODUCED_IN_ARM(13) __INTRODUCED_IN_MIPS(13) __INTRODUCED_IN_X86(9);
227
228float	acoshf(float);
229float	asinhf(float);
230float	atanhf(float);
231float	cbrtf(float);
232float	logbf(float);
233float	copysignf(float, float) __attribute_const__;
234long long llrintf(float);
235long long llroundf(float);
236long	lrintf(float);
237long	lroundf(float);
238float nanf(const char*) __attribute_const__ __INTRODUCED_IN_ARM(13) __INTRODUCED_IN_MIPS(13)
239    __INTRODUCED_IN_X86(9);
240float	nearbyintf(float);
241float	nextafterf(float, float);
242float	remainderf(float, float);
243float	remquof(float, float, int *);
244float	rintf(float);
245float	scalblnf(float, long) __INTRODUCED_IN_X86(18) __VERSIONER_NO_GUARD;
246float scalbnf(float, int);
247float	truncf(float);
248
249float	fdimf(float, float);
250float	fmaf(float, float, float);
251float	fmaxf(float, float) __attribute_const__;
252float	fminf(float, float) __attribute_const__;
253
254long double acoshl(long double) __INTRODUCED_IN(21);
255long double acosl(long double) __INTRODUCED_IN(21);
256long double asinhl(long double) __INTRODUCED_IN(21);
257long double asinl(long double) __INTRODUCED_IN(21);
258long double atan2l(long double, long double) __INTRODUCED_IN(21);
259long double atanhl(long double) __INTRODUCED_IN(21);
260long double atanl(long double) __INTRODUCED_IN(21);
261long double cbrtl(long double) __INTRODUCED_IN(21);
262long double ceill(long double);
263long double copysignl(long double, long double) __attribute_const__;
264long double coshl(long double) __INTRODUCED_IN(21);
265long double cosl(long double) __INTRODUCED_IN(21);
266long double erfcl(long double) __INTRODUCED_IN(21);
267long double erfl(long double) __INTRODUCED_IN(21);
268long double exp2l(long double) __INTRODUCED_IN(21);
269long double expl(long double) __INTRODUCED_IN(21);
270long double expm1l(long double) __INTRODUCED_IN(21);
271long double fabsl(long double) __attribute_const__;
272long double fdiml(long double, long double);
273long double floorl(long double);
274long double fmal(long double, long double, long double) __INTRODUCED_IN(21) __VERSIONER_NO_GUARD;
275long double fmaxl(long double, long double) __attribute_const__;
276long double fminl(long double, long double) __attribute_const__;
277long double fmodl(long double, long double) __INTRODUCED_IN(21);
278long double frexpl(long double value, int*)
279    __INTRODUCED_IN(21) __VERSIONER_NO_GUARD; /* fundamentally !__attribute_const__ */
280long double hypotl(long double, long double) __INTRODUCED_IN(21);
281int ilogbl(long double) __attribute_const__;
282long double ldexpl(long double, int);
283long double lgammal(long double) __INTRODUCED_IN(21);
284long long llrintl(long double) __INTRODUCED_IN(21);
285long long llroundl(long double);
286long double log10l(long double) __INTRODUCED_IN(21);
287long double log1pl(long double) __INTRODUCED_IN(21);
288long double log2l(long double) __INTRODUCED_IN(18);
289long double logbl(long double) __INTRODUCED_IN(18);
290long double logl(long double) __INTRODUCED_IN(21);
291long lrintl(long double) __INTRODUCED_IN(21);
292long lroundl(long double);
293long double modfl(long double, long double*) __INTRODUCED_IN(21); /* fundamentally !__attribute_const__ */
294long double nanl(const char*) __attribute_const__ __INTRODUCED_IN(13);
295long double nearbyintl(long double) __INTRODUCED_IN(21);
296long double nextafterl(long double, long double) __INTRODUCED_IN(21) __VERSIONER_NO_GUARD;
297double nexttoward(double, long double) __INTRODUCED_IN(18) __VERSIONER_NO_GUARD;
298float nexttowardf(float, long double);
299long double nexttowardl(long double, long double) __INTRODUCED_IN(18) __VERSIONER_NO_GUARD;
300long double powl(long double, long double) __INTRODUCED_IN(21);
301long double remainderl(long double, long double) __INTRODUCED_IN(21);
302long double remquol(long double, long double, int*) __INTRODUCED_IN(21);
303long double rintl(long double) __INTRODUCED_IN(21);
304long double roundl(long double);
305long double scalblnl(long double, long) __INTRODUCED_IN_X86(18) __VERSIONER_NO_GUARD;
306long double scalbnl(long double, int);
307long double sinhl(long double) __INTRODUCED_IN(21);
308long double sinl(long double) __INTRODUCED_IN(21);
309long double sqrtl(long double) __INTRODUCED_IN(21);
310long double tanhl(long double) __INTRODUCED_IN(21);
311long double tanl(long double) __INTRODUCED_IN(21);
312long double tgammal(long double) __INTRODUCED_IN(21);
313long double truncl(long double);
314
315double j0(double);
316double j1(double);
317double jn(int, double);
318double y0(double);
319double y1(double);
320double yn(int, double);
321
322#define M_E		2.7182818284590452354	/* e */
323#define M_LOG2E		1.4426950408889634074	/* log 2e */
324#define M_LOG10E	0.43429448190325182765	/* log 10e */
325#define M_LN2		0.69314718055994530942	/* log e2 */
326#define M_LN10		2.30258509299404568402	/* log e10 */
327#define M_PI		3.14159265358979323846	/* pi */
328#define M_PI_2		1.57079632679489661923	/* pi/2 */
329#define M_PI_4		0.78539816339744830962	/* pi/4 */
330#define M_1_PI		0.31830988618379067154	/* 1/pi */
331#define M_2_PI		0.63661977236758134308	/* 2/pi */
332#define M_2_SQRTPI	1.12837916709551257390	/* 2/sqrt(pi) */
333#define M_SQRT2		1.41421356237309504880	/* sqrt(2) */
334#define M_SQRT1_2	0.70710678118654752440	/* 1/sqrt(2) */
335
336#define MAXFLOAT	((float)3.40282346638528860e+38)
337
338#if defined(__USE_BSD) || defined(__USE_GNU)
339double gamma(double);
340double scalb(double, double);
341double drem(double, double);
342int finite(double) __attribute_const__;
343int isnanf(float) __attribute_const__;
344double gamma_r(double, int*);
345double lgamma_r(double, int*);
346double significand(double);
347long double lgammal_r(long double, int*) __INTRODUCED_IN(23);
348long double significandl(long double) __INTRODUCED_IN(21);
349float dremf(float, float);
350int finitef(float) __attribute_const__;
351float gammaf(float);
352float j0f(float);
353float j1f(float);
354float jnf(int, float);
355float scalbf(float, float);
356float y0f(float);
357float y1f(float);
358float ynf(int, float);
359float gammaf_r(float, int *);
360float lgammaf_r(float, int *);
361float significandf(float);
362#endif
363
364#if defined(__USE_GNU)
365#define M_El            2.718281828459045235360287471352662498L /* e */
366#define M_LOG2El        1.442695040888963407359924681001892137L /* log 2e */
367#define M_LOG10El       0.434294481903251827651128918916605082L /* log 10e */
368#define M_LN2l          0.693147180559945309417232121458176568L /* log e2 */
369#define M_LN10l         2.302585092994045684017991454684364208L /* log e10 */
370#define M_PIl           3.141592653589793238462643383279502884L /* pi */
371#define M_PI_2l         1.570796326794896619231321691639751442L /* pi/2 */
372#define M_PI_4l         0.785398163397448309615660845819875721L /* pi/4 */
373#define M_1_PIl         0.318309886183790671537767526745028724L /* 1/pi */
374#define M_2_PIl         0.636619772367581343075535053490057448L /* 2/pi */
375#define M_2_SQRTPIl     1.128379167095512573896158903121545172L /* 2/sqrt(pi) */
376#define M_SQRT2l        1.414213562373095048801688724209698079L /* sqrt(2) */
377#define M_SQRT1_2l      0.707106781186547524400844362104849039L /* 1/sqrt(2) */
378void sincos(double, double*, double*);
379void sincosf(float, float*, float*);
380void sincosl(long double, long double*, long double*);
381#endif
382
383__END_DECLS
384
385#endif /* !_MATH_H_ */
386