1// -*- C++ -*-
2//===---------------------------- cmath -----------------------------------===//
3//
4// The LLVM Compiler Infrastructure
5//
6// This file is dual licensed under the MIT and the University of Illinois Open
7// Source Licenses. See LICENSE.TXT for details.
8//
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
140bool signbit(arithmetic x);
141
142int fpclassify(arithmetic x);
143
144bool isfinite(arithmetic x);
145bool isinf(arithmetic x);
146bool isnan(arithmetic x);
147bool isnormal(arithmetic x);
148
149bool 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);
155
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
212double hypot(double x, double y, double z); // C++17
213float hypot(float x, float y, float z); // C++17
214long double hypot(long double x, long double y, long double z); // C++17
215
216int ilogb (arithmetic x);
217int ilogbf(float x);
218int ilogbl(long double x);
219
220floating_point lgamma (arithmetic x);
221float lgammaf(float x);
222long double lgammal(long double x);
223
224long long llrint (arithmetic x);
225long long llrintf(float x);
226long long llrintl(long double x);
227
228long long llround (arithmetic x);
229long long llroundf(float x);
230long long llroundl(long double x);
231
232floating_point log1p (arithmetic x);
233float log1pf(float x);
234long double log1pl(long double x);
235
236floating_point log2 (arithmetic x);
237float log2f(float x);
238long double log2l(long double x);
239
240floating_point logb (arithmetic x);
241float logbf(float x);
242long double logbl(long double x);
243
244long lrint (arithmetic x);
245long lrintf(float x);
246long lrintl(long double x);
247
248long lround (arithmetic x);
249long lroundf(float x);
250long lroundl(long double x);
251
252double nan (const char* str);
253float nanf(const char* str);
254long double nanl(const char* str);
255
256floating_point nearbyint (arithmetic x);
257float nearbyintf(float x);
258long double nearbyintl(long double x);
259
260floating_point nextafter (arithmetic x, arithmetic y);
261float nextafterf(float x, float y);
262long double nextafterl(long double x, long double y);
263
264floating_point nexttoward (arithmetic x, long double y);
265float nexttowardf(float x, long double y);
266long double nexttowardl(long double x, long double y);
267
268floating_point remainder (arithmetic x, arithmetic y);
269float remainderf(float x, float y);
270long double remainderl(long double x, long double y);
271
272floating_point remquo (arithmetic x, arithmetic y, int* pquo);
273float remquof(float x, float y, int* pquo);
274long double remquol(long double x, long double y, int* pquo);
275
276floating_point rint (arithmetic x);
277float rintf(float x);
278long double rintl(long double x);
279
280floating_point round (arithmetic x);
281float roundf(float x);
282long double roundl(long double x);
283
284floating_point scalbln (arithmetic x, long ex);
285float scalblnf(float x, long ex);
286long double scalblnl(long double x, long ex);
287
288floating_point scalbn (arithmetic x, int ex);
289float scalbnf(float x, int ex);
290long double scalbnl(long double x, int ex);
291
292floating_point tgamma (arithmetic x);
293float tgammaf(float x);
294long double tgammal(long double x);
295
296floating_point trunc (arithmetic x);
297float truncf(float x);
298long double truncl(long double x);
299
300} // std
301
302*/
303
304#include <__config>
305#include <math.h>
306
307#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
308#pragma GCC system_header
309#endif
310
311_LIBCPP_BEGIN_NAMESPACE_STD
312
313using ::signbit;
314using ::fpclassify;
315using ::isfinite;
316using ::isinf;
317using ::isnan;
318using ::isnormal;
319using ::isgreater;
320using ::isgreaterequal;
321using ::isless;
322using ::islessequal;
323using ::islessgreater;
324using ::isunordered;
325using ::isunordered;
326
327using ::float_t;
328using ::double_t;
329
330#ifndef _AIX
331using ::abs;
332#endif
333
334#ifndef __sun__
335using ::acos;
336using ::acosf;
337using ::asin;
338using ::asinf;
339using ::atan;
340using ::atanf;
341using ::atan2;
342using ::atan2f;
343using ::ceil;
344using ::ceilf;
345using ::cos;
346using ::cosf;
347using ::cosh;
348using ::coshf;
349#endif // __sun__
350
351using ::exp;
352using ::expf;
353
354#ifndef __sun__
355using ::fabs;
356using ::fabsf;
357using ::floor;
358using ::floorf;
359#endif //__sun__
360
361using ::fmod;
362using ::fmodf;
363
364#ifndef __sun__
365using ::frexp;
366using ::frexpf;
367using ::ldexp;
368using ::ldexpf;
369#endif // __sun__
370
371using ::log;
372using ::logf;
373
374#ifndef __sun__
375using ::log10;
376using ::log10f;
377using ::modf;
378using ::modff;
379#endif // __sun__
380
381using ::pow;
382using ::powf;
383
384#ifndef __sun__
385using ::sin;
386using ::sinf;
387using ::sinh;
388using ::sinhf;
389#endif // __sun__
390
391using ::sqrt;
392using ::sqrtf;
393using ::tan;
394using ::tanf;
395
396#ifndef __sun__
397using ::tanh;
398using ::tanhf;
399
400#ifndef _LIBCPP_MSVCRT
401using ::acosh;
402using ::acoshf;
403using ::asinh;
404using ::asinhf;
405using ::atanh;
406using ::atanhf;
407using ::cbrt;
408using ::cbrtf;
409#endif
410
411using ::copysign;
412using ::copysignf;
413
414#ifndef _LIBCPP_MSVCRT
415using ::erf;
416using ::erff;
417using ::erfc;
418using ::erfcf;
419using ::exp2;
420using ::exp2f;
421using ::expm1;
422using ::expm1f;
423using ::fdim;
424using ::fdimf;
425using ::fmaf;
426using ::fma;
427using ::fmax;
428using ::fmaxf;
429using ::fmin;
430using ::fminf;
431using ::hypot;
432using ::hypotf;
433using ::ilogb;
434using ::ilogbf;
435using ::lgamma;
436using ::lgammaf;
437using ::llrint;
438using ::llrintf;
439using ::llround;
440using ::llroundf;
441using ::log1p;
442using ::log1pf;
443using ::log2;
444using ::log2f;
445using ::logb;
446using ::logbf;
447using ::lrint;
448using ::lrintf;
449using ::lround;
450using ::lroundf;
451#endif // _LIBCPP_MSVCRT
452#endif // __sun__
453
454#ifndef _LIBCPP_MSVCRT
455using ::nan;
456using ::nanf;
457#endif // _LIBCPP_MSVCRT
458
459#ifndef __sun__
460#ifndef _LIBCPP_MSVCRT
461using ::nearbyint;
462using ::nearbyintf;
463using ::nextafter;
464using ::nextafterf;
465using ::nexttoward;
466using ::nexttowardf;
467using ::remainder;
468using ::remainderf;
469using ::remquo;
470using ::remquof;
471using ::rint;
472using ::rintf;
473using ::round;
474using ::roundf;
475using ::scalbln;
476using ::scalblnf;
477using ::scalbn;
478using ::scalbnf;
479using ::tgamma;
480using ::tgammaf;
481using ::trunc;
482using ::truncf;
483#endif // !_LIBCPP_MSVCRT
484
485using ::acosl;
486using ::asinl;
487using ::atanl;
488using ::atan2l;
489using ::ceill;
490using ::cosl;
491using ::coshl;
492using ::expl;
493using ::fabsl;
494using ::floorl;
495using ::fmodl;
496using ::frexpl;
497using ::ldexpl;
498using ::logl;
499using ::log10l;
500using ::modfl;
501using ::powl;
502using ::sinl;
503using ::sinhl;
504using ::sqrtl;
505using ::tanl;
506
507#ifndef _LIBCPP_MSVCRT
508using ::tanhl;
509using ::acoshl;
510using ::asinhl;
511using ::atanhl;
512using ::cbrtl;
513#endif // !_LIBCPP_MSVCRT
514
515using ::copysignl;
516
517#ifndef _LIBCPP_MSVCRT
518using ::erfl;
519using ::erfcl;
520using ::exp2l;
521using ::expm1l;
522using ::fdiml;
523using ::fmal;
524using ::fmaxl;
525using ::fminl;
526using ::hypotl;
527using ::ilogbl;
528using ::lgammal;
529using ::llrintl;
530using ::llroundl;
531using ::log1pl;
532using ::log2l;
533using ::logbl;
534using ::lrintl;
535using ::lroundl;
536using ::nanl;
537using ::nearbyintl;
538using ::nextafterl;
539using ::nexttowardl;
540using ::remainderl;
541using ::remquol;
542using ::rintl;
543using ::roundl;
544using ::scalblnl;
545using ::scalbnl;
546using ::tgammal;
547using ::truncl;
548#endif // !_LIBCPP_MSVCRT
549
550#else
551using ::lgamma;
552using ::lgammaf;
553#endif // __sun__
554
555#if _LIBCPP_STD_VER > 14
556inline _LIBCPP_INLINE_VISIBILITY float hypot( float x, float y, float z ) { return sqrt(lcpp_x: x*x + y*y + z*z); }
557inline _LIBCPP_INLINE_VISIBILITY double hypot( double x, double y, double z ) { return sqrt(x*x + y*y + z*z); }
558inline _LIBCPP_INLINE_VISIBILITY long double hypot( long double x, long double y, long double z ) { return sqrt(lcpp_x: x*x + y*y + z*z); }
559
560template <class _A1, class _A2, class _A3>
561inline _LIBCPP_INLINE_VISIBILITY
562typename std::__lazy_enable_if
563<
564 std::is_arithmetic<_A1>::value &&
565 std::is_arithmetic<_A2>::value &&
566 std::is_arithmetic<_A3>::value,
567 std::__promote<_A1, _A2, _A3>
568>::type
569hypot(_A1 __lcpp_x, _A2 __lcpp_y, _A3 __lcpp_z) _NOEXCEPT
570{
571 typedef typename std::__promote<_A1, _A2, _A3>::type __result_type;
572 static_assert((!(std::is_same<_A1, __result_type>::value &&
573 std::is_same<_A2, __result_type>::value &&
574 std::is_same<_A3, __result_type>::value)), "");
575 return hypot((__result_type)__lcpp_x, (__result_type)__lcpp_y, (__result_type)__lcpp_z);
576}
577#endif
578
579_LIBCPP_END_NAMESPACE_STD
580
581#endif // _LIBCPP_CMATH
582