xref: /freebsd/contrib/llvm-project/libcxx/include/cmath (revision 0b57cec536236d46e3dba9bd041533462f33dbb7)
1*0b57cec5SDimitry Andric// -*- C++ -*-
2*0b57cec5SDimitry Andric//===---------------------------- cmath -----------------------------------===//
3*0b57cec5SDimitry Andric//
4*0b57cec5SDimitry Andric// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5*0b57cec5SDimitry Andric// See https://llvm.org/LICENSE.txt for license information.
6*0b57cec5SDimitry Andric// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7*0b57cec5SDimitry Andric//
8*0b57cec5SDimitry Andric//===----------------------------------------------------------------------===//
9*0b57cec5SDimitry Andric
10*0b57cec5SDimitry Andric#ifndef _LIBCPP_CMATH
11*0b57cec5SDimitry Andric#define _LIBCPP_CMATH
12*0b57cec5SDimitry Andric
13*0b57cec5SDimitry Andric/*
14*0b57cec5SDimitry Andric    cmath synopsis
15*0b57cec5SDimitry Andric
16*0b57cec5SDimitry AndricMacros:
17*0b57cec5SDimitry Andric
18*0b57cec5SDimitry Andric    HUGE_VAL
19*0b57cec5SDimitry Andric    HUGE_VALF               // C99
20*0b57cec5SDimitry Andric    HUGE_VALL               // C99
21*0b57cec5SDimitry Andric    INFINITY                // C99
22*0b57cec5SDimitry Andric    NAN                     // C99
23*0b57cec5SDimitry Andric    FP_INFINITE             // C99
24*0b57cec5SDimitry Andric    FP_NAN                  // C99
25*0b57cec5SDimitry Andric    FP_NORMAL               // C99
26*0b57cec5SDimitry Andric    FP_SUBNORMAL            // C99
27*0b57cec5SDimitry Andric    FP_ZERO                 // C99
28*0b57cec5SDimitry Andric    FP_FAST_FMA             // C99
29*0b57cec5SDimitry Andric    FP_FAST_FMAF            // C99
30*0b57cec5SDimitry Andric    FP_FAST_FMAL            // C99
31*0b57cec5SDimitry Andric    FP_ILOGB0               // C99
32*0b57cec5SDimitry Andric    FP_ILOGBNAN             // C99
33*0b57cec5SDimitry Andric    MATH_ERRNO              // C99
34*0b57cec5SDimitry Andric    MATH_ERREXCEPT          // C99
35*0b57cec5SDimitry Andric    math_errhandling        // C99
36*0b57cec5SDimitry Andric
37*0b57cec5SDimitry Andricnamespace std
38*0b57cec5SDimitry Andric{
39*0b57cec5SDimitry Andric
40*0b57cec5SDimitry AndricTypes:
41*0b57cec5SDimitry Andric
42*0b57cec5SDimitry Andric    float_t                 // C99
43*0b57cec5SDimitry Andric    double_t                // C99
44*0b57cec5SDimitry Andric
45*0b57cec5SDimitry Andric// C90
46*0b57cec5SDimitry Andric
47*0b57cec5SDimitry Andricfloating_point abs(floating_point x);
48*0b57cec5SDimitry Andric
49*0b57cec5SDimitry Andricfloating_point acos (arithmetic x);
50*0b57cec5SDimitry Andricfloat          acosf(float x);
51*0b57cec5SDimitry Andriclong double    acosl(long double x);
52*0b57cec5SDimitry Andric
53*0b57cec5SDimitry Andricfloating_point asin (arithmetic x);
54*0b57cec5SDimitry Andricfloat          asinf(float x);
55*0b57cec5SDimitry Andriclong double    asinl(long double x);
56*0b57cec5SDimitry Andric
57*0b57cec5SDimitry Andricfloating_point atan (arithmetic x);
58*0b57cec5SDimitry Andricfloat          atanf(float x);
59*0b57cec5SDimitry Andriclong double    atanl(long double x);
60*0b57cec5SDimitry Andric
61*0b57cec5SDimitry Andricfloating_point atan2 (arithmetic y, arithmetic x);
62*0b57cec5SDimitry Andricfloat          atan2f(float y, float x);
63*0b57cec5SDimitry Andriclong double    atan2l(long double y, long double x);
64*0b57cec5SDimitry Andric
65*0b57cec5SDimitry Andricfloating_point ceil (arithmetic x);
66*0b57cec5SDimitry Andricfloat          ceilf(float x);
67*0b57cec5SDimitry Andriclong double    ceill(long double x);
68*0b57cec5SDimitry Andric
69*0b57cec5SDimitry Andricfloating_point cos (arithmetic x);
70*0b57cec5SDimitry Andricfloat          cosf(float x);
71*0b57cec5SDimitry Andriclong double    cosl(long double x);
72*0b57cec5SDimitry Andric
73*0b57cec5SDimitry Andricfloating_point cosh (arithmetic x);
74*0b57cec5SDimitry Andricfloat          coshf(float x);
75*0b57cec5SDimitry Andriclong double    coshl(long double x);
76*0b57cec5SDimitry Andric
77*0b57cec5SDimitry Andricfloating_point exp (arithmetic x);
78*0b57cec5SDimitry Andricfloat          expf(float x);
79*0b57cec5SDimitry Andriclong double    expl(long double x);
80*0b57cec5SDimitry Andric
81*0b57cec5SDimitry Andricfloating_point fabs (arithmetic x);
82*0b57cec5SDimitry Andricfloat          fabsf(float x);
83*0b57cec5SDimitry Andriclong double    fabsl(long double x);
84*0b57cec5SDimitry Andric
85*0b57cec5SDimitry Andricfloating_point floor (arithmetic x);
86*0b57cec5SDimitry Andricfloat          floorf(float x);
87*0b57cec5SDimitry Andriclong double    floorl(long double x);
88*0b57cec5SDimitry Andric
89*0b57cec5SDimitry Andricfloating_point fmod (arithmetic x, arithmetic y);
90*0b57cec5SDimitry Andricfloat          fmodf(float x, float y);
91*0b57cec5SDimitry Andriclong double    fmodl(long double x, long double y);
92*0b57cec5SDimitry Andric
93*0b57cec5SDimitry Andricfloating_point frexp (arithmetic value, int* exp);
94*0b57cec5SDimitry Andricfloat          frexpf(float value, int* exp);
95*0b57cec5SDimitry Andriclong double    frexpl(long double value, int* exp);
96*0b57cec5SDimitry Andric
97*0b57cec5SDimitry Andricfloating_point ldexp (arithmetic value, int exp);
98*0b57cec5SDimitry Andricfloat          ldexpf(float value, int exp);
99*0b57cec5SDimitry Andriclong double    ldexpl(long double value, int exp);
100*0b57cec5SDimitry Andric
101*0b57cec5SDimitry Andricfloating_point log (arithmetic x);
102*0b57cec5SDimitry Andricfloat          logf(float x);
103*0b57cec5SDimitry Andriclong double    logl(long double x);
104*0b57cec5SDimitry Andric
105*0b57cec5SDimitry Andricfloating_point log10 (arithmetic x);
106*0b57cec5SDimitry Andricfloat          log10f(float x);
107*0b57cec5SDimitry Andriclong double    log10l(long double x);
108*0b57cec5SDimitry Andric
109*0b57cec5SDimitry Andricfloating_point modf (floating_point value, floating_point* iptr);
110*0b57cec5SDimitry Andricfloat          modff(float value, float* iptr);
111*0b57cec5SDimitry Andriclong double    modfl(long double value, long double* iptr);
112*0b57cec5SDimitry Andric
113*0b57cec5SDimitry Andricfloating_point pow (arithmetic x, arithmetic y);
114*0b57cec5SDimitry Andricfloat          powf(float x, float y);
115*0b57cec5SDimitry Andriclong double    powl(long double x, long double y);
116*0b57cec5SDimitry Andric
117*0b57cec5SDimitry Andricfloating_point sin (arithmetic x);
118*0b57cec5SDimitry Andricfloat          sinf(float x);
119*0b57cec5SDimitry Andriclong double    sinl(long double x);
120*0b57cec5SDimitry Andric
121*0b57cec5SDimitry Andricfloating_point sinh (arithmetic x);
122*0b57cec5SDimitry Andricfloat          sinhf(float x);
123*0b57cec5SDimitry Andriclong double    sinhl(long double x);
124*0b57cec5SDimitry Andric
125*0b57cec5SDimitry Andricfloating_point sqrt (arithmetic x);
126*0b57cec5SDimitry Andricfloat          sqrtf(float x);
127*0b57cec5SDimitry Andriclong double    sqrtl(long double x);
128*0b57cec5SDimitry Andric
129*0b57cec5SDimitry Andricfloating_point tan (arithmetic x);
130*0b57cec5SDimitry Andricfloat          tanf(float x);
131*0b57cec5SDimitry Andriclong double    tanl(long double x);
132*0b57cec5SDimitry Andric
133*0b57cec5SDimitry Andricfloating_point tanh (arithmetic x);
134*0b57cec5SDimitry Andricfloat          tanhf(float x);
135*0b57cec5SDimitry Andriclong double    tanhl(long double x);
136*0b57cec5SDimitry Andric
137*0b57cec5SDimitry Andric//  C99
138*0b57cec5SDimitry Andric
139*0b57cec5SDimitry Andricbool signbit(arithmetic x);
140*0b57cec5SDimitry Andric
141*0b57cec5SDimitry Andricint fpclassify(arithmetic x);
142*0b57cec5SDimitry Andric
143*0b57cec5SDimitry Andricbool isfinite(arithmetic x);
144*0b57cec5SDimitry Andricbool isinf(arithmetic x);
145*0b57cec5SDimitry Andricbool isnan(arithmetic x);
146*0b57cec5SDimitry Andricbool isnormal(arithmetic x);
147*0b57cec5SDimitry Andric
148*0b57cec5SDimitry Andricbool isgreater(arithmetic x, arithmetic y);
149*0b57cec5SDimitry Andricbool isgreaterequal(arithmetic x, arithmetic y);
150*0b57cec5SDimitry Andricbool isless(arithmetic x, arithmetic y);
151*0b57cec5SDimitry Andricbool islessequal(arithmetic x, arithmetic y);
152*0b57cec5SDimitry Andricbool islessgreater(arithmetic x, arithmetic y);
153*0b57cec5SDimitry Andricbool isunordered(arithmetic x, arithmetic y);
154*0b57cec5SDimitry Andric
155*0b57cec5SDimitry Andricfloating_point acosh (arithmetic x);
156*0b57cec5SDimitry Andricfloat          acoshf(float x);
157*0b57cec5SDimitry Andriclong double    acoshl(long double x);
158*0b57cec5SDimitry Andric
159*0b57cec5SDimitry Andricfloating_point asinh (arithmetic x);
160*0b57cec5SDimitry Andricfloat          asinhf(float x);
161*0b57cec5SDimitry Andriclong double    asinhl(long double x);
162*0b57cec5SDimitry Andric
163*0b57cec5SDimitry Andricfloating_point atanh (arithmetic x);
164*0b57cec5SDimitry Andricfloat          atanhf(float x);
165*0b57cec5SDimitry Andriclong double    atanhl(long double x);
166*0b57cec5SDimitry Andric
167*0b57cec5SDimitry Andricfloating_point cbrt (arithmetic x);
168*0b57cec5SDimitry Andricfloat          cbrtf(float x);
169*0b57cec5SDimitry Andriclong double    cbrtl(long double x);
170*0b57cec5SDimitry Andric
171*0b57cec5SDimitry Andricfloating_point copysign (arithmetic x, arithmetic y);
172*0b57cec5SDimitry Andricfloat          copysignf(float x, float y);
173*0b57cec5SDimitry Andriclong double    copysignl(long double x, long double y);
174*0b57cec5SDimitry Andric
175*0b57cec5SDimitry Andricfloating_point erf (arithmetic x);
176*0b57cec5SDimitry Andricfloat          erff(float x);
177*0b57cec5SDimitry Andriclong double    erfl(long double x);
178*0b57cec5SDimitry Andric
179*0b57cec5SDimitry Andricfloating_point erfc (arithmetic x);
180*0b57cec5SDimitry Andricfloat          erfcf(float x);
181*0b57cec5SDimitry Andriclong double    erfcl(long double x);
182*0b57cec5SDimitry Andric
183*0b57cec5SDimitry Andricfloating_point exp2 (arithmetic x);
184*0b57cec5SDimitry Andricfloat          exp2f(float x);
185*0b57cec5SDimitry Andriclong double    exp2l(long double x);
186*0b57cec5SDimitry Andric
187*0b57cec5SDimitry Andricfloating_point expm1 (arithmetic x);
188*0b57cec5SDimitry Andricfloat          expm1f(float x);
189*0b57cec5SDimitry Andriclong double    expm1l(long double x);
190*0b57cec5SDimitry Andric
191*0b57cec5SDimitry Andricfloating_point fdim (arithmetic x, arithmetic y);
192*0b57cec5SDimitry Andricfloat          fdimf(float x, float y);
193*0b57cec5SDimitry Andriclong double    fdiml(long double x, long double y);
194*0b57cec5SDimitry Andric
195*0b57cec5SDimitry Andricfloating_point fma (arithmetic x, arithmetic y, arithmetic z);
196*0b57cec5SDimitry Andricfloat          fmaf(float x, float y, float z);
197*0b57cec5SDimitry Andriclong double    fmal(long double x, long double y, long double z);
198*0b57cec5SDimitry Andric
199*0b57cec5SDimitry Andricfloating_point fmax (arithmetic x, arithmetic y);
200*0b57cec5SDimitry Andricfloat          fmaxf(float x, float y);
201*0b57cec5SDimitry Andriclong double    fmaxl(long double x, long double y);
202*0b57cec5SDimitry Andric
203*0b57cec5SDimitry Andricfloating_point fmin (arithmetic x, arithmetic y);
204*0b57cec5SDimitry Andricfloat          fminf(float x, float y);
205*0b57cec5SDimitry Andriclong double    fminl(long double x, long double y);
206*0b57cec5SDimitry Andric
207*0b57cec5SDimitry Andricfloating_point hypot (arithmetic x, arithmetic y);
208*0b57cec5SDimitry Andricfloat          hypotf(float x, float y);
209*0b57cec5SDimitry Andriclong double    hypotl(long double x, long double y);
210*0b57cec5SDimitry Andric
211*0b57cec5SDimitry Andricdouble       hypot(double x, double y, double z);                // C++17
212*0b57cec5SDimitry Andricfloat        hypot(float x, float y, float z);                   // C++17
213*0b57cec5SDimitry Andriclong double  hypot(long double x, long double y, long double z); // C++17
214*0b57cec5SDimitry Andric
215*0b57cec5SDimitry Andricint ilogb (arithmetic x);
216*0b57cec5SDimitry Andricint ilogbf(float x);
217*0b57cec5SDimitry Andricint ilogbl(long double x);
218*0b57cec5SDimitry Andric
219*0b57cec5SDimitry Andricfloating_point lgamma (arithmetic x);
220*0b57cec5SDimitry Andricfloat          lgammaf(float x);
221*0b57cec5SDimitry Andriclong double    lgammal(long double x);
222*0b57cec5SDimitry Andric
223*0b57cec5SDimitry Andriclong long llrint (arithmetic x);
224*0b57cec5SDimitry Andriclong long llrintf(float x);
225*0b57cec5SDimitry Andriclong long llrintl(long double x);
226*0b57cec5SDimitry Andric
227*0b57cec5SDimitry Andriclong long llround (arithmetic x);
228*0b57cec5SDimitry Andriclong long llroundf(float x);
229*0b57cec5SDimitry Andriclong long llroundl(long double x);
230*0b57cec5SDimitry Andric
231*0b57cec5SDimitry Andricfloating_point log1p (arithmetic x);
232*0b57cec5SDimitry Andricfloat          log1pf(float x);
233*0b57cec5SDimitry Andriclong double    log1pl(long double x);
234*0b57cec5SDimitry Andric
235*0b57cec5SDimitry Andricfloating_point log2 (arithmetic x);
236*0b57cec5SDimitry Andricfloat          log2f(float x);
237*0b57cec5SDimitry Andriclong double    log2l(long double x);
238*0b57cec5SDimitry Andric
239*0b57cec5SDimitry Andricfloating_point logb (arithmetic x);
240*0b57cec5SDimitry Andricfloat          logbf(float x);
241*0b57cec5SDimitry Andriclong double    logbl(long double x);
242*0b57cec5SDimitry Andric
243*0b57cec5SDimitry Andriclong lrint (arithmetic x);
244*0b57cec5SDimitry Andriclong lrintf(float x);
245*0b57cec5SDimitry Andriclong lrintl(long double x);
246*0b57cec5SDimitry Andric
247*0b57cec5SDimitry Andriclong lround (arithmetic x);
248*0b57cec5SDimitry Andriclong lroundf(float x);
249*0b57cec5SDimitry Andriclong lroundl(long double x);
250*0b57cec5SDimitry Andric
251*0b57cec5SDimitry Andricdouble      nan (const char* str);
252*0b57cec5SDimitry Andricfloat       nanf(const char* str);
253*0b57cec5SDimitry Andriclong double nanl(const char* str);
254*0b57cec5SDimitry Andric
255*0b57cec5SDimitry Andricfloating_point nearbyint (arithmetic x);
256*0b57cec5SDimitry Andricfloat          nearbyintf(float x);
257*0b57cec5SDimitry Andriclong double    nearbyintl(long double x);
258*0b57cec5SDimitry Andric
259*0b57cec5SDimitry Andricfloating_point nextafter (arithmetic x, arithmetic y);
260*0b57cec5SDimitry Andricfloat          nextafterf(float x, float y);
261*0b57cec5SDimitry Andriclong double    nextafterl(long double x, long double y);
262*0b57cec5SDimitry Andric
263*0b57cec5SDimitry Andricfloating_point nexttoward (arithmetic x, long double y);
264*0b57cec5SDimitry Andricfloat          nexttowardf(float x, long double y);
265*0b57cec5SDimitry Andriclong double    nexttowardl(long double x, long double y);
266*0b57cec5SDimitry Andric
267*0b57cec5SDimitry Andricfloating_point remainder (arithmetic x, arithmetic y);
268*0b57cec5SDimitry Andricfloat          remainderf(float x, float y);
269*0b57cec5SDimitry Andriclong double    remainderl(long double x, long double y);
270*0b57cec5SDimitry Andric
271*0b57cec5SDimitry Andricfloating_point remquo (arithmetic x, arithmetic y, int* pquo);
272*0b57cec5SDimitry Andricfloat          remquof(float x, float y, int* pquo);
273*0b57cec5SDimitry Andriclong double    remquol(long double x, long double y, int* pquo);
274*0b57cec5SDimitry Andric
275*0b57cec5SDimitry Andricfloating_point rint (arithmetic x);
276*0b57cec5SDimitry Andricfloat          rintf(float x);
277*0b57cec5SDimitry Andriclong double    rintl(long double x);
278*0b57cec5SDimitry Andric
279*0b57cec5SDimitry Andricfloating_point round (arithmetic x);
280*0b57cec5SDimitry Andricfloat          roundf(float x);
281*0b57cec5SDimitry Andriclong double    roundl(long double x);
282*0b57cec5SDimitry Andric
283*0b57cec5SDimitry Andricfloating_point scalbln (arithmetic x, long ex);
284*0b57cec5SDimitry Andricfloat          scalblnf(float x, long ex);
285*0b57cec5SDimitry Andriclong double    scalblnl(long double x, long ex);
286*0b57cec5SDimitry Andric
287*0b57cec5SDimitry Andricfloating_point scalbn (arithmetic x, int ex);
288*0b57cec5SDimitry Andricfloat          scalbnf(float x, int ex);
289*0b57cec5SDimitry Andriclong double    scalbnl(long double x, int ex);
290*0b57cec5SDimitry Andric
291*0b57cec5SDimitry Andricfloating_point tgamma (arithmetic x);
292*0b57cec5SDimitry Andricfloat          tgammaf(float x);
293*0b57cec5SDimitry Andriclong double    tgammal(long double x);
294*0b57cec5SDimitry Andric
295*0b57cec5SDimitry Andricfloating_point trunc (arithmetic x);
296*0b57cec5SDimitry Andricfloat          truncf(float x);
297*0b57cec5SDimitry Andriclong double    truncl(long double x);
298*0b57cec5SDimitry Andric
299*0b57cec5SDimitry Andric}  // std
300*0b57cec5SDimitry Andric
301*0b57cec5SDimitry Andric*/
302*0b57cec5SDimitry Andric
303*0b57cec5SDimitry Andric#include <__config>
304*0b57cec5SDimitry Andric#include <math.h>
305*0b57cec5SDimitry Andric#include <version>
306*0b57cec5SDimitry Andric#include <type_traits>
307*0b57cec5SDimitry Andric
308*0b57cec5SDimitry Andric#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
309*0b57cec5SDimitry Andric#pragma GCC system_header
310*0b57cec5SDimitry Andric#endif
311*0b57cec5SDimitry Andric
312*0b57cec5SDimitry Andric_LIBCPP_PUSH_MACROS
313*0b57cec5SDimitry Andric#include <__undef_macros>
314*0b57cec5SDimitry Andric
315*0b57cec5SDimitry Andric_LIBCPP_BEGIN_NAMESPACE_STD
316*0b57cec5SDimitry Andric
317*0b57cec5SDimitry Andricusing ::signbit;
318*0b57cec5SDimitry Andricusing ::fpclassify;
319*0b57cec5SDimitry Andricusing ::isfinite;
320*0b57cec5SDimitry Andricusing ::isinf;
321*0b57cec5SDimitry Andricusing ::isnan;
322*0b57cec5SDimitry Andricusing ::isnormal;
323*0b57cec5SDimitry Andricusing ::isgreater;
324*0b57cec5SDimitry Andricusing ::isgreaterequal;
325*0b57cec5SDimitry Andricusing ::isless;
326*0b57cec5SDimitry Andricusing ::islessequal;
327*0b57cec5SDimitry Andricusing ::islessgreater;
328*0b57cec5SDimitry Andricusing ::isunordered;
329*0b57cec5SDimitry Andricusing ::isunordered;
330*0b57cec5SDimitry Andric
331*0b57cec5SDimitry Andricusing ::float_t;
332*0b57cec5SDimitry Andricusing ::double_t;
333*0b57cec5SDimitry Andric
334*0b57cec5SDimitry Andric#ifndef _AIX
335*0b57cec5SDimitry Andricusing ::abs;
336*0b57cec5SDimitry Andric#endif
337*0b57cec5SDimitry Andric
338*0b57cec5SDimitry Andricusing ::acos;
339*0b57cec5SDimitry Andricusing ::acosf;
340*0b57cec5SDimitry Andricusing ::asin;
341*0b57cec5SDimitry Andricusing ::asinf;
342*0b57cec5SDimitry Andricusing ::atan;
343*0b57cec5SDimitry Andricusing ::atanf;
344*0b57cec5SDimitry Andricusing ::atan2;
345*0b57cec5SDimitry Andricusing ::atan2f;
346*0b57cec5SDimitry Andricusing ::ceil;
347*0b57cec5SDimitry Andricusing ::ceilf;
348*0b57cec5SDimitry Andricusing ::cos;
349*0b57cec5SDimitry Andricusing ::cosf;
350*0b57cec5SDimitry Andricusing ::cosh;
351*0b57cec5SDimitry Andricusing ::coshf;
352*0b57cec5SDimitry Andric
353*0b57cec5SDimitry Andricusing ::exp;
354*0b57cec5SDimitry Andricusing ::expf;
355*0b57cec5SDimitry Andric
356*0b57cec5SDimitry Andricusing ::fabs;
357*0b57cec5SDimitry Andricusing ::fabsf;
358*0b57cec5SDimitry Andricusing ::floor;
359*0b57cec5SDimitry Andricusing ::floorf;
360*0b57cec5SDimitry Andric
361*0b57cec5SDimitry Andricusing ::fmod;
362*0b57cec5SDimitry Andricusing ::fmodf;
363*0b57cec5SDimitry Andric
364*0b57cec5SDimitry Andricusing ::frexp;
365*0b57cec5SDimitry Andricusing ::frexpf;
366*0b57cec5SDimitry Andricusing ::ldexp;
367*0b57cec5SDimitry Andricusing ::ldexpf;
368*0b57cec5SDimitry Andric
369*0b57cec5SDimitry Andricusing ::log;
370*0b57cec5SDimitry Andricusing ::logf;
371*0b57cec5SDimitry Andric
372*0b57cec5SDimitry Andricusing ::log10;
373*0b57cec5SDimitry Andricusing ::log10f;
374*0b57cec5SDimitry Andricusing ::modf;
375*0b57cec5SDimitry Andricusing ::modff;
376*0b57cec5SDimitry Andric
377*0b57cec5SDimitry Andricusing ::pow;
378*0b57cec5SDimitry Andricusing ::powf;
379*0b57cec5SDimitry Andric
380*0b57cec5SDimitry Andricusing ::sin;
381*0b57cec5SDimitry Andricusing ::sinf;
382*0b57cec5SDimitry Andricusing ::sinh;
383*0b57cec5SDimitry Andricusing ::sinhf;
384*0b57cec5SDimitry Andric
385*0b57cec5SDimitry Andricusing ::sqrt;
386*0b57cec5SDimitry Andricusing ::sqrtf;
387*0b57cec5SDimitry Andricusing ::tan;
388*0b57cec5SDimitry Andricusing ::tanf;
389*0b57cec5SDimitry Andric
390*0b57cec5SDimitry Andricusing ::tanh;
391*0b57cec5SDimitry Andricusing ::tanhf;
392*0b57cec5SDimitry Andric
393*0b57cec5SDimitry Andricusing ::acosh;
394*0b57cec5SDimitry Andricusing ::acoshf;
395*0b57cec5SDimitry Andricusing ::asinh;
396*0b57cec5SDimitry Andricusing ::asinhf;
397*0b57cec5SDimitry Andricusing ::atanh;
398*0b57cec5SDimitry Andricusing ::atanhf;
399*0b57cec5SDimitry Andricusing ::cbrt;
400*0b57cec5SDimitry Andricusing ::cbrtf;
401*0b57cec5SDimitry Andric
402*0b57cec5SDimitry Andricusing ::copysign;
403*0b57cec5SDimitry Andricusing ::copysignf;
404*0b57cec5SDimitry Andric
405*0b57cec5SDimitry Andricusing ::erf;
406*0b57cec5SDimitry Andricusing ::erff;
407*0b57cec5SDimitry Andricusing ::erfc;
408*0b57cec5SDimitry Andricusing ::erfcf;
409*0b57cec5SDimitry Andricusing ::exp2;
410*0b57cec5SDimitry Andricusing ::exp2f;
411*0b57cec5SDimitry Andricusing ::expm1;
412*0b57cec5SDimitry Andricusing ::expm1f;
413*0b57cec5SDimitry Andricusing ::fdim;
414*0b57cec5SDimitry Andricusing ::fdimf;
415*0b57cec5SDimitry Andricusing ::fmaf;
416*0b57cec5SDimitry Andricusing ::fma;
417*0b57cec5SDimitry Andricusing ::fmax;
418*0b57cec5SDimitry Andricusing ::fmaxf;
419*0b57cec5SDimitry Andricusing ::fmin;
420*0b57cec5SDimitry Andricusing ::fminf;
421*0b57cec5SDimitry Andricusing ::hypot;
422*0b57cec5SDimitry Andricusing ::hypotf;
423*0b57cec5SDimitry Andricusing ::ilogb;
424*0b57cec5SDimitry Andricusing ::ilogbf;
425*0b57cec5SDimitry Andricusing ::lgamma;
426*0b57cec5SDimitry Andricusing ::lgammaf;
427*0b57cec5SDimitry Andricusing ::llrint;
428*0b57cec5SDimitry Andricusing ::llrintf;
429*0b57cec5SDimitry Andricusing ::llround;
430*0b57cec5SDimitry Andricusing ::llroundf;
431*0b57cec5SDimitry Andricusing ::log1p;
432*0b57cec5SDimitry Andricusing ::log1pf;
433*0b57cec5SDimitry Andricusing ::log2;
434*0b57cec5SDimitry Andricusing ::log2f;
435*0b57cec5SDimitry Andricusing ::logb;
436*0b57cec5SDimitry Andricusing ::logbf;
437*0b57cec5SDimitry Andricusing ::lrint;
438*0b57cec5SDimitry Andricusing ::lrintf;
439*0b57cec5SDimitry Andricusing ::lround;
440*0b57cec5SDimitry Andricusing ::lroundf;
441*0b57cec5SDimitry Andric
442*0b57cec5SDimitry Andricusing ::nan;
443*0b57cec5SDimitry Andricusing ::nanf;
444*0b57cec5SDimitry Andric
445*0b57cec5SDimitry Andricusing ::nearbyint;
446*0b57cec5SDimitry Andricusing ::nearbyintf;
447*0b57cec5SDimitry Andricusing ::nextafter;
448*0b57cec5SDimitry Andricusing ::nextafterf;
449*0b57cec5SDimitry Andricusing ::nexttoward;
450*0b57cec5SDimitry Andricusing ::nexttowardf;
451*0b57cec5SDimitry Andricusing ::remainder;
452*0b57cec5SDimitry Andricusing ::remainderf;
453*0b57cec5SDimitry Andricusing ::remquo;
454*0b57cec5SDimitry Andricusing ::remquof;
455*0b57cec5SDimitry Andricusing ::rint;
456*0b57cec5SDimitry Andricusing ::rintf;
457*0b57cec5SDimitry Andricusing ::round;
458*0b57cec5SDimitry Andricusing ::roundf;
459*0b57cec5SDimitry Andricusing ::scalbln;
460*0b57cec5SDimitry Andricusing ::scalblnf;
461*0b57cec5SDimitry Andricusing ::scalbn;
462*0b57cec5SDimitry Andricusing ::scalbnf;
463*0b57cec5SDimitry Andricusing ::tgamma;
464*0b57cec5SDimitry Andricusing ::tgammaf;
465*0b57cec5SDimitry Andricusing ::trunc;
466*0b57cec5SDimitry Andricusing ::truncf;
467*0b57cec5SDimitry Andric
468*0b57cec5SDimitry Andricusing ::acosl;
469*0b57cec5SDimitry Andricusing ::asinl;
470*0b57cec5SDimitry Andricusing ::atanl;
471*0b57cec5SDimitry Andricusing ::atan2l;
472*0b57cec5SDimitry Andricusing ::ceill;
473*0b57cec5SDimitry Andricusing ::cosl;
474*0b57cec5SDimitry Andricusing ::coshl;
475*0b57cec5SDimitry Andricusing ::expl;
476*0b57cec5SDimitry Andricusing ::fabsl;
477*0b57cec5SDimitry Andricusing ::floorl;
478*0b57cec5SDimitry Andricusing ::fmodl;
479*0b57cec5SDimitry Andricusing ::frexpl;
480*0b57cec5SDimitry Andricusing ::ldexpl;
481*0b57cec5SDimitry Andricusing ::logl;
482*0b57cec5SDimitry Andricusing ::log10l;
483*0b57cec5SDimitry Andricusing ::modfl;
484*0b57cec5SDimitry Andricusing ::powl;
485*0b57cec5SDimitry Andricusing ::sinl;
486*0b57cec5SDimitry Andricusing ::sinhl;
487*0b57cec5SDimitry Andricusing ::sqrtl;
488*0b57cec5SDimitry Andricusing ::tanl;
489*0b57cec5SDimitry Andric
490*0b57cec5SDimitry Andricusing ::tanhl;
491*0b57cec5SDimitry Andricusing ::acoshl;
492*0b57cec5SDimitry Andricusing ::asinhl;
493*0b57cec5SDimitry Andricusing ::atanhl;
494*0b57cec5SDimitry Andricusing ::cbrtl;
495*0b57cec5SDimitry Andric
496*0b57cec5SDimitry Andricusing ::copysignl;
497*0b57cec5SDimitry Andric
498*0b57cec5SDimitry Andricusing ::erfl;
499*0b57cec5SDimitry Andricusing ::erfcl;
500*0b57cec5SDimitry Andricusing ::exp2l;
501*0b57cec5SDimitry Andricusing ::expm1l;
502*0b57cec5SDimitry Andricusing ::fdiml;
503*0b57cec5SDimitry Andricusing ::fmal;
504*0b57cec5SDimitry Andricusing ::fmaxl;
505*0b57cec5SDimitry Andricusing ::fminl;
506*0b57cec5SDimitry Andricusing ::hypotl;
507*0b57cec5SDimitry Andricusing ::ilogbl;
508*0b57cec5SDimitry Andricusing ::lgammal;
509*0b57cec5SDimitry Andricusing ::llrintl;
510*0b57cec5SDimitry Andricusing ::llroundl;
511*0b57cec5SDimitry Andricusing ::log1pl;
512*0b57cec5SDimitry Andricusing ::log2l;
513*0b57cec5SDimitry Andricusing ::logbl;
514*0b57cec5SDimitry Andricusing ::lrintl;
515*0b57cec5SDimitry Andricusing ::lroundl;
516*0b57cec5SDimitry Andricusing ::nanl;
517*0b57cec5SDimitry Andricusing ::nearbyintl;
518*0b57cec5SDimitry Andricusing ::nextafterl;
519*0b57cec5SDimitry Andricusing ::nexttowardl;
520*0b57cec5SDimitry Andricusing ::remainderl;
521*0b57cec5SDimitry Andricusing ::remquol;
522*0b57cec5SDimitry Andricusing ::rintl;
523*0b57cec5SDimitry Andricusing ::roundl;
524*0b57cec5SDimitry Andricusing ::scalblnl;
525*0b57cec5SDimitry Andricusing ::scalbnl;
526*0b57cec5SDimitry Andricusing ::tgammal;
527*0b57cec5SDimitry Andricusing ::truncl;
528*0b57cec5SDimitry Andric
529*0b57cec5SDimitry Andric#if _LIBCPP_STD_VER > 14
530*0b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY float       hypot(       float x,       float y,       float z ) { return sqrt(x*x + y*y + z*z); }
531*0b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY double      hypot(      double x,      double y,      double z ) { return sqrt(x*x + y*y + z*z); }
532*0b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY long double hypot( long double x, long double y, long double z ) { return sqrt(x*x + y*y + z*z); }
533*0b57cec5SDimitry Andric
534*0b57cec5SDimitry Andrictemplate <class _A1, class _A2, class _A3>
535*0b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
536*0b57cec5SDimitry Andrictypename _EnableIf
537*0b57cec5SDimitry Andric<
538*0b57cec5SDimitry Andric    is_arithmetic<_A1>::value &&
539*0b57cec5SDimitry Andric    is_arithmetic<_A2>::value &&
540*0b57cec5SDimitry Andric    is_arithmetic<_A3>::value,
541*0b57cec5SDimitry Andric    __promote<_A1, _A2, _A3>
542*0b57cec5SDimitry Andric>::type
543*0b57cec5SDimitry Andrichypot(_A1 __lcpp_x, _A2 __lcpp_y, _A3 __lcpp_z) _NOEXCEPT
544*0b57cec5SDimitry Andric{
545*0b57cec5SDimitry Andric    typedef typename __promote<_A1, _A2, _A3>::type __result_type;
546*0b57cec5SDimitry Andric    static_assert((!(is_same<_A1, __result_type>::value &&
547*0b57cec5SDimitry Andric                     is_same<_A2, __result_type>::value &&
548*0b57cec5SDimitry Andric                     is_same<_A3, __result_type>::value)), "");
549*0b57cec5SDimitry Andric    return hypot((__result_type)__lcpp_x, (__result_type)__lcpp_y, (__result_type)__lcpp_z);
550*0b57cec5SDimitry Andric}
551*0b57cec5SDimitry Andric#endif
552*0b57cec5SDimitry Andric
553*0b57cec5SDimitry Andrictemplate <class _A1>
554*0b57cec5SDimitry Andric_LIBCPP_INLINE_VISIBILITY
555*0b57cec5SDimitry Andric_LIBCPP_CONSTEXPR typename enable_if<is_floating_point<_A1>::value, bool>::type
556*0b57cec5SDimitry Andric__libcpp_isnan_or_builtin(_A1 __lcpp_x) _NOEXCEPT
557*0b57cec5SDimitry Andric{
558*0b57cec5SDimitry Andric#if __has_builtin(__builtin_isnan)
559*0b57cec5SDimitry Andric    return __builtin_isnan(__lcpp_x);
560*0b57cec5SDimitry Andric#else
561*0b57cec5SDimitry Andric    return isnan(__lcpp_x);
562*0b57cec5SDimitry Andric#endif
563*0b57cec5SDimitry Andric}
564*0b57cec5SDimitry Andric
565*0b57cec5SDimitry Andrictemplate <class _A1>
566*0b57cec5SDimitry Andric_LIBCPP_INLINE_VISIBILITY
567*0b57cec5SDimitry Andric_LIBCPP_CONSTEXPR typename enable_if<!is_floating_point<_A1>::value, bool>::type
568*0b57cec5SDimitry Andric__libcpp_isnan_or_builtin(_A1 __lcpp_x) _NOEXCEPT
569*0b57cec5SDimitry Andric{
570*0b57cec5SDimitry Andric    return isnan(__lcpp_x);
571*0b57cec5SDimitry Andric}
572*0b57cec5SDimitry Andric
573*0b57cec5SDimitry Andrictemplate <class _A1>
574*0b57cec5SDimitry Andric_LIBCPP_INLINE_VISIBILITY
575*0b57cec5SDimitry Andric_LIBCPP_CONSTEXPR typename enable_if<is_floating_point<_A1>::value, bool>::type
576*0b57cec5SDimitry Andric__libcpp_isinf_or_builtin(_A1 __lcpp_x) _NOEXCEPT
577*0b57cec5SDimitry Andric{
578*0b57cec5SDimitry Andric#if __has_builtin(__builtin_isinf)
579*0b57cec5SDimitry Andric    return __builtin_isinf(__lcpp_x);
580*0b57cec5SDimitry Andric#else
581*0b57cec5SDimitry Andric    return isinf(__lcpp_x);
582*0b57cec5SDimitry Andric#endif
583*0b57cec5SDimitry Andric}
584*0b57cec5SDimitry Andric
585*0b57cec5SDimitry Andrictemplate <class _A1>
586*0b57cec5SDimitry Andric_LIBCPP_INLINE_VISIBILITY
587*0b57cec5SDimitry Andric_LIBCPP_CONSTEXPR typename enable_if<!is_floating_point<_A1>::value, bool>::type
588*0b57cec5SDimitry Andric__libcpp_isinf_or_builtin(_A1 __lcpp_x) _NOEXCEPT
589*0b57cec5SDimitry Andric{
590*0b57cec5SDimitry Andric    return isinf(__lcpp_x);
591*0b57cec5SDimitry Andric}
592*0b57cec5SDimitry Andric
593*0b57cec5SDimitry Andrictemplate <class _A1>
594*0b57cec5SDimitry Andric_LIBCPP_INLINE_VISIBILITY
595*0b57cec5SDimitry Andric_LIBCPP_CONSTEXPR typename enable_if<is_floating_point<_A1>::value, bool>::type
596*0b57cec5SDimitry Andric__libcpp_isfinite_or_builtin(_A1 __lcpp_x) _NOEXCEPT
597*0b57cec5SDimitry Andric{
598*0b57cec5SDimitry Andric#if __has_builtin(__builtin_isfinite)
599*0b57cec5SDimitry Andric    return __builtin_isfinite(__lcpp_x);
600*0b57cec5SDimitry Andric#else
601*0b57cec5SDimitry Andric    return isfinite(__lcpp_x);
602*0b57cec5SDimitry Andric#endif
603*0b57cec5SDimitry Andric}
604*0b57cec5SDimitry Andric
605*0b57cec5SDimitry Andrictemplate <class _A1>
606*0b57cec5SDimitry Andric_LIBCPP_INLINE_VISIBILITY
607*0b57cec5SDimitry Andric_LIBCPP_CONSTEXPR typename enable_if<!is_floating_point<_A1>::value, bool>::type
608*0b57cec5SDimitry Andric__libcpp_isfinite_or_builtin(_A1 __lcpp_x) _NOEXCEPT
609*0b57cec5SDimitry Andric{
610*0b57cec5SDimitry Andric    return isfinite(__lcpp_x);
611*0b57cec5SDimitry Andric}
612*0b57cec5SDimitry Andric
613*0b57cec5SDimitry Andric#if _LIBCPP_STD_VER > 17
614*0b57cec5SDimitry Andrictemplate <typename _Fp>
615*0b57cec5SDimitry Andricconstexpr
616*0b57cec5SDimitry Andric_Fp __lerp(_Fp __a, _Fp __b, _Fp __t) noexcept {
617*0b57cec5SDimitry Andric    if ((__a <= 0 && __b >= 0) || (__a >= 0 && __b <= 0))
618*0b57cec5SDimitry Andric        return __t * __b + (1 - __t) * __a;
619*0b57cec5SDimitry Andric
620*0b57cec5SDimitry Andric    if (__t == 1) return __b;
621*0b57cec5SDimitry Andric    const _Fp __x = __a + __t * (__b - __a);
622*0b57cec5SDimitry Andric    if (__t > 1 == __b > __a)
623*0b57cec5SDimitry Andric    	return __b < __x ? __x : __b;
624*0b57cec5SDimitry Andric    else
625*0b57cec5SDimitry Andric    	return __x < __b ? __x : __b;
626*0b57cec5SDimitry Andric}
627*0b57cec5SDimitry Andric
628*0b57cec5SDimitry Andricconstexpr float
629*0b57cec5SDimitry Andriclerp(float __a, float __b, float __t)                   _NOEXCEPT { return __lerp(__a, __b, __t); }
630*0b57cec5SDimitry Andric
631*0b57cec5SDimitry Andricconstexpr double
632*0b57cec5SDimitry Andriclerp(double __a, double __b, double __t)                _NOEXCEPT { return __lerp(__a, __b, __t); }
633*0b57cec5SDimitry Andric
634*0b57cec5SDimitry Andricconstexpr long double
635*0b57cec5SDimitry Andriclerp(long double __a, long double __b, long double __t) _NOEXCEPT { return __lerp(__a, __b, __t); }
636*0b57cec5SDimitry Andric
637*0b57cec5SDimitry Andric#endif // _LIBCPP_STD_VER > 17
638*0b57cec5SDimitry Andric
639*0b57cec5SDimitry Andrictemplate <class _IntT, class _FloatT,
640*0b57cec5SDimitry Andric    bool _FloatBigger = (numeric_limits<_FloatT>::digits > numeric_limits<_IntT>::digits),
641*0b57cec5SDimitry Andric    int _Bits = (numeric_limits<_IntT>::digits - numeric_limits<_FloatT>::digits)>
642*0b57cec5SDimitry Andric_LIBCPP_INLINE_VISIBILITY
643*0b57cec5SDimitry Andric_LIBCPP_CONSTEXPR _IntT __max_representable_int_for_float() _NOEXCEPT {
644*0b57cec5SDimitry Andric  static_assert(is_floating_point<_FloatT>::value, "must be a floating point type");
645*0b57cec5SDimitry Andric  static_assert(is_integral<_IntT>::value, "must be an integral type");
646*0b57cec5SDimitry Andric  static_assert(numeric_limits<_FloatT>::radix == 2, "FloatT has incorrect radix");
647*0b57cec5SDimitry Andric  static_assert((_IsSame<_FloatT, float>::value || _IsSame<_FloatT, double>::value
648*0b57cec5SDimitry Andric                 || _IsSame<_FloatT,long double>::value), "unsupported floating point type");
649*0b57cec5SDimitry Andric  return _FloatBigger ? numeric_limits<_IntT>::max() :  (numeric_limits<_IntT>::max() >> _Bits << _Bits);
650*0b57cec5SDimitry Andric}
651*0b57cec5SDimitry Andric
652*0b57cec5SDimitry Andric// Convert a floating point number to the specified integral type after
653*0b57cec5SDimitry Andric// clamping to the integral types representable range.
654*0b57cec5SDimitry Andric//
655*0b57cec5SDimitry Andric// The behavior is undefined if `__r` is NaN.
656*0b57cec5SDimitry Andrictemplate <class _IntT, class _RealT>
657*0b57cec5SDimitry Andric_LIBCPP_INLINE_VISIBILITY
658*0b57cec5SDimitry Andric_IntT __clamp_to_integral(_RealT __r) _NOEXCEPT {
659*0b57cec5SDimitry Andric  using _Lim = std::numeric_limits<_IntT>;
660*0b57cec5SDimitry Andric  const _IntT _MaxVal = std::__max_representable_int_for_float<_IntT, _RealT>();
661*0b57cec5SDimitry Andric  if (__r >= ::nextafter(static_cast<_RealT>(_MaxVal), INFINITY)) {
662*0b57cec5SDimitry Andric    return _Lim::max();
663*0b57cec5SDimitry Andric  } else if (__r <= _Lim::lowest()) {
664*0b57cec5SDimitry Andric    return _Lim::min();
665*0b57cec5SDimitry Andric  }
666*0b57cec5SDimitry Andric  return static_cast<_IntT>(__r);
667*0b57cec5SDimitry Andric}
668*0b57cec5SDimitry Andric
669*0b57cec5SDimitry Andric_LIBCPP_END_NAMESPACE_STD
670*0b57cec5SDimitry Andric
671*0b57cec5SDimitry Andric_LIBCPP_POP_MACROS
672*0b57cec5SDimitry Andric
673*0b57cec5SDimitry Andric#endif  // _LIBCPP_CMATH
674