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