blob: d3b4a333c20b8375ed77d8b6e0fd56bbb6721dd9 [file] [log] [blame]
The Android Open Source Project1dc9e472009-03-03 19:28:35 -08001/*
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/*
Elliott Hughesfee514e2020-09-17 11:57:50 -070013 * Originally based on fdlibm.h 5.1 via FreeBSD.
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080014 */
15
Elliott Hughesfee514e2020-09-17 11:57:50 -070016#pragma once
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080017
18#include <sys/cdefs.h>
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080019#include <limits.h>
20
Elliott Hughesde9ac712014-05-19 16:58:52 -070021__BEGIN_DECLS
Elliott Hughesde9ac712014-05-19 16:58:52 -070022
Elliott Hughes50cda382017-09-14 15:30:08 -070023/* C11. */
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080024
Elliott Hughes50cda382017-09-14 15:30:08 -070025typedef double __double_t;
26typedef __double_t double_t;
27typedef float __float_t;
28typedef __float_t float_t;
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080029
Elliott Hughes50cda382017-09-14 15:30:08 -070030#define HUGE_VAL __builtin_huge_val()
31#define HUGE_VALF __builtin_huge_valf()
32#define HUGE_VALL __builtin_huge_vall()
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080033
Elliott Hughes50cda382017-09-14 15:30:08 -070034#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
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080043
Elliott Hughesb6622802015-08-14 14:04:30 -070044#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
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080052#endif
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080053
Elliott Hughes50cda382017-09-14 15:30:08 -070054#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)
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080062
Elliott Hughesb6622802015-08-14 14:04:30 -070063#define isfinite(x) __builtin_isfinite(x)
Elliott Hughes50cda382017-09-14 15:30:08 -070064
Elliott Hughesb6622802015-08-14 14:04:30 -070065#define isinf(x) __builtin_isinf(x)
Elliott Hughes50cda382017-09-14 15:30:08 -070066
Elliott Hughesb6622802015-08-14 14:04:30 -070067#define isnan(x) __builtin_isnan(x)
Elliott Hughes50cda382017-09-14 15:30:08 -070068
Elliott Hughesb6622802015-08-14 14:04:30 -070069#define isnormal(x) __builtin_isnormal(x)
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080070
Elliott Hughes50cda382017-09-14 15:30:08 -070071#define signbit(x) \
72 ((sizeof(x) == sizeof(float)) ? __builtin_signbitf(x) \
73 : (sizeof(x) == sizeof(double)) ? __builtin_signbit(x) \
74 : __builtin_signbitl(x))
75
76double acos(double __x);
77float acosf(float __x);
78long double acosl(long double __x) __RENAME_LDBL(acos, 3, 21);
79
80double asin(double __x);
81float asinf(float __x);
82long double asinl(long double __x) __RENAME_LDBL(asin, 3, 21);
83
84double atan(double __x);
85float atanf(float __x);
86long double atanl(long double __x) __RENAME_LDBL(atan, 3, 21);
87
88double atan2(double __y, double __x);
89float atan2f(float __y, float __x);
90long double atan2l(long double __y, long double __x) __RENAME_LDBL(atan2, 3, 21);
91
92double cos(double __x);
93float cosf(float __x);
94long double cosl(long double __x) __RENAME_LDBL(cos, 3, 21);
95
96double sin(double __x);
97float sinf(float __x);
98long double sinl(long double __x) __RENAME_LDBL(sin, 3, 21);
99
100double tan(double __x);
101float tanf(float __x);
102long double tanl(long double __x) __RENAME_LDBL(tan, 3, 21);
103
104double acosh(double __x);
105float acoshf(float __x);
106long double acoshl(long double __x) __RENAME_LDBL(acosh, 3, 21);
107
108double asinh(double __x);
109float asinhf(float __x);
110long double asinhl(long double __x) __RENAME_LDBL(asinh, 3, 21);
111
112double atanh(double __x);
113float atanhf(float __x);
114long double atanhl(long double __x) __RENAME_LDBL(atanh, 3, 21);
115
116double cosh(double __x);
117float coshf(float __x);
118long double coshl(long double __x) __RENAME_LDBL(cosh, 3, 21);
119
120double sinh(double __x);
121float sinhf(float __x);
122long double sinhl(long double __x) __RENAME_LDBL(sinh, 3, 21);
123
124double tanh(double __x);
125float tanhf(float __x);
126long double tanhl(long double __x) __RENAME_LDBL(tanh, 3, 21);
127
128double exp(double __x);
129float expf(float __x);
130long double expl(long double __x) __RENAME_LDBL(exp, 3, 21);
131
132double exp2(double __x);
133float exp2f(float __x);
134long double exp2l(long double __x) __RENAME_LDBL(exp2, 3, 21);
135
136double expm1(double __x);
137float expm1f(float __x);
138long double expm1l(long double __x) __RENAME_LDBL(expm1, 3, 21);
139
zijunzhao195b90b2023-02-08 02:00:09 +0000140double frexp(double __x, int* _Nonnull __exponent);
141float frexpf(float __x, int* _Nonnull __exponent);
142long double frexpl(long double __x, int* _Nonnull __exponent) __RENAME_LDBL(frexp, 3, 21);
Elliott Hughes50cda382017-09-14 15:30:08 -0700143
144int ilogb(double __x) __attribute_const__;
145int ilogbf(float __x) __attribute_const__;
Elliott Hughesd6541c22017-09-18 16:22:32 -0700146int ilogbl(long double __x) __RENAME_LDBL(ilogb, 3, 3) __attribute_const__;
Elliott Hughes50cda382017-09-14 15:30:08 -0700147
148double ldexp(double __x, int __exponent);
149float ldexpf(float __x, int __exponent);
150long double ldexpl(long double __x, int __exponent) __RENAME_LDBL(ldexp, 3, 3);
151
152double log(double __x);
153float logf(float __x);
154long double logl(long double __x) __RENAME_LDBL(log, 3, 21);
155
156double log10(double __x);
157float log10f(float __x);
158long double log10l(long double __x) __RENAME_LDBL(log10, 3, 21);
159
160double log1p(double __x);
161float log1pf(float __x);
162long double log1pl(long double __x) __RENAME_LDBL(log1p, 3, 21);
163
164double log2(double __x) __INTRODUCED_IN(18);
165float log2f(float __x) __INTRODUCED_IN(18);
166long double log2l(long double __x) __RENAME_LDBL(log2, 18, 18);
167
168double logb(double __x);
169float logbf(float __x);
170long double logbl(long double __x) __RENAME_LDBL(logb, 3, 18);
171
zijunzhao195b90b2023-02-08 02:00:09 +0000172double modf(double __x, double* _Nonnull __integral_part);
173float modff(float __x, float* _Nonnull __integral_part);
174long double modfl(long double __x, long double* _Nonnull __integral_part) __RENAME_LDBL(modf, 3, 21);
Elliott Hughes50cda382017-09-14 15:30:08 -0700175
176double scalbn(double __x, int __exponent);
177float scalbnf(float __x, int __exponent);
178long double scalbnl(long double __x, int __exponent) __RENAME_LDBL(scalbn, 3, 3);
179
Elliott Hughese17ebfd2023-05-26 13:00:51 -0700180double scalbln(double __x, long __exponent);
181float scalblnf(float __x, long __exponent);
182long double scalblnl(long double __x, long __exponent) __RENAME_LDBL(scalbln, 9, 18);
Elliott Hughes50cda382017-09-14 15:30:08 -0700183
184double cbrt(double __x);
185float cbrtf(float __x);
186long double cbrtl(long double __x) __RENAME_LDBL(cbrt, 3, 21);
187
188double fabs(double __x) __attribute_const__;
189float fabsf(float __x) __attribute_const__;
Elliott Hughesd6541c22017-09-18 16:22:32 -0700190long double fabsl(long double __x) __RENAME_LDBL(fabs, 3, 3) __attribute_const__;
Elliott Hughes50cda382017-09-14 15:30:08 -0700191
192double hypot(double __x, double __y);
193float hypotf(float __x, float __y);
194long double hypotl(long double __x, long double __y) __RENAME_LDBL(hypot, 3, 21);
195
196double pow(double __x, double __y);
197float powf(float __x, float __y);
198long double powl(long double __x, long double __y) __RENAME_LDBL(pow, 3, 21);
199
200double sqrt(double __x);
201float sqrtf(float __x);
202long double sqrtl(long double __x) __RENAME_LDBL(sqrt, 3, 21);
203
204double erf(double __x);
205float erff(float __x);
206long double erfl(long double __x) __RENAME_LDBL(erf, 3, 21);
207
208double erfc(double __x);
209float erfcf(float __x);
210long double erfcl(long double __x) __RENAME_LDBL(erfc, 3, 21);
211
212double lgamma(double __x);
213float lgammaf(float __x);
214long double lgammal(long double __x) __RENAME_LDBL(lgamma, 3, 21);
215
216double tgamma(double __x);
Elliott Hughesf106a392019-10-03 16:09:04 -0700217float tgammaf(float __x);
Elliott Hughes50cda382017-09-14 15:30:08 -0700218long double tgammal(long double __x) __RENAME_LDBL(tgamma, 3, 21);
219
220double ceil(double __x);
221float ceilf(float __x);
222long double ceill(long double __x) __RENAME_LDBL(ceil, 3, 3);
223
224double floor(double __x);
225float floorf(float __x);
226long double floorl(long double __x) __RENAME_LDBL(floor, 3, 3);
227
228double nearbyint(double __x);
229float nearbyintf(float __x);
230long double nearbyintl(long double __x) __RENAME_LDBL(nearbyint, 3, 21);
231
232double rint(double __x);
233float rintf(float __x);
234long double rintl(long double __x) __RENAME_LDBL(rint, 3, 21);
235
236long lrint(double __x);
237long lrintf(float __x);
238long lrintl(long double __x) __RENAME_LDBL(lrint, 3, 21);
239
240long long llrint(double __x);
241long long llrintf(float __x);
242long long llrintl(long double __x) __RENAME_LDBL(llrint, 3, 21);
243
244double round(double __x);
245float roundf(float __x);
246long double roundl(long double __x) __RENAME_LDBL(roundl, 3, 3);
247
248long lround(double __x);
249long lroundf(float __x);
250long lroundl(long double __x) __RENAME_LDBL(lround, 3, 3);
251
252long long llround(double __x);
253long long llroundf(float __x);
254long long llroundl(long double __x) __RENAME_LDBL(llround, 3, 3);
255
256double trunc(double __x);
257float truncf(float __x);
258long double truncl(long double __x) __RENAME_LDBL(trunc, 3, 3);
259
260double fmod(double __x, double __y);
261float fmodf(float __x, float __y);
262long double fmodl(long double __x, long double __y) __RENAME_LDBL(fmod, 3, 21);
263
264double remainder(double __x, double __y);
265float remainderf(float __x, float __y);
266long double remainderl(long double __x, long double __y) __RENAME_LDBL(remainder, 3, 21);
267
zijunzhao195b90b2023-02-08 02:00:09 +0000268double remquo(double __x, double __y, int* _Nonnull __quotient_bits);
269float remquof(float __x, float __y, int* _Nonnull __quotient_bits);
270long double remquol(long double __x, long double __y, int* _Nonnull __quotient_bits) __RENAME_LDBL(remquo, 3, 21);
Elliott Hughes50cda382017-09-14 15:30:08 -0700271
272double copysign(double __value, double __sign) __attribute_const__;
273float copysignf(float __value, float __sign) __attribute_const__;
Elliott Hughesd6541c22017-09-18 16:22:32 -0700274long double copysignl(long double __value, long double __sign) __RENAME_LDBL(copysign, 3, 3) __attribute_const__;
Elliott Hughes50cda382017-09-14 15:30:08 -0700275
zijunzhao195b90b2023-02-08 02:00:09 +0000276double nan(const char* _Nonnull __kind) __attribute_const__;
277float nanf(const char* _Nonnull __kind) __attribute_const__;
278long double nanl(const char* _Nonnull __kind) __RENAME_LDBL(nan, 13, 13) __attribute_const__;
Elliott Hughes50cda382017-09-14 15:30:08 -0700279
280double nextafter(double __x, double __y);
281float nextafterf(float __x, float __y);
Dan Alberteae41f82021-01-29 16:24:06 -0800282long double nextafterl(long double __x, long double __y) __RENAME_LDBL_NO_GUARD_FOR_NDK(nextafter, 3, 21);
Elliott Hughes50cda382017-09-14 15:30:08 -0700283
Elliott Hughese17ebfd2023-05-26 13:00:51 -0700284double nexttoward(double __x, long double __y);
Elliott Hughes50cda382017-09-14 15:30:08 -0700285float nexttowardf(float __x, long double __y);
Dan Alberteae41f82021-01-29 16:24:06 -0800286long double nexttowardl(long double __x, long double __y) __RENAME_LDBL_NO_GUARD_FOR_NDK(nexttoward, 18, 18);
Elliott Hughes50cda382017-09-14 15:30:08 -0700287
288double fdim(double __x, double __y);
289float fdimf(float __x, float __y);
290long double fdiml(long double __x, long double __y) __RENAME_LDBL(fdim, 3, 3);
291
292double fmax(double __x, double __y) __attribute_const__;
293float fmaxf(float __x, float __y) __attribute_const__;
Elliott Hughesd6541c22017-09-18 16:22:32 -0700294long double fmaxl(long double __x, long double __y) __RENAME_LDBL(fmax, 3, 3) __attribute_const__;
Elliott Hughes50cda382017-09-14 15:30:08 -0700295
296double fmin(double __x, double __y) __attribute_const__;
297float fminf(float __x, float __y) __attribute_const__;
Elliott Hughesd6541c22017-09-18 16:22:32 -0700298long double fminl(long double __x, long double __y) __RENAME_LDBL(fmin, 3, 3) __attribute_const__;
Elliott Hughes50cda382017-09-14 15:30:08 -0700299
300double fma(double __x, double __y, double __z);
301float fmaf(float __x, float __y, float __z);
Dan Alberteae41f82021-01-29 16:24:06 -0800302long double fmal(long double __x, long double __y, long double __z) __RENAME_LDBL_NO_GUARD_FOR_NDK(fma, 3, 21);
Elliott Hughes50cda382017-09-14 15:30:08 -0700303
Elliott Hughesb6622802015-08-14 14:04:30 -0700304#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))
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800310
Dan Albert284c8f12017-03-30 16:34:27 -0700311/*
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 */
Elliott Hughes684c31a2017-08-18 15:07:41 -0700322int (isinf)(double __x) __attribute_const__ __INTRODUCED_IN(21);
323int (isnan)(double __x) __attribute_const__;
Dan Albert284c8f12017-03-30 16:34:27 -0700324
Elliott Hughes50cda382017-09-14 15:30:08 -0700325/* POSIX extensions. */
Josh Gao46b44162016-05-27 11:14:16 -0700326
Elliott Hughes50cda382017-09-14 15:30:08 -0700327extern int signgam;
Elliott Hughesb4f2f282014-05-08 21:19:12 -0700328
Elliott Hughes684c31a2017-08-18 15:07:41 -0700329double j0(double __x);
330double j1(double __x);
331double jn(int __n, double __x);
332double y0(double __x);
333double y1(double __x);
334double yn(int __n, double __x);
Elliott Hughesc1929e42016-08-12 16:18:03 -0700335
Elliott Hughes3ba55f82016-06-08 18:11:23 -0700336#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) */
Elliott Hughes9c8d7112016-06-13 13:23:42 -0700349
Elliott Hughes3ba55f82016-06-08 18:11:23 -0700350#define MAXFLOAT ((float)3.40282346638528860e+38)
Elliott Hughes9c8d7112016-06-13 13:23:42 -0700351
Elliott Hughes50cda382017-09-14 15:30:08 -0700352/* BSD extensions. */
353
354#if defined(__USE_BSD)
355#define HUGE MAXFLOAT
356#endif
357
358/* Extensions in both BSD and GNU. */
359
Elliott Hughes9c8d7112016-06-13 13:23:42 -0700360#if defined(__USE_BSD) || defined(__USE_GNU)
Elliott Hughes684c31a2017-08-18 15:07:41 -0700361double gamma(double __x);
362double scalb(double __x, double __exponent);
363double drem(double __x, double __y);
364int finite(double __x) __attribute_const__;
365int isnanf(float __x) __attribute_const__;
zijunzhao195b90b2023-02-08 02:00:09 +0000366double gamma_r(double __x, int* _Nonnull __sign);
367double lgamma_r(double __x, int* _Nonnull __sign);
Elliott Hughes684c31a2017-08-18 15:07:41 -0700368double significand(double __x);
zijunzhao195b90b2023-02-08 02:00:09 +0000369long double lgammal_r(long double __x, int* _Nonnull __sign) __INTRODUCED_IN(23);
Elliott Hughes684c31a2017-08-18 15:07:41 -0700370long double significandl(long double __x) __INTRODUCED_IN(21);
371float dremf(float __x, float __y);
372int finitef(float __x) __attribute_const__;
373float gammaf(float __x);
374float j0f(float __x);
375float j1f(float __x);
376float jnf(int __n, float __x);
377float scalbf(float __x, float __exponent);
378float y0f(float __x);
379float y1f(float __x);
380float ynf(int __n, float __x);
zijunzhao195b90b2023-02-08 02:00:09 +0000381float gammaf_r(float __x, int* _Nonnull __sign);
382float lgammaf_r(float __x, int* _Nonnull __sign);
Elliott Hughes684c31a2017-08-18 15:07:41 -0700383float significandf(float __x);
zijunzhao195b90b2023-02-08 02:00:09 +0000384void sincos(double __x, double* _Nonnull __sin, double* _Nonnull __cos);
385void sincosf(float __x, float* _Nonnull __sin, float* _Nonnull __cos);
386void sincosl(long double __x, long double* _Nonnull __sin, long double* _Nonnull __cos);
Elliott Hughes75531852014-09-18 11:23:58 -0700387#endif
388
Elliott Hughes50cda382017-09-14 15:30:08 -0700389/* GNU extensions. */
390
Elliott Hughes5f5cc452014-08-18 16:04:03 -0700391#if defined(__USE_GNU)
Elliott Hughes3ba55f82016-06-08 18:11:23 -0700392#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) */
Elliott Hughes3ba55f82016-06-08 18:11:23 -0700405#endif
Elliott Hughesb4f2f282014-05-08 21:19:12 -0700406
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800407__END_DECLS