xref: /aosp_15_r20/bionic/libc/include/math.h (revision 8d67ca893c1523eb926b9080dbe4e2ffd2a27ba1)
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) __builtin_signbit(x)
72 
73 double acos(double __x);
74 float acosf(float __x);
75 long double acosl(long double __x);
76 
77 double asin(double __x);
78 float asinf(float __x);
79 long double asinl(long double __x);
80 
81 double atan(double __x);
82 float atanf(float __x);
83 long double atanl(long double __x);
84 
85 double atan2(double __y, double __x);
86 float atan2f(float __y, float __x);
87 long double atan2l(long double __y, long double __x);
88 
89 double cos(double __x);
90 float cosf(float __x);
91 long double cosl(long double __x);
92 
93 double sin(double __x);
94 float sinf(float __x);
95 long double sinl(long double __x);
96 
97 double tan(double __x);
98 float tanf(float __x);
99 long double tanl(long double __x);
100 
101 double acosh(double __x);
102 float acoshf(float __x);
103 long double acoshl(long double __x);
104 
105 double asinh(double __x);
106 float asinhf(float __x);
107 long double asinhl(long double __x);
108 
109 double atanh(double __x);
110 float atanhf(float __x);
111 long double atanhl(long double __x);
112 
113 double cosh(double __x);
114 float coshf(float __x);
115 long double coshl(long double __x);
116 
117 double sinh(double __x);
118 float sinhf(float __x);
119 long double sinhl(long double __x);
120 
121 double tanh(double __x);
122 float tanhf(float __x);
123 long double tanhl(long double __x);
124 
125 double exp(double __x);
126 float expf(float __x);
127 long double expl(long double __x);
128 
129 double exp2(double __x);
130 float exp2f(float __x);
131 long double exp2l(long double __x);
132 
133 double expm1(double __x);
134 float expm1f(float __x);
135 long double expm1l(long double __x);
136 
137 double frexp(double __x, int* _Nonnull __exponent);
138 float frexpf(float __x, int* _Nonnull __exponent);
139 long double frexpl(long double __x, int* _Nonnull __exponent);
140 
141 int ilogb(double __x) __attribute_const__;
142 int ilogbf(float __x) __attribute_const__;
143 int ilogbl(long double __x) __attribute_const__;
144 
145 double ldexp(double __x, int __exponent);
146 float ldexpf(float __x, int __exponent);
147 long double ldexpl(long double __x, int __exponent);
148 
149 double log(double __x);
150 float logf(float __x);
151 long double logl(long double __x);
152 
153 double log10(double __x);
154 float log10f(float __x);
155 long double log10l(long double __x);
156 
157 double log1p(double __x);
158 float log1pf(float __x);
159 long double log1pl(long double __x);
160 
161 double log2(double __x);
162 float log2f(float __x);
163 long double log2l(long double __x);
164 
165 double logb(double __x);
166 float logbf(float __x);
167 long double logbl(long double __x);
168 
169 double modf(double __x, double* _Nonnull __integral_part);
170 float modff(float __x, float* _Nonnull __integral_part);
171 long double modfl(long double __x, long double* _Nonnull __integral_part);
172 
173 double scalbn(double __x, int __exponent);
174 float scalbnf(float __x, int __exponent);
175 long double scalbnl(long double __x, int __exponent);
176 
177 double scalbln(double __x, long __exponent);
178 float scalblnf(float __x, long __exponent);
179 long double scalblnl(long double __x, long __exponent);
180 
181 double cbrt(double __x);
182 float cbrtf(float __x);
183 long double cbrtl(long double __x);
184 
185 double fabs(double __x) __attribute_const__;
186 float fabsf(float __x) __attribute_const__;
187 long double fabsl(long double __x) __attribute_const__;
188 
189 double hypot(double __x, double __y);
190 float hypotf(float __x, float __y);
191 long double hypotl(long double __x, long double __y);
192 
193 double pow(double __x, double __y);
194 float powf(float __x, float __y);
195 long double powl(long double __x, long double __y);
196 
197 double sqrt(double __x);
198 float sqrtf(float __x);
199 long double sqrtl(long double __x);
200 
201 double erf(double __x);
202 float erff(float __x);
203 long double erfl(long double __x);
204 
205 double erfc(double __x);
206 float erfcf(float __x);
207 long double erfcl(long double __x);
208 
209 double lgamma(double __x);
210 float lgammaf(float __x);
211 long double lgammal(long double __x);
212 
213 double tgamma(double __x);
214 float tgammaf(float __x);
215 long double tgammal(long double __x);
216 
217 double ceil(double __x);
218 float ceilf(float __x);
219 long double ceill(long double __x);
220 
221 double floor(double __x);
222 float floorf(float __x);
223 long double floorl(long double __x);
224 
225 double nearbyint(double __x);
226 float nearbyintf(float __x);
227 long double nearbyintl(long double __x);
228 
229 double rint(double __x);
230 float rintf(float __x);
231 long double rintl(long double __x);
232 
233 long lrint(double __x);
234 long lrintf(float __x);
235 long lrintl(long double __x);
236 
237 long long llrint(double __x);
238 long long llrintf(float __x);
239 long long llrintl(long double __x);
240 
241 double round(double __x);
242 float roundf(float __x);
243 long double roundl(long double __x);
244 
245 long lround(double __x);
246 long lroundf(float __x);
247 long lroundl(long double __x);
248 
249 long long llround(double __x);
250 long long llroundf(float __x);
251 long long llroundl(long double __x);
252 
253 double trunc(double __x);
254 float truncf(float __x);
255 long double truncl(long double __x);
256 
257 double fmod(double __x, double __y);
258 float fmodf(float __x, float __y);
259 long double fmodl(long double __x, long double __y);
260 
261 double remainder(double __x, double __y);
262 float remainderf(float __x, float __y);
263 long double remainderl(long double __x, long double __y);
264 
265 double remquo(double __x, double __y, int* _Nonnull __quotient_bits);
266 float remquof(float __x, float __y, int* _Nonnull __quotient_bits);
267 long double remquol(long double __x, long double __y, int* _Nonnull __quotient_bits);
268 
269 double copysign(double __value, double __sign) __attribute_const__;
270 float copysignf(float __value, float __sign) __attribute_const__;
271 long double copysignl(long double __value, long double __sign) __attribute_const__;
272 
273 double nan(const char* _Nonnull __kind) __attribute_const__;
274 float nanf(const char* _Nonnull __kind) __attribute_const__;
275 long double nanl(const char* _Nonnull __kind) __attribute_const__;
276 
277 double nextafter(double __x, double __y);
278 float nextafterf(float __x, float __y);
279 long double nextafterl(long double __x, long double __y);
280 
281 double nexttoward(double __x, long double __y);
282 float nexttowardf(float __x, long double __y);
283 long double nexttowardl(long double __x, long double __y);
284 
285 double fdim(double __x, double __y);
286 float fdimf(float __x, float __y);
287 long double fdiml(long double __x, long double __y);
288 
289 double fmax(double __x, double __y) __attribute_const__;
290 float fmaxf(float __x, float __y) __attribute_const__;
291 long double fmaxl(long double __x, long double __y) __attribute_const__;
292 
293 double fmin(double __x, double __y) __attribute_const__;
294 float fminf(float __x, float __y) __attribute_const__;
295 long double fminl(long double __x, long double __y) __attribute_const__;
296 
297 double fma(double __x, double __y, double __z);
298 float fmaf(float __x, float __y, float __z);
299 long double fmal(long double __x, long double __y, long double __z);
300 
301 #define isgreater(x, y) __builtin_isgreater((x), (y))
302 #define isgreaterequal(x, y) __builtin_isgreaterequal((x), (y))
303 #define isless(x, y) __builtin_isless((x), (y))
304 #define islessequal(x, y) __builtin_islessequal((x), (y))
305 #define islessgreater(x, y) __builtin_islessgreater((x), (y))
306 #define isunordered(x, y) __builtin_isunordered((x), (y))
307 
308 /* POSIX extensions. */
309 
310 extern int signgam;
311 
312 double j0(double __x);
313 double j1(double __x);
314 double jn(int __n, double __x);
315 double y0(double __x);
316 double y1(double __x);
317 double yn(int __n, double __x);
318 
319 #define M_E		2.7182818284590452354	/* e */
320 #define M_LOG2E		1.4426950408889634074	/* log 2e */
321 #define M_LOG10E	0.43429448190325182765	/* log 10e */
322 #define M_LN2		0.69314718055994530942	/* log e2 */
323 #define M_LN10		2.30258509299404568402	/* log e10 */
324 #define M_PI		3.14159265358979323846	/* pi */
325 #define M_PI_2		1.57079632679489661923	/* pi/2 */
326 #define M_PI_4		0.78539816339744830962	/* pi/4 */
327 #define M_1_PI		0.31830988618379067154	/* 1/pi */
328 #define M_2_PI		0.63661977236758134308	/* 2/pi */
329 #define M_2_SQRTPI	1.12837916709551257390	/* 2/sqrt(pi) */
330 #define M_SQRT2		1.41421356237309504880	/* sqrt(2) */
331 #define M_SQRT1_2	0.70710678118654752440	/* 1/sqrt(2) */
332 
333 #define MAXFLOAT	((float)3.40282346638528860e+38)
334 
335 /* BSD extensions. */
336 
337 #if defined(__USE_BSD)
338 #define HUGE MAXFLOAT
339 #endif
340 
341 /* Extensions in both BSD and GNU. */
342 
343 #if defined(__USE_BSD) || defined(__USE_GNU)
344 double gamma(double __x);
345 double scalb(double __x, double __exponent);
346 double drem(double __x, double __y);
347 int finite(double __x) __attribute_const__;
348 int isinff(float __x) __attribute_const__;
349 int isnanf(float __x) __attribute_const__;
350 double gamma_r(double __x, int* _Nonnull __sign);
351 double lgamma_r(double __x, int* _Nonnull __sign);
352 double significand(double __x);
353 
354 #if __BIONIC_AVAILABILITY_GUARD(23)
355 long double lgammal_r(long double __x, int* _Nonnull __sign) __INTRODUCED_IN(23);
356 #endif /* __BIONIC_AVAILABILITY_GUARD(23) */
357 
358 long double significandl(long double __x);
359 float dremf(float __x, float __y);
360 int finitef(float __x) __attribute_const__;
361 float gammaf(float __x);
362 float j0f(float __x);
363 float j1f(float __x);
364 float jnf(int __n, float __x);
365 float scalbf(float __x, float __exponent);
366 float y0f(float __x);
367 float y1f(float __x);
368 float ynf(int __n, float __x);
369 float gammaf_r(float __x, int* _Nonnull __sign);
370 float lgammaf_r(float __x, int* _Nonnull __sign);
371 float significandf(float __x);
372 void sincos(double __x, double* _Nonnull __sin, double* _Nonnull __cos);
373 void sincosf(float __x, float* _Nonnull __sin, float* _Nonnull __cos);
374 void sincosl(long double __x, long double* _Nonnull __sin, long double* _Nonnull __cos);
375 #endif
376 
377 /* GNU extensions. */
378 
379 #if defined(__USE_GNU)
380 #define M_El            2.718281828459045235360287471352662498L /* e */
381 #define M_LOG2El        1.442695040888963407359924681001892137L /* log 2e */
382 #define M_LOG10El       0.434294481903251827651128918916605082L /* log 10e */
383 #define M_LN2l          0.693147180559945309417232121458176568L /* log e2 */
384 #define M_LN10l         2.302585092994045684017991454684364208L /* log e10 */
385 #define M_PIl           3.141592653589793238462643383279502884L /* pi */
386 #define M_PI_2l         1.570796326794896619231321691639751442L /* pi/2 */
387 #define M_PI_4l         0.785398163397448309615660845819875721L /* pi/4 */
388 #define M_1_PIl         0.318309886183790671537767526745028724L /* 1/pi */
389 #define M_2_PIl         0.636619772367581343075535053490057448L /* 2/pi */
390 #define M_2_SQRTPIl     1.128379167095512573896158903121545172L /* 2/sqrt(pi) */
391 #define M_SQRT2l        1.414213562373095048801688724209698079L /* sqrt(2) */
392 #define M_SQRT1_2l      0.707106781186547524400844362104849039L /* 1/sqrt(2) */
393 int isinfl(long double __x) __attribute_const__;
394 int isnanl(long double __x) __attribute_const__;
395 #endif
396 
397 __END_DECLS
398