• 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$
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 
75 typedef double __double_t;
76 typedef __double_t double_t;
77 typedef float __float_t;
78 typedef __float_t float_t;
79 
80 #if defined(__USE_BSD)
81 #define HUGE MAXFLOAT
82 #endif
83 
84 extern 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 
92 int __fpclassifyd(double) __attribute_const__;
93 int __fpclassifyf(float) __attribute_const__;
94 int __fpclassifyl(long double) __attribute_const__;
95 int __isfinitef(float) __attribute_const__;
96 int __isfinite(double) __attribute_const__;
97 int __isfinitel(long double) __attribute_const__;
98 int __isinff(float) __attribute_const__;
99 int __isinfl(long double) __attribute_const__;
100 int __isnanf(float) __attribute_const__ __INTRODUCED_IN(21);
101 int __isnanl(long double) __attribute_const__;
102 int __isnormalf(float) __attribute_const__;
103 int __isnormal(double) __attribute_const__;
104 int __isnormall(long double) __attribute_const__;
105 int __signbit(double) __attribute_const__;
106 int __signbitf(float) __attribute_const__;
107 int __signbitl(long double) __attribute_const__;
108 
109 double	acos(double);
110 double	asin(double);
111 double	atan(double);
112 double	atan2(double, double);
113 double	cos(double);
114 double	sin(double);
115 double	tan(double);
116 
117 double	cosh(double);
118 double	sinh(double);
119 double	tanh(double);
120 
121 double	exp(double);
122 double	frexp(double, int *);	/* fundamentally !__attribute_const__ */
123 double	ldexp(double, int);
124 double	log(double);
125 double	log10(double);
126 double	modf(double, double *);	/* fundamentally !__attribute_const__ */
127 
128 double	pow(double, double);
129 double	sqrt(double);
130 
131 double	ceil(double);
132 double	fabs(double) __attribute_const__;
133 double	floor(double);
134 double	fmod(double, double);
135 
136 double	acosh(double);
137 double	asinh(double);
138 double	atanh(double);
139 double	cbrt(double);
140 double	erf(double);
141 double	erfc(double);
142 double	exp2(double);
143 double	expm1(double);
144 double	fma(double, double, double);
145 double	hypot(double, double);
146 int	ilogb(double) __attribute_const__;
147 double	lgamma(double);
148 long long llrint(double);
149 long long llround(double);
150 double	log1p(double);
151 double log2(double) __INTRODUCED_IN(18);
152 double	logb(double);
153 long	lrint(double);
154 long	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  */
167 int(isinf)(double) __attribute_const__ __INTRODUCED_IN(21);
168 int	(isnan)(double) __attribute_const__;
169 
170 double nan(const char*) __attribute_const__ __INTRODUCED_IN_ARM(13) __INTRODUCED_IN_MIPS(13)
171     __INTRODUCED_IN_X86(9);
172 
173 double	nextafter(double, double);
174 double	remainder(double, double);
175 double	remquo(double, double, int*);
176 double	rint(double);
177 
178 double	copysign(double, double) __attribute_const__;
179 double	fdim(double, double);
180 double	fmax(double, double) __attribute_const__;
181 double	fmin(double, double) __attribute_const__;
182 double	nearbyint(double);
183 double	round(double);
184 double scalbln(double, long) __INTRODUCED_IN_X86(18) __VERSIONER_NO_GUARD;
185 double scalbn(double, int);
186 double	tgamma(double);
187 double	trunc(double);
188 
189 float	acosf(float);
190 float	asinf(float);
191 float	atanf(float);
192 float	atan2f(float, float);
193 float	cosf(float);
194 float	sinf(float);
195 float	tanf(float);
196 
197 float	coshf(float);
198 float	sinhf(float);
199 float	tanhf(float);
200 
201 float	exp2f(float);
202 float	expf(float);
203 float	expm1f(float);
204 float	frexpf(float, int *);	/* fundamentally !__attribute_const__ */
205 int	ilogbf(float) __attribute_const__;
206 float	ldexpf(float, int);
207 float	log10f(float);
208 float	log1pf(float);
209 float log2f(float) __INTRODUCED_IN(18);
210 float	logf(float);
211 float	modff(float, float *);	/* fundamentally !__attribute_const__ */
212 
213 float	powf(float, float);
214 float	sqrtf(float);
215 
216 float	ceilf(float);
217 float	fabsf(float) __attribute_const__;
218 float	floorf(float);
219 float	fmodf(float, float);
220 float	roundf(float);
221 
222 float	erff(float);
223 float	erfcf(float);
224 float	hypotf(float, float);
225 float	lgammaf(float);
226 float tgammaf(float) __INTRODUCED_IN_ARM(13) __INTRODUCED_IN_MIPS(13) __INTRODUCED_IN_X86(9);
227 
228 float	acoshf(float);
229 float	asinhf(float);
230 float	atanhf(float);
231 float	cbrtf(float);
232 float	logbf(float);
233 float	copysignf(float, float) __attribute_const__;
234 long long llrintf(float);
235 long long llroundf(float);
236 long	lrintf(float);
237 long	lroundf(float);
238 float nanf(const char*) __attribute_const__ __INTRODUCED_IN_ARM(13) __INTRODUCED_IN_MIPS(13)
239     __INTRODUCED_IN_X86(9);
240 float	nearbyintf(float);
241 float	nextafterf(float, float);
242 float	remainderf(float, float);
243 float	remquof(float, float, int *);
244 float	rintf(float);
245 float	scalblnf(float, long) __INTRODUCED_IN_X86(18) __VERSIONER_NO_GUARD;
246 float scalbnf(float, int);
247 float	truncf(float);
248 
249 float	fdimf(float, float);
250 float	fmaf(float, float, float);
251 float	fmaxf(float, float) __attribute_const__;
252 float	fminf(float, float) __attribute_const__;
253 
254 long double acoshl(long double) __INTRODUCED_IN(21);
255 long double acosl(long double) __INTRODUCED_IN(21);
256 long double asinhl(long double) __INTRODUCED_IN(21);
257 long double asinl(long double) __INTRODUCED_IN(21);
258 long double atan2l(long double, long double) __INTRODUCED_IN(21);
259 long double atanhl(long double) __INTRODUCED_IN(21);
260 long double atanl(long double) __INTRODUCED_IN(21);
261 long double cbrtl(long double) __INTRODUCED_IN(21);
262 long double ceill(long double);
263 long double copysignl(long double, long double) __attribute_const__;
264 long double coshl(long double) __INTRODUCED_IN(21);
265 long double cosl(long double) __INTRODUCED_IN(21);
266 long double erfcl(long double) __INTRODUCED_IN(21);
267 long double erfl(long double) __INTRODUCED_IN(21);
268 long double exp2l(long double) __INTRODUCED_IN(21);
269 long double expl(long double) __INTRODUCED_IN(21);
270 long double expm1l(long double) __INTRODUCED_IN(21);
271 long double fabsl(long double) __attribute_const__;
272 long double fdiml(long double, long double);
273 long double floorl(long double);
274 long double fmal(long double, long double, long double) __INTRODUCED_IN(21) __VERSIONER_NO_GUARD;
275 long double fmaxl(long double, long double) __attribute_const__;
276 long double fminl(long double, long double) __attribute_const__;
277 long double fmodl(long double, long double) __INTRODUCED_IN(21);
278 long double frexpl(long double value, int*)
279     __INTRODUCED_IN(21) __VERSIONER_NO_GUARD; /* fundamentally !__attribute_const__ */
280 long double hypotl(long double, long double) __INTRODUCED_IN(21);
281 int ilogbl(long double) __attribute_const__;
282 long double ldexpl(long double, int);
283 long double lgammal(long double) __INTRODUCED_IN(21);
284 long long llrintl(long double) __INTRODUCED_IN(21);
285 long long llroundl(long double);
286 long double log10l(long double) __INTRODUCED_IN(21);
287 long double log1pl(long double) __INTRODUCED_IN(21);
288 long double log2l(long double) __INTRODUCED_IN(18);
289 long double logbl(long double) __INTRODUCED_IN(18);
290 long double logl(long double) __INTRODUCED_IN(21);
291 long lrintl(long double) __INTRODUCED_IN(21);
292 long lroundl(long double);
293 long double modfl(long double, long double*) __INTRODUCED_IN(21); /* fundamentally !__attribute_const__ */
294 long double nanl(const char*) __attribute_const__ __INTRODUCED_IN(13);
295 long double nearbyintl(long double) __INTRODUCED_IN(21);
296 long double nextafterl(long double, long double) __INTRODUCED_IN(21) __VERSIONER_NO_GUARD;
297 double nexttoward(double, long double) __INTRODUCED_IN(18) __VERSIONER_NO_GUARD;
298 float nexttowardf(float, long double);
299 long double nexttowardl(long double, long double) __INTRODUCED_IN(18) __VERSIONER_NO_GUARD;
300 long double powl(long double, long double) __INTRODUCED_IN(21);
301 long double remainderl(long double, long double) __INTRODUCED_IN(21);
302 long double remquol(long double, long double, int*) __INTRODUCED_IN(21);
303 long double rintl(long double) __INTRODUCED_IN(21);
304 long double roundl(long double);
305 long double scalblnl(long double, long) __INTRODUCED_IN_X86(18) __VERSIONER_NO_GUARD;
306 long double scalbnl(long double, int);
307 long double sinhl(long double) __INTRODUCED_IN(21);
308 long double sinl(long double) __INTRODUCED_IN(21);
309 long double sqrtl(long double) __INTRODUCED_IN(21);
310 long double tanhl(long double) __INTRODUCED_IN(21);
311 long double tanl(long double) __INTRODUCED_IN(21);
312 long double tgammal(long double) __INTRODUCED_IN(21);
313 long double truncl(long double);
314 
315 double j0(double);
316 double j1(double);
317 double jn(int, double);
318 double y0(double);
319 double y1(double);
320 double 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)
339 double gamma(double);
340 double scalb(double, double);
341 double drem(double, double);
342 int finite(double) __attribute_const__;
343 int isnanf(float) __attribute_const__;
344 double gamma_r(double, int*);
345 double lgamma_r(double, int*);
346 double significand(double);
347 long double lgammal_r(long double, int*) __INTRODUCED_IN(23);
348 long double significandl(long double) __INTRODUCED_IN(21);
349 float dremf(float, float);
350 int finitef(float) __attribute_const__;
351 float gammaf(float);
352 float j0f(float);
353 float j1f(float);
354 float jnf(int, float);
355 float scalbf(float, float);
356 float y0f(float);
357 float y1f(float);
358 float ynf(int, float);
359 float gammaf_r(float, int *);
360 float lgammaf_r(float, int *);
361 float 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) */
378 void sincos(double, double*, double*);
379 void sincosf(float, float*, float*);
380 void sincosl(long double, long double*, long double*);
381 #endif
382 
383 __END_DECLS
384 
385 #endif /* !_MATH_H_ */
386