blob: ebbde18168ff76639fa9281cabbb70e2b65683d3 [file] [log] [blame]
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001// -*- C++ -*-
2//===---------------------------- cmath -----------------------------------===//
3//
Howard Hinnantf5256e12010-05-11 21:36:01 +00004// The LLVM Compiler Infrastructure
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00005//
Howard Hinnantb64f8b02010-11-16 22:09:02 +00006// This file is dual licensed under the MIT and the University of Illinois Open
7// Source Licenses. See LICENSE.TXT for details.
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00008//
9//===----------------------------------------------------------------------===//
10
11#ifndef _LIBCPP_CMATH
12#define _LIBCPP_CMATH
13
14/*
15 cmath synopsis
16
17Macros:
18
19 HUGE_VAL
20 HUGE_VALF // C99
21 HUGE_VALL // C99
22 INFINITY // C99
23 NAN // C99
24 FP_INFINITE // C99
25 FP_NAN // C99
26 FP_NORMAL // C99
27 FP_SUBNORMAL // C99
28 FP_ZERO // C99
29 FP_FAST_FMA // C99
30 FP_FAST_FMAF // C99
31 FP_FAST_FMAL // C99
32 FP_ILOGB0 // C99
33 FP_ILOGBNAN // C99
34 MATH_ERRNO // C99
35 MATH_ERREXCEPT // C99
36 math_errhandling // C99
37
38namespace std
39{
40
41Types:
42
43 float_t // C99
44 double_t // C99
45
46// C90
47
48floating_point abs(floating_point x);
49
50floating_point acos (arithmetic x);
51float acosf(float x);
52long double acosl(long double x);
53
54floating_point asin (arithmetic x);
55float asinf(float x);
56long double asinl(long double x);
57
58floating_point atan (arithmetic x);
59float atanf(float x);
60long double atanl(long double x);
61
62floating_point atan2 (arithmetic y, arithmetic x);
63float atan2f(float y, float x);
64long double atan2l(long double y, long double x);
65
66floating_point ceil (arithmetic x);
67float ceilf(float x);
68long double ceill(long double x);
69
70floating_point cos (arithmetic x);
71float cosf(float x);
72long double cosl(long double x);
73
74floating_point cosh (arithmetic x);
75float coshf(float x);
76long double coshl(long double x);
77
78floating_point exp (arithmetic x);
79float expf(float x);
80long double expl(long double x);
81
82floating_point fabs (arithmetic x);
83float fabsf(float x);
84long double fabsl(long double x);
85
86floating_point floor (arithmetic x);
87float floorf(float x);
88long double floorl(long double x);
89
90floating_point fmod (arithmetic x, arithmetic y);
91float fmodf(float x, float y);
92long double fmodl(long double x, long double y);
93
94floating_point frexp (arithmetic value, int* exp);
95float frexpf(float value, int* exp);
96long double frexpl(long double value, int* exp);
97
98floating_point ldexp (arithmetic value, int exp);
99float ldexpf(float value, int exp);
100long double ldexpl(long double value, int exp);
101
102floating_point log (arithmetic x);
103float logf(float x);
104long double logl(long double x);
105
106floating_point log10 (arithmetic x);
107float log10f(float x);
108long double log10l(long double x);
109
110floating_point modf (floating_point value, floating_point* iptr);
111float modff(float value, float* iptr);
112long double modfl(long double value, long double* iptr);
113
114floating_point pow (arithmetic x, arithmetic y);
115float powf(float x, float y);
116long double powl(long double x, long double y);
117
118floating_point sin (arithmetic x);
119float sinf(float x);
120long double sinl(long double x);
121
122floating_point sinh (arithmetic x);
123float sinhf(float x);
124long double sinhl(long double x);
125
126floating_point sqrt (arithmetic x);
127float sqrtf(float x);
128long double sqrtl(long double x);
129
130floating_point tan (arithmetic x);
131float tanf(float x);
132long double tanl(long double x);
133
134floating_point tanh (arithmetic x);
135float tanhf(float x);
136long double tanhl(long double x);
137
138// C99
139
Howard Hinnantb05a5562013-01-14 20:56:22 +0000140bool signbit(arithmetic x);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000141
Howard Hinnantb05a5562013-01-14 20:56:22 +0000142int fpclassify(arithmetic x);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000143
Howard Hinnantb05a5562013-01-14 20:56:22 +0000144bool isfinite(arithmetic x);
145bool isinf(arithmetic x);
146bool isnan(arithmetic x);
147bool isnormal(arithmetic x);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000148
Howard Hinnantb05a5562013-01-14 20:56:22 +0000149bool isgreater(arithmetic x, arithmetic y);
150bool isgreaterequal(arithmetic x, arithmetic y);
151bool isless(arithmetic x, arithmetic y);
152bool islessequal(arithmetic x, arithmetic y);
153bool islessgreater(arithmetic x, arithmetic y);
154bool isunordered(arithmetic x, arithmetic y);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000155
156floating_point acosh (arithmetic x);
157float acoshf(float x);
158long double acoshl(long double x);
159
160floating_point asinh (arithmetic x);
161float asinhf(float x);
162long double asinhl(long double x);
163
164floating_point atanh (arithmetic x);
165float atanhf(float x);
166long double atanhl(long double x);
167
168floating_point cbrt (arithmetic x);
169float cbrtf(float x);
170long double cbrtl(long double x);
171
172floating_point copysign (arithmetic x, arithmetic y);
173float copysignf(float x, float y);
174long double copysignl(long double x, long double y);
175
176floating_point erf (arithmetic x);
177float erff(float x);
178long double erfl(long double x);
179
180floating_point erfc (arithmetic x);
181float erfcf(float x);
182long double erfcl(long double x);
183
184floating_point exp2 (arithmetic x);
185float exp2f(float x);
186long double exp2l(long double x);
187
188floating_point expm1 (arithmetic x);
189float expm1f(float x);
190long double expm1l(long double x);
191
192floating_point fdim (arithmetic x, arithmetic y);
193float fdimf(float x, float y);
194long double fdiml(long double x, long double y);
195
196floating_point fma (arithmetic x, arithmetic y, arithmetic z);
197float fmaf(float x, float y, float z);
198long double fmal(long double x, long double y, long double z);
199
200floating_point fmax (arithmetic x, arithmetic y);
201float fmaxf(float x, float y);
202long double fmaxl(long double x, long double y);
203
204floating_point fmin (arithmetic x, arithmetic y);
205float fminf(float x, float y);
206long double fminl(long double x, long double y);
207
208floating_point hypot (arithmetic x, arithmetic y);
209float hypotf(float x, float y);
210long double hypotl(long double x, long double y);
211
212int ilogb (arithmetic x);
213int ilogbf(float x);
214int ilogbl(long double x);
215
216floating_point lgamma (arithmetic x);
217float lgammaf(float x);
218long double lgammal(long double x);
219
220long long llrint (arithmetic x);
221long long llrintf(float x);
222long long llrintl(long double x);
223
224long long llround (arithmetic x);
225long long llroundf(float x);
226long long llroundl(long double x);
227
228floating_point log1p (arithmetic x);
229float log1pf(float x);
230long double log1pl(long double x);
231
232floating_point log2 (arithmetic x);
233float log2f(float x);
234long double log2l(long double x);
235
236floating_point logb (arithmetic x);
237float logbf(float x);
238long double logbl(long double x);
239
240long lrint (arithmetic x);
241long lrintf(float x);
242long lrintl(long double x);
243
244long lround (arithmetic x);
245long lroundf(float x);
246long lroundl(long double x);
247
248double nan (const char* str);
249float nanf(const char* str);
250long double nanl(const char* str);
251
252floating_point nearbyint (arithmetic x);
253float nearbyintf(float x);
254long double nearbyintl(long double x);
255
256floating_point nextafter (arithmetic x, arithmetic y);
257float nextafterf(float x, float y);
258long double nextafterl(long double x, long double y);
259
260floating_point nexttoward (arithmetic x, long double y);
261float nexttowardf(float x, long double y);
262long double nexttowardl(long double x, long double y);
263
264floating_point remainder (arithmetic x, arithmetic y);
265float remainderf(float x, float y);
266long double remainderl(long double x, long double y);
267
268floating_point remquo (arithmetic x, arithmetic y, int* pquo);
269float remquof(float x, float y, int* pquo);
270long double remquol(long double x, long double y, int* pquo);
271
272floating_point rint (arithmetic x);
273float rintf(float x);
274long double rintl(long double x);
275
276floating_point round (arithmetic x);
277float roundf(float x);
278long double roundl(long double x);
279
280floating_point scalbln (arithmetic x, long ex);
281float scalblnf(float x, long ex);
282long double scalblnl(long double x, long ex);
283
284floating_point scalbn (arithmetic x, int ex);
285float scalbnf(float x, int ex);
286long double scalbnl(long double x, int ex);
287
288floating_point tgamma (arithmetic x);
289float tgammaf(float x);
290long double tgammal(long double x);
291
292floating_point trunc (arithmetic x);
293float truncf(float x);
294long double truncl(long double x);
295
296} // std
297
298*/
299
300#include <__config>
301#include <math.h>
Howard Hinnant9f8884e2011-10-27 16:24:42 +0000302
Howard Hinnant08e17472011-10-17 20:05:10 +0000303#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000304#pragma GCC system_header
Howard Hinnant08e17472011-10-17 20:05:10 +0000305#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000306
307_LIBCPP_BEGIN_NAMESPACE_STD
308
Howard Hinnant0a111112011-05-13 21:52:40 +0000309using ::signbit;
310using ::fpclassify;
311using ::isfinite;
312using ::isinf;
313using ::isnan;
314using ::isnormal;
315using ::isgreater;
316using ::isgreaterequal;
317using ::isless;
318using ::islessequal;
319using ::islessgreater;
320using ::isunordered;
321using ::isunordered;
322
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000323using ::float_t;
324using ::double_t;
325
Richard Smith4faa3942015-10-08 20:40:34 +0000326#ifndef _AIX
Eric Fiselier0b6f8ed2015-03-18 15:24:18 +0000327using ::abs;
328#endif
329
David Chisnall997e4542012-02-29 13:05:08 +0000330#ifndef __sun__
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000331using ::acos;
332using ::acosf;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000333using ::asin;
334using ::asinf;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000335using ::atan;
336using ::atanf;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000337using ::atan2;
338using ::atan2f;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000339using ::ceil;
340using ::ceilf;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000341using ::cos;
342using ::cosf;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000343using ::cosh;
344using ::coshf;
David Chisnall997e4542012-02-29 13:05:08 +0000345#endif // __sun__
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000346
347using ::exp;
348using ::expf;
349
David Chisnall997e4542012-02-29 13:05:08 +0000350#ifndef __sun__
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000351using ::fabs;
352using ::fabsf;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000353using ::floor;
354using ::floorf;
David Chisnall997e4542012-02-29 13:05:08 +0000355#endif //__sun__
Richard Smith4faa3942015-10-08 20:40:34 +0000356
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000357using ::fmod;
358using ::fmodf;
Richard Smith4faa3942015-10-08 20:40:34 +0000359
David Chisnall997e4542012-02-29 13:05:08 +0000360#ifndef __sun__
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000361using ::frexp;
362using ::frexpf;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000363using ::ldexp;
364using ::ldexpf;
David Chisnall997e4542012-02-29 13:05:08 +0000365#endif // __sun__
Richard Smith4faa3942015-10-08 20:40:34 +0000366
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000367using ::log;
368using ::logf;
Richard Smith4faa3942015-10-08 20:40:34 +0000369
David Chisnall997e4542012-02-29 13:05:08 +0000370#ifndef __sun__
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000371using ::log10;
372using ::log10f;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000373using ::modf;
374using ::modff;
David Chisnall997e4542012-02-29 13:05:08 +0000375#endif // __sun__
Richard Smith4faa3942015-10-08 20:40:34 +0000376
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000377using ::pow;
378using ::powf;
379
David Chisnall997e4542012-02-29 13:05:08 +0000380#ifndef __sun__
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000381using ::sin;
382using ::sinf;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000383using ::sinh;
384using ::sinhf;
David Chisnall997e4542012-02-29 13:05:08 +0000385#endif // __sun__
Richard Smith4faa3942015-10-08 20:40:34 +0000386
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000387using ::sqrt;
388using ::sqrtf;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000389using ::tan;
390using ::tanf;
Richard Smith4faa3942015-10-08 20:40:34 +0000391
David Chisnall997e4542012-02-29 13:05:08 +0000392#ifndef __sun__
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000393using ::tanh;
394using ::tanhf;
395
Howard Hinnante9df0a52013-08-01 18:17:34 +0000396#ifndef _LIBCPP_MSVCRT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000397using ::acosh;
398using ::acoshf;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000399using ::asinh;
400using ::asinhf;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000401using ::atanh;
402using ::atanhf;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000403using ::cbrt;
404using ::cbrtf;
Howard Hinnant9f8884e2011-10-27 16:24:42 +0000405#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000406
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000407using ::copysign;
408using ::copysignf;
409
Howard Hinnante9df0a52013-08-01 18:17:34 +0000410#ifndef _LIBCPP_MSVCRT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000411using ::erf;
412using ::erff;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000413using ::erfc;
414using ::erfcf;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000415using ::exp2;
416using ::exp2f;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000417using ::expm1;
418using ::expm1f;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000419using ::fdim;
420using ::fdimf;
Marshall Clow0d6dcb52014-03-05 17:09:51 +0000421using ::fmaf;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000422using ::fma;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000423using ::fmax;
424using ::fmaxf;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000425using ::fmin;
426using ::fminf;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000427using ::hypot;
428using ::hypotf;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000429using ::ilogb;
430using ::ilogbf;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000431using ::lgamma;
432using ::lgammaf;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000433using ::llrint;
434using ::llrintf;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000435using ::llround;
436using ::llroundf;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000437using ::log1p;
438using ::log1pf;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000439using ::log2;
440using ::log2f;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000441using ::logb;
442using ::logbf;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000443using ::lrint;
444using ::lrintf;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000445using ::lround;
446using ::lroundf;
Howard Hinnante9df0a52013-08-01 18:17:34 +0000447#endif // _LIBCPP_MSVCRT
David Chisnall997e4542012-02-29 13:05:08 +0000448#endif // __sun__
Howard Hinnante9df0a52013-08-01 18:17:34 +0000449
Howard Hinnante9df0a52013-08-01 18:17:34 +0000450#ifndef _LIBCPP_MSVCRT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000451using ::nan;
452using ::nanf;
Howard Hinnante9df0a52013-08-01 18:17:34 +0000453#endif // _LIBCPP_MSVCRT
454
David Chisnall997e4542012-02-29 13:05:08 +0000455#ifndef __sun__
Howard Hinnante9df0a52013-08-01 18:17:34 +0000456#ifndef _LIBCPP_MSVCRT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000457using ::nearbyint;
458using ::nearbyintf;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000459using ::nextafter;
460using ::nextafterf;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000461using ::nexttoward;
462using ::nexttowardf;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000463using ::remainder;
464using ::remainderf;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000465using ::remquo;
466using ::remquof;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000467using ::rint;
468using ::rintf;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000469using ::round;
470using ::roundf;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000471using ::scalbln;
472using ::scalblnf;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000473using ::scalbn;
474using ::scalbnf;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000475using ::tgamma;
476using ::tgammaf;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000477using ::trunc;
478using ::truncf;
Howard Hinnante9df0a52013-08-01 18:17:34 +0000479#endif // !_LIBCPP_MSVCRT
Howard Hinnant9f8884e2011-10-27 16:24:42 +0000480
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000481using ::acosl;
482using ::asinl;
483using ::atanl;
484using ::atan2l;
485using ::ceill;
486using ::cosl;
487using ::coshl;
488using ::expl;
489using ::fabsl;
490using ::floorl;
491using ::fmodl;
492using ::frexpl;
493using ::ldexpl;
494using ::logl;
495using ::log10l;
496using ::modfl;
497using ::powl;
498using ::sinl;
499using ::sinhl;
500using ::sqrtl;
501using ::tanl;
Richard Smith4faa3942015-10-08 20:40:34 +0000502
Howard Hinnante9df0a52013-08-01 18:17:34 +0000503#ifndef _LIBCPP_MSVCRT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000504using ::tanhl;
505using ::acoshl;
506using ::asinhl;
507using ::atanhl;
508using ::cbrtl;
Howard Hinnante9df0a52013-08-01 18:17:34 +0000509#endif // !_LIBCPP_MSVCRT
Richard Smith4faa3942015-10-08 20:40:34 +0000510
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000511using ::copysignl;
Richard Smith4faa3942015-10-08 20:40:34 +0000512
Howard Hinnante9df0a52013-08-01 18:17:34 +0000513#ifndef _LIBCPP_MSVCRT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000514using ::erfl;
515using ::erfcl;
516using ::exp2l;
517using ::expm1l;
518using ::fdiml;
519using ::fmal;
520using ::fmaxl;
521using ::fminl;
522using ::hypotl;
523using ::ilogbl;
524using ::lgammal;
525using ::llrintl;
526using ::llroundl;
527using ::log1pl;
528using ::log2l;
529using ::logbl;
530using ::lrintl;
531using ::lroundl;
532using ::nanl;
533using ::nearbyintl;
534using ::nextafterl;
535using ::nexttowardl;
536using ::remainderl;
537using ::remquol;
538using ::rintl;
539using ::roundl;
540using ::scalblnl;
541using ::scalbnl;
542using ::tgammal;
543using ::truncl;
Howard Hinnante9df0a52013-08-01 18:17:34 +0000544#endif // !_LIBCPP_MSVCRT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000545
David Chisnall997e4542012-02-29 13:05:08 +0000546#else
547using ::lgamma;
548using ::lgammaf;
549#endif // __sun__
Richard Smith4faa3942015-10-08 20:40:34 +0000550
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000551_LIBCPP_END_NAMESPACE_STD
552
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000553#endif // _LIBCPP_CMATH