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