blob: 248ed3c1e0817fbc03b2ce8bb222658415f53ae8 [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/*
13 * from: @(#)fdlibm.h 5.1 93/09/24
Elliott Hughesa0ee0782013-01-30 19:06:37 -080014 * $FreeBSD$
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080015 */
16
17#ifndef _MATH_H_
Elliott Hughesb6622802015-08-14 14:04:30 -070018#define _MATH_H_
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080019
20#include <sys/cdefs.h>
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080021#include <limits.h>
22
Elliott Hughesde9ac712014-05-19 16:58:52 -070023__BEGIN_DECLS
Elliott Hughesde9ac712014-05-19 16:58:52 -070024
Elliott Hughesb6622802015-08-14 14:04:30 -070025#define HUGE_VAL __builtin_huge_val()
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080026
Elliott Hughesb6622802015-08-14 14:04:30 -070027#define FP_ILOGB0 (-INT_MAX)
28#define FP_ILOGBNAN INT_MAX
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080029
Elliott Hughesb6622802015-08-14 14:04:30 -070030#define HUGE_VALF __builtin_huge_valf()
31#define HUGE_VALL __builtin_huge_vall()
32#define INFINITY __builtin_inff()
33#define NAN __builtin_nanf("")
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080034
Elliott Hughesb6622802015-08-14 14:04:30 -070035#define MATH_ERRNO 1
36#define MATH_ERREXCEPT 2
37#define math_errhandling MATH_ERREXCEPT
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080038
Elliott Hughesb6622802015-08-14 14:04:30 -070039#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
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080047#endif
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080048
49/* Symbolic constants to classify floating point numbers. */
Elliott Hughesb6622802015-08-14 14:04:30 -070050#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)
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080057
Elliott Hughesb6622802015-08-14 14:04:30 -070058#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)
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080062
Elliott Hughesb6622802015-08-14 14:04:30 -070063#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))
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080069
Elliott Hughesb6622802015-08-14 14:04:30 -070070#define signbit(x) \
71 ((sizeof(x) == sizeof(float)) ? __builtin_signbitf(x) \
72 : (sizeof(x) == sizeof(double)) ? __builtin_signbit(x) \
73 : __builtin_signbitl(x))
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080074
Elliott Hughes9f87a0b2014-02-07 14:55:58 -080075typedef double __double_t;
76typedef __double_t double_t;
77typedef float __float_t;
78typedef __float_t float_t;
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080079
Elliott Hughes3ba55f82016-06-08 18:11:23 -070080#if defined(__USE_BSD)
81#define HUGE MAXFLOAT
Elliott Hughes9ee6adb2016-03-11 14:49:13 -080082#endif
83
Elliott Hughesc1929e42016-08-12 16:18:03 -070084extern int signgam;
85
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080086/*
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
Elliott Hughes95fa0612016-09-28 12:29:52 -070089 * as __attribute_const__. In C99, FENV_ACCESS affects the purity of these functions.
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080090 */
Elliott Hughesde9ac712014-05-19 16:58:52 -070091
Elliott Hughes684c31a2017-08-18 15:07:41 -070092int __fpclassifyd(double __x) __attribute_const__;
93int __fpclassifyf(float __x) __attribute_const__;
94int __fpclassifyl(long double __x) __attribute_const__;
95int __isfinitef(float __x) __attribute_const__;
96int __isfinite(double __x) __attribute_const__;
97int __isfinitel(long double __x) __attribute_const__;
98int __isinff(float __x) __attribute_const__;
99int __isinfl(long double __x) __attribute_const__;
100int __isnanf(float __x) __attribute_const__ __INTRODUCED_IN(21);
101int __isnanl(long double __x) __attribute_const__;
102int __isnormalf(float __x) __attribute_const__;
103int __isnormal(double __x) __attribute_const__;
104int __isnormall(long double __x) __attribute_const__;
105int __signbit(double __x) __attribute_const__;
106int __signbitf(float __x) __attribute_const__;
107int __signbitl(long double __x) __attribute_const__;
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800108
Elliott Hughes684c31a2017-08-18 15:07:41 -0700109double acos(double __x);
110double asin(double __x);
111double atan(double __x);
112double atan2(double __y, double __x);
113double cos(double __x);
114double sin(double __x);
115double tan(double __x);
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800116
Elliott Hughes684c31a2017-08-18 15:07:41 -0700117double cosh(double __x);
118double sinh(double __x);
119double tanh(double __x);
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800120
Elliott Hughes684c31a2017-08-18 15:07:41 -0700121double exp(double __x);
122double frexp(double __x, int* __exponent); /* fundamentally !__attribute_const__ */
123double ldexp(double __x, int __exponent);
124double log(double __x);
125double log10(double __x);
126double modf(double __x, double* __integral_part); /* fundamentally !__attribute_const__ */
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800127
Elliott Hughes684c31a2017-08-18 15:07:41 -0700128double pow(double __x, double __y);
129double sqrt(double __x);
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800130
Elliott Hughes684c31a2017-08-18 15:07:41 -0700131double ceil(double __x);
132double fabs(double __x) __attribute_const__;
133double floor(double __x);
134double fmod(double __x, double __y);
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800135
Elliott Hughes684c31a2017-08-18 15:07:41 -0700136double acosh(double __x);
137double asinh(double __x);
138double atanh(double __x);
139double cbrt(double __x);
140double erf(double __x);
141double erfc(double __x);
142double exp2(double __x);
143double expm1(double __x);
144double fma(double __x, double __y, double __z);
145double hypot(double __x, double __y);
146int ilogb(double __x) __attribute_const__;
147double lgamma(double __x);
148long long llrint(double __x);
149long long llround(double __x);
150double log1p(double __x);
151double log2(double __x) __INTRODUCED_IN(18);
152double logb(double __x);
153long lrint(double __x);
154long lround(double __x);
Josh Gao46b44162016-05-27 11:14:16 -0700155
Dan Albert284c8f12017-03-30 16:34:27 -0700156/*
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 */
Elliott Hughes684c31a2017-08-18 15:07:41 -0700167int (isinf)(double __x) __attribute_const__ __INTRODUCED_IN(21);
168int (isnan)(double __x) __attribute_const__;
Dan Albert284c8f12017-03-30 16:34:27 -0700169
Elliott Hughes684c31a2017-08-18 15:07:41 -0700170double nan(const char* __kind) __attribute_const__ __INTRODUCED_IN_ARM(13) __INTRODUCED_IN_MIPS(13)
Josh Gao46b44162016-05-27 11:14:16 -0700171 __INTRODUCED_IN_X86(9);
172
Elliott Hughes684c31a2017-08-18 15:07:41 -0700173double nextafter(double __x, double __y);
174double remainder(double __x, double __y);
175double remquo(double __x, double __y, int* __quotient_bits);
176double rint(double __x);
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800177
Elliott Hughes684c31a2017-08-18 15:07:41 -0700178double copysign(double __value, double __sign) __attribute_const__;
179double fdim(double __x, double __y);
180double fmax(double __x, double __y) __attribute_const__;
181double fmin(double __x, double __y) __attribute_const__;
182double nearbyint(double __x);
183double round(double __x);
184double scalbln(double __x, long __exponent) __INTRODUCED_IN_X86(18) __VERSIONER_NO_GUARD;
185double scalbn(double __x, int __exponent);
186double tgamma(double __x);
187double trunc(double __x);
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800188
Elliott Hughes684c31a2017-08-18 15:07:41 -0700189float acosf(float __x);
190float asinf(float __x);
191float atanf(float __x);
192float atan2f(float __y, float __x);
193float cosf(float __x);
194float sinf(float __x);
195float tanf(float __x);
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800196
Elliott Hughes684c31a2017-08-18 15:07:41 -0700197float coshf(float __x);
198float sinhf(float __x);
199float tanhf(float __x);
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800200
Elliott Hughes684c31a2017-08-18 15:07:41 -0700201float exp2f(float __x);
202float expf(float __x);
203float expm1f(float __x);
204float frexpf(float __x, int* __exponent); /* fundamentally !__attribute_const__ */
205int ilogbf(float __x) __attribute_const__;
206float ldexpf(float __x, int __exponent);
207float log10f(float __x);
208float log1pf(float __x);
209float log2f(float __x) __INTRODUCED_IN(18);
210float logf(float __x);
211float modff(float __x, float* __integral_part); /* fundamentally !__attribute_const__ */
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800212
Elliott Hughes684c31a2017-08-18 15:07:41 -0700213float powf(float __x, float __y);
214float sqrtf(float __x);
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800215
Elliott Hughes684c31a2017-08-18 15:07:41 -0700216float ceilf(float __x);
217float fabsf(float __x) __attribute_const__;
218float floorf(float __x);
219float fmodf(float __x, float __y);
220float roundf(float __x);
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800221
Elliott Hughes684c31a2017-08-18 15:07:41 -0700222float erff(float __x);
223float erfcf(float __x);
224float hypotf(float __x, float __y);
225float lgammaf(float __x);
226float tgammaf(float __x) __INTRODUCED_IN_ARM(13) __INTRODUCED_IN_MIPS(13) __INTRODUCED_IN_X86(9);
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800227
Elliott Hughes684c31a2017-08-18 15:07:41 -0700228float acoshf(float __x);
229float asinhf(float __x);
230float atanhf(float __x);
231float cbrtf(float __x);
232float logbf(float __x);
233float copysignf(float __value, float __sign) __attribute_const__;
234long long llrintf(float __x);
235long long llroundf(float __x);
236long lrintf(float __x);
237long lroundf(float __x);
238float nanf(const char* __kind) __attribute_const__ __INTRODUCED_IN_ARM(13) __INTRODUCED_IN_MIPS(13)
Josh Gao46b44162016-05-27 11:14:16 -0700239 __INTRODUCED_IN_X86(9);
Elliott Hughes684c31a2017-08-18 15:07:41 -0700240float nearbyintf(float __x);
241float nextafterf(float __x, float __y);
242float remainderf(float __x, float __y);
243float remquof(float __x, float __y, int* __quotient_bits);
244float rintf(float __x);
245float scalblnf(float __x, long __exponent) __INTRODUCED_IN_X86(18) __VERSIONER_NO_GUARD;
246float scalbnf(float __x, int __exponent);
247float truncf(float __x);
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800248
Elliott Hughes684c31a2017-08-18 15:07:41 -0700249float fdimf(float __x, float __y);
250float fmaf(float __x, float __y, float __z);
251float fmaxf(float __x, float __y) __attribute_const__;
252float fminf(float __x, float __y) __attribute_const__;
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800253
Elliott Hughes684c31a2017-08-18 15:07:41 -0700254long double acoshl(long double __x) __INTRODUCED_IN(21);
255long double acosl(long double __x) __INTRODUCED_IN(21);
256long double asinhl(long double __x) __INTRODUCED_IN(21);
257long double asinl(long double __x) __INTRODUCED_IN(21);
258long double atan2l(long double __y, long double __x) __INTRODUCED_IN(21);
259long double atanhl(long double __x) __INTRODUCED_IN(21);
260long double atanl(long double __x) __INTRODUCED_IN(21);
261long double cbrtl(long double __x) __INTRODUCED_IN(21);
262long double ceill(long double __x);
263long double copysignl(long double __value, long double __sign) __attribute_const__;
264long double coshl(long double __x) __INTRODUCED_IN(21);
265long double cosl(long double __x) __INTRODUCED_IN(21);
266long double erfcl(long double __x) __INTRODUCED_IN(21);
267long double erfl(long double __x) __INTRODUCED_IN(21);
268long double exp2l(long double __x) __INTRODUCED_IN(21);
269long double expl(long double __x) __INTRODUCED_IN(21);
270long double expm1l(long double __x) __INTRODUCED_IN(21);
271long double fabsl(long double __x) __attribute_const__;
272long double fdiml(long double __x, long double __y);
273long double floorl(long double __x);
274long double fmal(long double __x, long double __y, long double __z) __INTRODUCED_IN(21) __VERSIONER_NO_GUARD;
275long double fmaxl(long double __x, long double __y) __attribute_const__;
276long double fminl(long double __x, long double __y) __attribute_const__;
277long double fmodl(long double __x, long double __y) __INTRODUCED_IN(21);
278long double frexpl(long double __x, int* __exponent)
Elliott Hughes95fa0612016-09-28 12:29:52 -0700279 __INTRODUCED_IN(21) __VERSIONER_NO_GUARD; /* fundamentally !__attribute_const__ */
Elliott Hughes684c31a2017-08-18 15:07:41 -0700280long double hypotl(long double __x, long double __y) __INTRODUCED_IN(21);
281int ilogbl(long double __x) __attribute_const__;
282long double ldexpl(long double __x, int __exponent);
283long double lgammal(long double __x) __INTRODUCED_IN(21);
284long long llrintl(long double __x) __INTRODUCED_IN(21);
285long long llroundl(long double __x);
286long double log10l(long double __x) __INTRODUCED_IN(21);
287long double log1pl(long double __x) __INTRODUCED_IN(21);
288long double log2l(long double __x) __INTRODUCED_IN(18);
289long double logbl(long double __x) __INTRODUCED_IN(18);
290long double logl(long double __x) __INTRODUCED_IN(21);
291long lrintl(long double __x) __INTRODUCED_IN(21);
292long lroundl(long double __x);
293long double modfl(long double __x, long double* __integral_part) __INTRODUCED_IN(21); /* fundamentally !__attribute_const__ */
294long double nanl(const char* __kind) __attribute_const__ __INTRODUCED_IN(13);
295long double nearbyintl(long double __x) __INTRODUCED_IN(21);
296long double nextafterl(long double __x, long double __y) __INTRODUCED_IN(21) __VERSIONER_NO_GUARD;
297double nexttoward(double __x, long double __y) __INTRODUCED_IN(18) __VERSIONER_NO_GUARD;
298float nexttowardf(float __x, long double __y);
299long double nexttowardl(long double __x, long double __y) __INTRODUCED_IN(18) __VERSIONER_NO_GUARD;
300long double powl(long double __x, long double __y) __INTRODUCED_IN(21);
301long double remainderl(long double __x, long double __y) __INTRODUCED_IN(21);
302long double remquol(long double __x, long double __y, int* __quotient_bits) __INTRODUCED_IN(21);
303long double rintl(long double __x) __INTRODUCED_IN(21);
304long double roundl(long double __x);
305long double scalblnl(long double __x, long __exponent) __INTRODUCED_IN_X86(18) __VERSIONER_NO_GUARD;
306long double scalbnl(long double __x, int __exponent);
307long double sinhl(long double __x) __INTRODUCED_IN(21);
308long double sinl(long double __x) __INTRODUCED_IN(21);
309long double sqrtl(long double __x) __INTRODUCED_IN(21);
310long double tanhl(long double __x) __INTRODUCED_IN(21);
311long double tanl(long double __x) __INTRODUCED_IN(21);
312long double tgammal(long double __x) __INTRODUCED_IN(21);
313long double truncl(long double __x);
Elliott Hughesb4f2f282014-05-08 21:19:12 -0700314
Elliott Hughes684c31a2017-08-18 15:07:41 -0700315double j0(double __x);
316double j1(double __x);
317double jn(int __n, double __x);
318double y0(double __x);
319double y1(double __x);
320double yn(int __n, double __x);
Elliott Hughesc1929e42016-08-12 16:18:03 -0700321
Elliott Hughes3ba55f82016-06-08 18:11:23 -0700322#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) */
Elliott Hughes9c8d7112016-06-13 13:23:42 -0700335
Elliott Hughes3ba55f82016-06-08 18:11:23 -0700336#define MAXFLOAT ((float)3.40282346638528860e+38)
Elliott Hughes9c8d7112016-06-13 13:23:42 -0700337
338#if defined(__USE_BSD) || defined(__USE_GNU)
Elliott Hughes684c31a2017-08-18 15:07:41 -0700339double gamma(double __x);
340double scalb(double __x, double __exponent);
341double drem(double __x, double __y);
342int finite(double __x) __attribute_const__;
343int isnanf(float __x) __attribute_const__;
344double gamma_r(double __x, int* __sign);
345double lgamma_r(double __x, int* __sign);
346double significand(double __x);
347long double lgammal_r(long double __x, int* __sign) __INTRODUCED_IN(23);
348long double significandl(long double __x) __INTRODUCED_IN(21);
349float dremf(float __x, float __y);
350int finitef(float __x) __attribute_const__;
351float gammaf(float __x);
352float j0f(float __x);
353float j1f(float __x);
354float jnf(int __n, float __x);
355float scalbf(float __x, float __exponent);
356float y0f(float __x);
357float y1f(float __x);
358float ynf(int __n, float __x);
359float gammaf_r(float __x, int* __sign);
360float lgammaf_r(float __x, int* __sign);
361float significandf(float __x);
Elliott Hughes75531852014-09-18 11:23:58 -0700362#endif
363
Elliott Hughes5f5cc452014-08-18 16:04:03 -0700364#if defined(__USE_GNU)
Elliott Hughes3ba55f82016-06-08 18:11:23 -0700365#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) */
Elliott Hughes684c31a2017-08-18 15:07:41 -0700378void sincos(double __x, double* __sin, double* __cos);
379void sincosf(float __x, float* __sin, float* __cos);
380void sincosl(long double __x, long double* __sin, long double* __cos);
Elliott Hughes3ba55f82016-06-08 18:11:23 -0700381#endif
Elliott Hughesb4f2f282014-05-08 21:19:12 -0700382
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800383__END_DECLS
384
Elliott Hughes684c31a2017-08-18 15:07:41 -0700385#endif