blob: a23d1ff3ed378a4ff60f4f882e4a93bce0590385 [file] [log] [blame]
Richard Smith081bb592015-10-08 20:40:34 +00001// -*- C++ -*-
Louis Dionne9bd93882021-11-17 16:25:01 -05002//===----------------------------------------------------------------------===//
Richard Smith081bb592015-10-08 20:40:34 +00003//
Chandler Carruthd2012102019-01-19 10:56:40 +00004// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5// See https://llvm.org/LICENSE.txt for license information.
6// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
Richard Smith081bb592015-10-08 20:40:34 +00007//
8//===----------------------------------------------------------------------===//
9
10#ifndef _LIBCPP_MATH_H
11#define _LIBCPP_MATH_H
12
13/*
14 math.h synopsis
15
16Macros:
17
18 HUGE_VAL
19 HUGE_VALF // C99
20 HUGE_VALL // C99
21 INFINITY // C99
22 NAN // C99
23 FP_INFINITE // C99
24 FP_NAN // C99
25 FP_NORMAL // C99
26 FP_SUBNORMAL // C99
27 FP_ZERO // C99
28 FP_FAST_FMA // C99
29 FP_FAST_FMAF // C99
30 FP_FAST_FMAL // C99
31 FP_ILOGB0 // C99
32 FP_ILOGBNAN // C99
33 MATH_ERRNO // C99
34 MATH_ERREXCEPT // C99
35 math_errhandling // C99
36
37Types:
38
39 float_t // C99
40 double_t // C99
41
42// C90
43
44floating_point abs(floating_point x);
45
46floating_point acos (arithmetic x);
47float acosf(float x);
48long double acosl(long double x);
49
50floating_point asin (arithmetic x);
51float asinf(float x);
52long double asinl(long double x);
53
54floating_point atan (arithmetic x);
55float atanf(float x);
56long double atanl(long double x);
57
58floating_point atan2 (arithmetic y, arithmetic x);
59float atan2f(float y, float x);
60long double atan2l(long double y, long double x);
61
62floating_point ceil (arithmetic x);
63float ceilf(float x);
64long double ceill(long double x);
65
66floating_point cos (arithmetic x);
67float cosf(float x);
68long double cosl(long double x);
69
70floating_point cosh (arithmetic x);
71float coshf(float x);
72long double coshl(long double x);
73
74floating_point exp (arithmetic x);
75float expf(float x);
76long double expl(long double x);
77
78floating_point fabs (arithmetic x);
79float fabsf(float x);
80long double fabsl(long double x);
81
82floating_point floor (arithmetic x);
83float floorf(float x);
84long double floorl(long double x);
85
86floating_point fmod (arithmetic x, arithmetic y);
87float fmodf(float x, float y);
88long double fmodl(long double x, long double y);
89
90floating_point frexp (arithmetic value, int* exp);
91float frexpf(float value, int* exp);
92long double frexpl(long double value, int* exp);
93
94floating_point ldexp (arithmetic value, int exp);
95float ldexpf(float value, int exp);
96long double ldexpl(long double value, int exp);
97
98floating_point log (arithmetic x);
99float logf(float x);
100long double logl(long double x);
101
102floating_point log10 (arithmetic x);
103float log10f(float x);
104long double log10l(long double x);
105
106floating_point modf (floating_point value, floating_point* iptr);
107float modff(float value, float* iptr);
108long double modfl(long double value, long double* iptr);
109
110floating_point pow (arithmetic x, arithmetic y);
111float powf(float x, float y);
112long double powl(long double x, long double y);
113
114floating_point sin (arithmetic x);
115float sinf(float x);
116long double sinl(long double x);
117
118floating_point sinh (arithmetic x);
119float sinhf(float x);
120long double sinhl(long double x);
121
122floating_point sqrt (arithmetic x);
123float sqrtf(float x);
124long double sqrtl(long double x);
125
126floating_point tan (arithmetic x);
127float tanf(float x);
128long double tanl(long double x);
129
130floating_point tanh (arithmetic x);
131float tanhf(float x);
132long double tanhl(long double x);
133
134// C99
135
136bool signbit(arithmetic x);
137
138int fpclassify(arithmetic x);
139
140bool isfinite(arithmetic x);
141bool isinf(arithmetic x);
142bool isnan(arithmetic x);
143bool isnormal(arithmetic x);
144
145bool isgreater(arithmetic x, arithmetic y);
146bool isgreaterequal(arithmetic x, arithmetic y);
147bool isless(arithmetic x, arithmetic y);
148bool islessequal(arithmetic x, arithmetic y);
149bool islessgreater(arithmetic x, arithmetic y);
150bool isunordered(arithmetic x, arithmetic y);
151
152floating_point acosh (arithmetic x);
153float acoshf(float x);
154long double acoshl(long double x);
155
156floating_point asinh (arithmetic x);
157float asinhf(float x);
158long double asinhl(long double x);
159
160floating_point atanh (arithmetic x);
161float atanhf(float x);
162long double atanhl(long double x);
163
164floating_point cbrt (arithmetic x);
165float cbrtf(float x);
166long double cbrtl(long double x);
167
168floating_point copysign (arithmetic x, arithmetic y);
169float copysignf(float x, float y);
170long double copysignl(long double x, long double y);
171
172floating_point erf (arithmetic x);
173float erff(float x);
174long double erfl(long double x);
175
176floating_point erfc (arithmetic x);
177float erfcf(float x);
178long double erfcl(long double x);
179
180floating_point exp2 (arithmetic x);
181float exp2f(float x);
182long double exp2l(long double x);
183
184floating_point expm1 (arithmetic x);
185float expm1f(float x);
186long double expm1l(long double x);
187
188floating_point fdim (arithmetic x, arithmetic y);
189float fdimf(float x, float y);
190long double fdiml(long double x, long double y);
191
192floating_point fma (arithmetic x, arithmetic y, arithmetic z);
193float fmaf(float x, float y, float z);
194long double fmal(long double x, long double y, long double z);
195
196floating_point fmax (arithmetic x, arithmetic y);
197float fmaxf(float x, float y);
198long double fmaxl(long double x, long double y);
199
200floating_point fmin (arithmetic x, arithmetic y);
201float fminf(float x, float y);
202long double fminl(long double x, long double y);
203
204floating_point hypot (arithmetic x, arithmetic y);
205float hypotf(float x, float y);
206long double hypotl(long double x, long double y);
207
208int ilogb (arithmetic x);
209int ilogbf(float x);
210int ilogbl(long double x);
211
212floating_point lgamma (arithmetic x);
213float lgammaf(float x);
214long double lgammal(long double x);
215
216long long llrint (arithmetic x);
217long long llrintf(float x);
218long long llrintl(long double x);
219
220long long llround (arithmetic x);
221long long llroundf(float x);
222long long llroundl(long double x);
223
224floating_point log1p (arithmetic x);
225float log1pf(float x);
226long double log1pl(long double x);
227
228floating_point log2 (arithmetic x);
229float log2f(float x);
230long double log2l(long double x);
231
232floating_point logb (arithmetic x);
233float logbf(float x);
234long double logbl(long double x);
235
236long lrint (arithmetic x);
237long lrintf(float x);
238long lrintl(long double x);
239
240long lround (arithmetic x);
241long lroundf(float x);
242long lroundl(long double x);
243
244double nan (const char* str);
245float nanf(const char* str);
246long double nanl(const char* str);
247
248floating_point nearbyint (arithmetic x);
249float nearbyintf(float x);
250long double nearbyintl(long double x);
251
252floating_point nextafter (arithmetic x, arithmetic y);
253float nextafterf(float x, float y);
254long double nextafterl(long double x, long double y);
255
256floating_point nexttoward (arithmetic x, long double y);
257float nexttowardf(float x, long double y);
258long double nexttowardl(long double x, long double y);
259
260floating_point remainder (arithmetic x, arithmetic y);
261float remainderf(float x, float y);
262long double remainderl(long double x, long double y);
263
264floating_point remquo (arithmetic x, arithmetic y, int* pquo);
265float remquof(float x, float y, int* pquo);
266long double remquol(long double x, long double y, int* pquo);
267
268floating_point rint (arithmetic x);
269float rintf(float x);
270long double rintl(long double x);
271
272floating_point round (arithmetic x);
273float roundf(float x);
274long double roundl(long double x);
275
276floating_point scalbln (arithmetic x, long ex);
277float scalblnf(float x, long ex);
278long double scalblnl(long double x, long ex);
279
280floating_point scalbn (arithmetic x, int ex);
281float scalbnf(float x, int ex);
282long double scalbnl(long double x, int ex);
283
284floating_point tgamma (arithmetic x);
285float tgammaf(float x);
286long double tgammal(long double x);
287
288floating_point trunc (arithmetic x);
289float truncf(float x);
290long double truncl(long double x);
291
292*/
293
294#include <__config>
Richard Smith081bb592015-10-08 20:40:34 +0000295
296#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
Arthur O'Dwyer6eeaa002022-02-01 20:16:40 -0500297# pragma GCC system_header
Richard Smith081bb592015-10-08 20:40:34 +0000298#endif
299
Louis Dionnebe1aa9e2022-11-15 17:08:01 -0500300# if __has_include_next(<math.h>)
301# include_next <math.h>
302# endif
Mikhail Maltsev34b4f972018-02-22 09:34:08 +0000303
Richard Smith081bb592015-10-08 20:40:34 +0000304#ifdef __cplusplus
305
306// We support including .h headers inside 'extern "C"' contexts, so switch
307// back to C++ linkage before including these C++ headers.
308extern "C++" {
309
Nikolas Klauserca7ac532022-12-21 00:07:17 +0100310#include <__type_traits/enable_if.h>
311#include <__type_traits/is_floating_point.h>
312#include <__type_traits/is_integral.h>
313#include <__type_traits/is_same.h>
Nikolas Klauser6c8f7122022-07-24 16:03:12 +0200314#include <__type_traits/promote.h>
Arthur O'Dwyer65077c02022-01-07 09:45:05 -0500315#include <limits>
Eric Fiselier6c9e1a72020-02-15 18:55:07 -0500316#include <stdlib.h>
Richard Smith081bb592015-10-08 20:40:34 +0000317
Nikolas Klauserae1fbc42022-11-04 20:19:20 +0100318
319# ifdef fpclassify
320# undef fpclassify
321# endif
Richard Smith081bb592015-10-08 20:40:34 +0000322
Nikolas Klauser9a97dd72022-11-04 16:36:34 +0100323# ifdef signbit
Nikolas Klauser9a97dd72022-11-04 16:36:34 +0100324# undef signbit
Nikolas Klauserae1fbc42022-11-04 20:19:20 +0100325# endif
326
327# ifdef isfinite
328# undef isfinite
329# endif
330
331# ifdef isinf
332# undef isinf
333# endif
334
335# ifdef isnan
336# undef isnan
337# endif
338
339# ifdef isnormal
340# undef isnormal
341# endif
342
343# ifdef isgreater
344# undef isgreater
345# endif
346
347# ifdef isgreaterequal
348# undef isgreaterequal
349# endif
350
351# ifdef isless
352# undef isless
353# endif
354
355# ifdef islessequal
356# undef islessequal
357# endif
358
359# ifdef islessgreater
360# undef islessgreater
361# endif
362
363# ifdef isunordered
364# undef isunordered
365# endif
366
367// signbit
Richard Smith081bb592015-10-08 20:40:34 +0000368
Nikolas Klausere96070f2022-11-04 20:08:56 +0100369template <class _A1, std::__enable_if_t<std::is_floating_point<_A1>::value, int> = 0>
Nikolas Klauserb0bb09c2022-12-25 20:13:39 +0100370_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI bool signbit(_A1 __x) _NOEXCEPT {
Nikolas Klauser25fbc472022-11-04 16:56:51 +0100371 return __builtin_signbit(__x);
Richard Smith081bb592015-10-08 20:40:34 +0000372}
373
Nikolas Klausere96070f2022-11-04 20:08:56 +0100374template <class _A1, std::__enable_if_t<std::is_integral<_A1>::value && std::is_signed<_A1>::value, int> = 0>
Nikolas Klauserb0bb09c2022-12-25 20:13:39 +0100375_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI bool signbit(_A1 __x) _NOEXCEPT {
Nikolas Klauser9a97dd72022-11-04 16:36:34 +0100376 return __x < 0;
377}
Duncan P. N. Exon Smith321d6bf2017-04-21 23:14:55 +0000378
Nikolas Klausere96070f2022-11-04 20:08:56 +0100379template <class _A1, std::__enable_if_t<std::is_integral<_A1>::value && !std::is_signed<_A1>::value, int> = 0>
Nikolas Klauserb0bb09c2022-12-25 20:13:39 +0100380_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI bool signbit(_A1) _NOEXCEPT {
Nikolas Klauser9a97dd72022-11-04 16:36:34 +0100381 return false;
382}
Duncan P. N. Exon Smith321d6bf2017-04-21 23:14:55 +0000383
Richard Smith081bb592015-10-08 20:40:34 +0000384// fpclassify
385
Nikolas Klausere96070f2022-11-04 20:08:56 +0100386template <class _A1, std::__enable_if_t<std::is_floating_point<_A1>::value, int> = 0>
Nikolas Klauserb0bb09c2022-12-25 20:13:39 +0100387_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI int fpclassify(_A1 __x) _NOEXCEPT {
Nikolas Klauser25fbc472022-11-04 16:56:51 +0100388 return __builtin_fpclassify(FP_NAN, FP_INFINITE, FP_NORMAL, FP_SUBNORMAL, FP_ZERO, __x);
Richard Smith081bb592015-10-08 20:40:34 +0000389}
390
Nikolas Klausere96070f2022-11-04 20:08:56 +0100391template <class _A1, std::__enable_if_t<std::is_integral<_A1>::value, int> = 0>
Nikolas Klauserb0bb09c2022-12-25 20:13:39 +0100392_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI int fpclassify(_A1 __x) _NOEXCEPT {
Nikolas Klauser9a97dd72022-11-04 16:36:34 +0100393 return __x == 0 ? FP_ZERO : FP_NORMAL;
394}
Duncan P. N. Exon Smith321d6bf2017-04-21 23:14:55 +0000395
Nikolas Klauserae1fbc42022-11-04 20:19:20 +0100396// The MSVC runtime already provides these functions as templates
397#ifndef _LIBCPP_MSVCRT
Richard Smith081bb592015-10-08 20:40:34 +0000398
Nikolas Klauserae1fbc42022-11-04 20:19:20 +0100399// isfinite
Richard Smith081bb592015-10-08 20:40:34 +0000400
Nikolas Klausere96070f2022-11-04 20:08:56 +0100401template <class _A1,
402 std::__enable_if_t<std::is_arithmetic<_A1>::value && std::numeric_limits<_A1>::has_infinity, int> = 0>
Nikolas Klauserb0bb09c2022-12-25 20:13:39 +0100403_LIBCPP_NODISCARD_EXT _LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI bool isfinite(_A1 __x) _NOEXCEPT {
Nikolas Klauser25fbc472022-11-04 16:56:51 +0100404 return __builtin_isfinite((typename std::__promote<_A1>::type)__x);
Richard Smith081bb592015-10-08 20:40:34 +0000405}
406
Nikolas Klausere96070f2022-11-04 20:08:56 +0100407template <class _A1,
408 std::__enable_if_t<std::is_arithmetic<_A1>::value && !std::numeric_limits<_A1>::has_infinity, int> = 0>
Nikolas Klauserb0bb09c2022-12-25 20:13:39 +0100409_LIBCPP_NODISCARD_EXT _LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI bool isfinite(_A1) _NOEXCEPT {
Nikolas Klauser9a97dd72022-11-04 16:36:34 +0100410 return true;
411}
Duncan P. N. Exon Smith321d6bf2017-04-21 23:14:55 +0000412
Richard Smith081bb592015-10-08 20:40:34 +0000413// isinf
414
Nikolas Klausere96070f2022-11-04 20:08:56 +0100415template <class _A1,
416 std::__enable_if_t<std::is_arithmetic<_A1>::value && std::numeric_limits<_A1>::has_infinity, int> = 0>
Nikolas Klauserb0bb09c2022-12-25 20:13:39 +0100417_LIBCPP_NODISCARD_EXT _LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI bool isinf(_A1 __x) _NOEXCEPT {
Nikolas Klauser25fbc472022-11-04 16:56:51 +0100418 return __builtin_isinf((typename std::__promote<_A1>::type)__x);
Richard Smith081bb592015-10-08 20:40:34 +0000419}
420
Duncan P. N. Exon Smith321d6bf2017-04-21 23:14:55 +0000421template <class _A1>
Nikolas Klauserb0bb09c2022-12-25 20:13:39 +0100422_LIBCPP_NODISCARD_EXT _LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI
Nikolas Klauser9a97dd72022-11-04 16:36:34 +0100423 typename std::enable_if< std::is_arithmetic<_A1>::value && !std::numeric_limits<_A1>::has_infinity, bool>::type
424 isinf(_A1) _NOEXCEPT {
425 return false;
426}
Duncan P. N. Exon Smith321d6bf2017-04-21 23:14:55 +0000427
Nikolas Klauser9a97dd72022-11-04 16:36:34 +0100428# ifdef _LIBCPP_PREFERRED_OVERLOAD
Nikolas Klauserb0bb09c2022-12-25 20:13:39 +0100429_LIBCPP_NODISCARD_EXT inline _LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI bool isinf(float __x) _NOEXCEPT {
Nikolas Klauserdfc04a32022-12-19 00:02:44 +0100430 return __builtin_isinf(__x);
431}
Richard Smithafccfd32018-05-01 03:05:40 +0000432
Nikolas Klauserb0bb09c2022-12-25 20:13:39 +0100433_LIBCPP_NODISCARD_EXT inline _LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI _LIBCPP_PREFERRED_OVERLOAD bool isinf(double __x) _NOEXCEPT {
Nikolas Klauserdfc04a32022-12-19 00:02:44 +0100434 return __builtin_isinf(__x);
435}
Richard Smithafccfd32018-05-01 03:05:40 +0000436
Nikolas Klauserb0bb09c2022-12-25 20:13:39 +0100437_LIBCPP_NODISCARD_EXT inline _LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI bool isinf(long double __x) _NOEXCEPT {
Nikolas Klauserdfc04a32022-12-19 00:02:44 +0100438 return __builtin_isinf(__x);
439}
Nikolas Klauser9a97dd72022-11-04 16:36:34 +0100440# endif
Richard Smithafccfd32018-05-01 03:05:40 +0000441
Richard Smith081bb592015-10-08 20:40:34 +0000442// isnan
443
Nikolas Klausere96070f2022-11-04 20:08:56 +0100444template <class _A1, std::__enable_if_t<std::is_floating_point<_A1>::value, int> = 0>
Nikolas Klauserb0bb09c2022-12-25 20:13:39 +0100445_LIBCPP_NODISCARD_EXT _LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI bool isnan(_A1 __x) _NOEXCEPT {
Nikolas Klauser25fbc472022-11-04 16:56:51 +0100446 return __builtin_isnan(__x);
Richard Smith081bb592015-10-08 20:40:34 +0000447}
448
Nikolas Klausere96070f2022-11-04 20:08:56 +0100449template <class _A1, std::__enable_if_t<std::is_integral<_A1>::value, int> = 0>
Nikolas Klauserb0bb09c2022-12-25 20:13:39 +0100450_LIBCPP_NODISCARD_EXT _LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI bool isnan(_A1) _NOEXCEPT {
Nikolas Klauser9a97dd72022-11-04 16:36:34 +0100451 return false;
452}
Duncan P. N. Exon Smith321d6bf2017-04-21 23:14:55 +0000453
Nikolas Klauser9a97dd72022-11-04 16:36:34 +0100454# ifdef _LIBCPP_PREFERRED_OVERLOAD
Nikolas Klauserb0bb09c2022-12-25 20:13:39 +0100455_LIBCPP_NODISCARD_EXT inline _LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI bool isnan(float __x) _NOEXCEPT {
Nikolas Klauserdfc04a32022-12-19 00:02:44 +0100456 return __builtin_isnan(__x);
457}
Richard Smithafccfd32018-05-01 03:05:40 +0000458
Nikolas Klauserb0bb09c2022-12-25 20:13:39 +0100459_LIBCPP_NODISCARD_EXT inline _LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI _LIBCPP_PREFERRED_OVERLOAD bool isnan(double __x) _NOEXCEPT {
Nikolas Klauserdfc04a32022-12-19 00:02:44 +0100460 return __builtin_isnan(__x);
461}
Richard Smithafccfd32018-05-01 03:05:40 +0000462
Nikolas Klauserb0bb09c2022-12-25 20:13:39 +0100463_LIBCPP_NODISCARD_EXT inline _LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI bool isnan(long double __x) _NOEXCEPT {
Nikolas Klauserdfc04a32022-12-19 00:02:44 +0100464 return __builtin_isnan(__x);
465}
Nikolas Klauser9a97dd72022-11-04 16:36:34 +0100466# endif
Richard Smithafccfd32018-05-01 03:05:40 +0000467
Richard Smith081bb592015-10-08 20:40:34 +0000468// isnormal
469
Nikolas Klausere96070f2022-11-04 20:08:56 +0100470template <class _A1, std::__enable_if_t<std::is_floating_point<_A1>::value, int> = 0>
Nikolas Klauserb0bb09c2022-12-25 20:13:39 +0100471_LIBCPP_NODISCARD_EXT _LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI bool isnormal(_A1 __x) _NOEXCEPT {
Nikolas Klauser25fbc472022-11-04 16:56:51 +0100472 return __builtin_isnormal(__x);
Richard Smith081bb592015-10-08 20:40:34 +0000473}
474
Nikolas Klausere96070f2022-11-04 20:08:56 +0100475template <class _A1, std::__enable_if_t<std::is_integral<_A1>::value, int> = 0>
Nikolas Klauserb0bb09c2022-12-25 20:13:39 +0100476_LIBCPP_NODISCARD_EXT _LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI bool isnormal(_A1 __x) _NOEXCEPT {
Nikolas Klauser9a97dd72022-11-04 16:36:34 +0100477 return __x != 0;
478}
Duncan P. N. Exon Smith321d6bf2017-04-21 23:14:55 +0000479
Richard Smith081bb592015-10-08 20:40:34 +0000480// isgreater
481
Nikolas Klausere96070f2022-11-04 20:08:56 +0100482template <class _A1,
483 class _A2,
484 std::__enable_if_t<std::is_arithmetic<_A1>::value && std::is_arithmetic<_A2>::value, int> = 0>
Nikolas Klauserb0bb09c2022-12-25 20:13:39 +0100485_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI bool isgreater(_A1 __x, _A2 __y) _NOEXCEPT {
Nikolas Klauser9a97dd72022-11-04 16:36:34 +0100486 typedef typename std::__promote<_A1, _A2>::type type;
Nikolas Klauser25fbc472022-11-04 16:56:51 +0100487 return __builtin_isgreater((type)__x, (type)__y);
Richard Smith081bb592015-10-08 20:40:34 +0000488}
489
Richard Smith081bb592015-10-08 20:40:34 +0000490// isgreaterequal
491
Nikolas Klausere96070f2022-11-04 20:08:56 +0100492template <class _A1,
493 class _A2,
494 std::__enable_if_t<std::is_arithmetic<_A1>::value && std::is_arithmetic<_A2>::value, int> = 0>
Nikolas Klauserb0bb09c2022-12-25 20:13:39 +0100495_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI bool isgreaterequal(_A1 __x, _A2 __y) _NOEXCEPT {
Nikolas Klauser9a97dd72022-11-04 16:36:34 +0100496 typedef typename std::__promote<_A1, _A2>::type type;
Nikolas Klauser25fbc472022-11-04 16:56:51 +0100497 return __builtin_isgreaterequal((type)__x, (type)__y);
Richard Smith081bb592015-10-08 20:40:34 +0000498}
499
Richard Smith081bb592015-10-08 20:40:34 +0000500// isless
501
Nikolas Klausere96070f2022-11-04 20:08:56 +0100502template <class _A1,
503 class _A2,
504 std::__enable_if_t<std::is_arithmetic<_A1>::value && std::is_arithmetic<_A2>::value, int> = 0>
Nikolas Klauserb0bb09c2022-12-25 20:13:39 +0100505_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI bool isless(_A1 __x, _A2 __y) _NOEXCEPT {
Nikolas Klauser9a97dd72022-11-04 16:36:34 +0100506 typedef typename std::__promote<_A1, _A2>::type type;
Nikolas Klauser25fbc472022-11-04 16:56:51 +0100507 return __builtin_isless((type)__x, (type)__y);
Richard Smith081bb592015-10-08 20:40:34 +0000508}
509
Richard Smith081bb592015-10-08 20:40:34 +0000510// islessequal
511
Nikolas Klausere96070f2022-11-04 20:08:56 +0100512template <class _A1,
513 class _A2,
514 std::__enable_if_t<std::is_arithmetic<_A1>::value && std::is_arithmetic<_A2>::value, int> = 0>
Nikolas Klauserb0bb09c2022-12-25 20:13:39 +0100515_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI bool islessequal(_A1 __x, _A2 __y) _NOEXCEPT {
Nikolas Klauser9a97dd72022-11-04 16:36:34 +0100516 typedef typename std::__promote<_A1, _A2>::type type;
Nikolas Klauser25fbc472022-11-04 16:56:51 +0100517 return __builtin_islessequal((type)__x, (type)__y);
Richard Smith081bb592015-10-08 20:40:34 +0000518}
519
Richard Smith081bb592015-10-08 20:40:34 +0000520// islessgreater
521
Nikolas Klausere96070f2022-11-04 20:08:56 +0100522template <class _A1,
523 class _A2,
524 std::__enable_if_t<std::is_arithmetic<_A1>::value && std::is_arithmetic<_A2>::value, int> = 0>
Nikolas Klauserb0bb09c2022-12-25 20:13:39 +0100525_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI bool islessgreater(_A1 __x, _A2 __y) _NOEXCEPT {
Nikolas Klauser9a97dd72022-11-04 16:36:34 +0100526 typedef typename std::__promote<_A1, _A2>::type type;
Nikolas Klauser25fbc472022-11-04 16:56:51 +0100527 return __builtin_islessgreater((type)__x, (type)__y);
Richard Smith081bb592015-10-08 20:40:34 +0000528}
529
Richard Smith081bb592015-10-08 20:40:34 +0000530// isunordered
531
Nikolas Klausere96070f2022-11-04 20:08:56 +0100532template <class _A1,
533 class _A2,
534 std::__enable_if_t<std::is_arithmetic<_A1>::value && std::is_arithmetic<_A2>::value, int> = 0>
Nikolas Klauserb0bb09c2022-12-25 20:13:39 +0100535_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI bool isunordered(_A1 __x, _A2 __y) _NOEXCEPT {
Nikolas Klauser9a97dd72022-11-04 16:36:34 +0100536 typedef typename std::__promote<_A1, _A2>::type type;
Nikolas Klauser25fbc472022-11-04 16:56:51 +0100537 return __builtin_isunordered((type)__x, (type)__y);
Richard Smith081bb592015-10-08 20:40:34 +0000538}
539
Nikolas Klauserae1fbc42022-11-04 20:19:20 +0100540#endif // _LIBCPP_MSVCRT
Richard Smith081bb592015-10-08 20:40:34 +0000541
Richard Smith081bb592015-10-08 20:40:34 +0000542// abs
Eric Fiselier6c9e1a72020-02-15 18:55:07 -0500543//
544// handled in stdlib.h
Richard Smith081bb592015-10-08 20:40:34 +0000545
Eric Fiselier2b85c6e2019-04-23 18:01:58 +0000546// div
Eric Fiselier6c9e1a72020-02-15 18:55:07 -0500547//
548// handled in stdlib.h
Eric Fiselier2b85c6e2019-04-23 18:01:58 +0000549
Nikolas Klauser52399652022-11-01 22:29:57 +0100550// We have to provide double overloads for <math.h> to work on platforms that don't provide the full set of math
551// functions. To make the overload set work with multiple functions that take the same arguments, we make our overloads
552// templates. Functions are preferred over function templates during overload resolution, which means that our overload
553// will only be selected when the C library doesn't provide one.
554
Richard Smith081bb592015-10-08 20:40:34 +0000555// acos
556
David Tenty7249ac92022-02-07 18:22:35 -0500557# if !defined(__sun__)
Nikolas Klauser04005952022-10-21 01:41:22 +0200558inline _LIBCPP_HIDE_FROM_ABI float acos(float __x) _NOEXCEPT {return __builtin_acosf(__x);}
Nikolas Klauser52399652022-11-01 22:29:57 +0100559
560template <class = int>
561_LIBCPP_HIDE_FROM_ABI double acos(double __x) _NOEXCEPT {
562 return __builtin_acos(__x);
563}
564
Nikolas Klauser04005952022-10-21 01:41:22 +0200565inline _LIBCPP_HIDE_FROM_ABI long double acos(long double __x) _NOEXCEPT {return __builtin_acosl(__x);}
David Tenty7249ac92022-02-07 18:22:35 -0500566# endif
Richard Smith081bb592015-10-08 20:40:34 +0000567
568template <class _A1>
Nikolas Klauser4956e722022-10-12 15:41:22 +0200569inline _LIBCPP_HIDE_FROM_ABI
Richard Smith081bb592015-10-08 20:40:34 +0000570typename std::enable_if<std::is_integral<_A1>::value, double>::type
Nikolas Klauser04005952022-10-21 01:41:22 +0200571acos(_A1 __x) _NOEXCEPT {return __builtin_acos((double)__x);}
Richard Smith081bb592015-10-08 20:40:34 +0000572
573// asin
574
David Tenty7249ac92022-02-07 18:22:35 -0500575# if !defined(__sun__)
Nikolas Klauser04005952022-10-21 01:41:22 +0200576inline _LIBCPP_HIDE_FROM_ABI float asin(float __x) _NOEXCEPT {return __builtin_asinf(__x);}
Nikolas Klauser52399652022-11-01 22:29:57 +0100577
578template <class = int>
579_LIBCPP_HIDE_FROM_ABI double asin(double __x) _NOEXCEPT {
580 return __builtin_asin(__x);
581}
582
Nikolas Klauser04005952022-10-21 01:41:22 +0200583inline _LIBCPP_HIDE_FROM_ABI long double asin(long double __x) _NOEXCEPT {return __builtin_asinl(__x);}
David Tenty7249ac92022-02-07 18:22:35 -0500584# endif
Richard Smith081bb592015-10-08 20:40:34 +0000585
586template <class _A1>
Nikolas Klauser4956e722022-10-12 15:41:22 +0200587inline _LIBCPP_HIDE_FROM_ABI
Richard Smith081bb592015-10-08 20:40:34 +0000588typename std::enable_if<std::is_integral<_A1>::value, double>::type
Nikolas Klauser04005952022-10-21 01:41:22 +0200589asin(_A1 __x) _NOEXCEPT {return __builtin_asin((double)__x);}
Richard Smith081bb592015-10-08 20:40:34 +0000590
591// atan
592
David Tenty7249ac92022-02-07 18:22:35 -0500593# if !defined(__sun__)
Nikolas Klauser04005952022-10-21 01:41:22 +0200594inline _LIBCPP_HIDE_FROM_ABI float atan(float __x) _NOEXCEPT {return __builtin_atanf(__x);}
Nikolas Klauser52399652022-11-01 22:29:57 +0100595
596template <class = int>
597_LIBCPP_HIDE_FROM_ABI double atan(double __x) _NOEXCEPT {
598 return __builtin_atan(__x);
599}
600
Nikolas Klauser04005952022-10-21 01:41:22 +0200601inline _LIBCPP_HIDE_FROM_ABI long double atan(long double __x) _NOEXCEPT {return __builtin_atanl(__x);}
David Tenty7249ac92022-02-07 18:22:35 -0500602# endif
Richard Smith081bb592015-10-08 20:40:34 +0000603
604template <class _A1>
Nikolas Klauser4956e722022-10-12 15:41:22 +0200605inline _LIBCPP_HIDE_FROM_ABI
Richard Smith081bb592015-10-08 20:40:34 +0000606typename std::enable_if<std::is_integral<_A1>::value, double>::type
Nikolas Klauser04005952022-10-21 01:41:22 +0200607atan(_A1 __x) _NOEXCEPT {return __builtin_atan((double)__x);}
Richard Smith081bb592015-10-08 20:40:34 +0000608
609// atan2
610
David Tenty7249ac92022-02-07 18:22:35 -0500611# if !defined(__sun__)
Nikolas Klauser04005952022-10-21 01:41:22 +0200612inline _LIBCPP_HIDE_FROM_ABI float atan2(float __y, float __x) _NOEXCEPT {return __builtin_atan2f(__y, __x);}
Nikolas Klauser52399652022-11-01 22:29:57 +0100613
614template <class = int>
615_LIBCPP_HIDE_FROM_ABI double atan2(double __x, double __y) _NOEXCEPT {
616 return __builtin_atan2(__x, __y);
617}
618
Nikolas Klauser04005952022-10-21 01:41:22 +0200619inline _LIBCPP_HIDE_FROM_ABI long double atan2(long double __y, long double __x) _NOEXCEPT {return __builtin_atan2l(__y, __x);}
David Tenty7249ac92022-02-07 18:22:35 -0500620# endif
Richard Smith081bb592015-10-08 20:40:34 +0000621
622template <class _A1, class _A2>
Nikolas Klauser4956e722022-10-12 15:41:22 +0200623inline _LIBCPP_HIDE_FROM_ABI
Louis Dionne9ce598d2021-09-08 09:14:43 -0400624typename std::__enable_if_t
Richard Smith081bb592015-10-08 20:40:34 +0000625<
626 std::is_arithmetic<_A1>::value &&
627 std::is_arithmetic<_A2>::value,
628 std::__promote<_A1, _A2>
629>::type
Nikolas Klauser9806f452022-10-12 15:45:09 +0200630atan2(_A1 __y, _A2 __x) _NOEXCEPT
Richard Smith081bb592015-10-08 20:40:34 +0000631{
632 typedef typename std::__promote<_A1, _A2>::type __result_type;
Eric Fiselier3906a132019-06-23 20:28:29 +0000633 static_assert((!(std::_IsSame<_A1, __result_type>::value &&
634 std::_IsSame<_A2, __result_type>::value)), "");
Nikolas Klauser9806f452022-10-12 15:45:09 +0200635 return ::atan2((__result_type)__y, (__result_type)__x);
Richard Smith081bb592015-10-08 20:40:34 +0000636}
637
638// ceil
639
David Tenty7249ac92022-02-07 18:22:35 -0500640# if !defined(__sun__)
Nikolas Klauserb0bb09c2022-12-25 20:13:39 +0100641_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI float ceil(float __x) _NOEXCEPT {return __builtin_ceilf(__x);}
Nikolas Klauser52399652022-11-01 22:29:57 +0100642
643template <class = int>
Nikolas Klauserb0bb09c2022-12-25 20:13:39 +0100644_LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI double ceil(double __x) _NOEXCEPT {
Nikolas Klauser52399652022-11-01 22:29:57 +0100645 return __builtin_ceil(__x);
646}
647
Nikolas Klauserb0bb09c2022-12-25 20:13:39 +0100648_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI long double ceil(long double __x) _NOEXCEPT {return __builtin_ceill(__x);}
David Tenty7249ac92022-02-07 18:22:35 -0500649# endif
Richard Smith081bb592015-10-08 20:40:34 +0000650
651template <class _A1>
Nikolas Klauserb0bb09c2022-12-25 20:13:39 +0100652_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI
Richard Smith081bb592015-10-08 20:40:34 +0000653typename std::enable_if<std::is_integral<_A1>::value, double>::type
Nikolas Klauser04005952022-10-21 01:41:22 +0200654ceil(_A1 __x) _NOEXCEPT {return __builtin_ceil((double)__x);}
Richard Smith081bb592015-10-08 20:40:34 +0000655
656// cos
657
David Tenty7249ac92022-02-07 18:22:35 -0500658# if !defined(__sun__)
Nikolas Klauser04005952022-10-21 01:41:22 +0200659inline _LIBCPP_HIDE_FROM_ABI float cos(float __x) _NOEXCEPT {return __builtin_cosf(__x);}
Nikolas Klauser52399652022-11-01 22:29:57 +0100660
661template <class = int>
662_LIBCPP_HIDE_FROM_ABI double cos(double __x) _NOEXCEPT {
663 return __builtin_cos(__x);
664}
665
Nikolas Klauser04005952022-10-21 01:41:22 +0200666inline _LIBCPP_HIDE_FROM_ABI long double cos(long double __x) _NOEXCEPT {return __builtin_cosl(__x);}
David Tenty7249ac92022-02-07 18:22:35 -0500667# endif
Richard Smith081bb592015-10-08 20:40:34 +0000668
669template <class _A1>
Nikolas Klauser4956e722022-10-12 15:41:22 +0200670inline _LIBCPP_HIDE_FROM_ABI
Richard Smith081bb592015-10-08 20:40:34 +0000671typename std::enable_if<std::is_integral<_A1>::value, double>::type
Nikolas Klauser04005952022-10-21 01:41:22 +0200672cos(_A1 __x) _NOEXCEPT {return __builtin_cos((double)__x);}
Richard Smith081bb592015-10-08 20:40:34 +0000673
674// cosh
675
David Tenty7249ac92022-02-07 18:22:35 -0500676# if !defined(__sun__)
Nikolas Klauser04005952022-10-21 01:41:22 +0200677inline _LIBCPP_HIDE_FROM_ABI float cosh(float __x) _NOEXCEPT {return __builtin_coshf(__x);}
Nikolas Klauser52399652022-11-01 22:29:57 +0100678
679template <class = int>
680_LIBCPP_HIDE_FROM_ABI double cosh(double __x) _NOEXCEPT {
681 return __builtin_cosh(__x);
682}
683
Nikolas Klauser04005952022-10-21 01:41:22 +0200684inline _LIBCPP_HIDE_FROM_ABI long double cosh(long double __x) _NOEXCEPT {return __builtin_coshl(__x);}
David Tenty7249ac92022-02-07 18:22:35 -0500685# endif
Richard Smith081bb592015-10-08 20:40:34 +0000686
687template <class _A1>
Nikolas Klauser4956e722022-10-12 15:41:22 +0200688inline _LIBCPP_HIDE_FROM_ABI
Richard Smith081bb592015-10-08 20:40:34 +0000689typename std::enable_if<std::is_integral<_A1>::value, double>::type
Nikolas Klauser04005952022-10-21 01:41:22 +0200690cosh(_A1 __x) _NOEXCEPT {return __builtin_cosh((double)__x);}
Richard Smith081bb592015-10-08 20:40:34 +0000691
692// exp
693
David Tenty7249ac92022-02-07 18:22:35 -0500694# if !defined(__sun__)
Nikolas Klauser04005952022-10-21 01:41:22 +0200695inline _LIBCPP_HIDE_FROM_ABI float exp(float __x) _NOEXCEPT {return __builtin_expf(__x);}
Nikolas Klauser52399652022-11-01 22:29:57 +0100696
697template <class = int>
698_LIBCPP_HIDE_FROM_ABI double exp(double __x) _NOEXCEPT {
699 return __builtin_exp(__x);
700}
701
Nikolas Klauser04005952022-10-21 01:41:22 +0200702inline _LIBCPP_HIDE_FROM_ABI long double exp(long double __x) _NOEXCEPT {return __builtin_expl(__x);}
David Tenty7249ac92022-02-07 18:22:35 -0500703# endif
Richard Smith081bb592015-10-08 20:40:34 +0000704
705template <class _A1>
Nikolas Klauser4956e722022-10-12 15:41:22 +0200706inline _LIBCPP_HIDE_FROM_ABI
Richard Smith081bb592015-10-08 20:40:34 +0000707typename std::enable_if<std::is_integral<_A1>::value, double>::type
Nikolas Klauser04005952022-10-21 01:41:22 +0200708exp(_A1 __x) _NOEXCEPT {return __builtin_exp((double)__x);}
Richard Smith081bb592015-10-08 20:40:34 +0000709
710// fabs
711
David Tenty7249ac92022-02-07 18:22:35 -0500712# if !defined(__sun__)
Nikolas Klauserb0bb09c2022-12-25 20:13:39 +0100713_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI float fabs(float __x) _NOEXCEPT {return __builtin_fabsf(__x);}
Nikolas Klauser52399652022-11-01 22:29:57 +0100714
715template <class = int>
Nikolas Klauserb0bb09c2022-12-25 20:13:39 +0100716_LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI double fabs(double __x) _NOEXCEPT {
Nikolas Klauser52399652022-11-01 22:29:57 +0100717 return __builtin_fabs(__x);
718}
719
Nikolas Klauserb0bb09c2022-12-25 20:13:39 +0100720_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI long double fabs(long double __x) _NOEXCEPT {return __builtin_fabsl(__x);}
David Tenty7249ac92022-02-07 18:22:35 -0500721# endif
Richard Smith081bb592015-10-08 20:40:34 +0000722
723template <class _A1>
Nikolas Klauserb0bb09c2022-12-25 20:13:39 +0100724_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI
Richard Smith081bb592015-10-08 20:40:34 +0000725typename std::enable_if<std::is_integral<_A1>::value, double>::type
Nikolas Klauser04005952022-10-21 01:41:22 +0200726fabs(_A1 __x) _NOEXCEPT {return __builtin_fabs((double)__x);}
Richard Smith081bb592015-10-08 20:40:34 +0000727
728// floor
729
David Tenty7249ac92022-02-07 18:22:35 -0500730# if !defined(__sun__)
Nikolas Klauserb0bb09c2022-12-25 20:13:39 +0100731_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI float floor(float __x) _NOEXCEPT {return __builtin_floorf(__x);}
Nikolas Klauser52399652022-11-01 22:29:57 +0100732
733template <class = int>
Nikolas Klauserb0bb09c2022-12-25 20:13:39 +0100734_LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI double floor(double __x) _NOEXCEPT {
Nikolas Klauser52399652022-11-01 22:29:57 +0100735 return __builtin_floor(__x);
736}
737
Nikolas Klauserb0bb09c2022-12-25 20:13:39 +0100738_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI long double floor(long double __x) _NOEXCEPT {return __builtin_floorl(__x);}
David Tenty7249ac92022-02-07 18:22:35 -0500739# endif
Richard Smith081bb592015-10-08 20:40:34 +0000740
741template <class _A1>
Nikolas Klauserb0bb09c2022-12-25 20:13:39 +0100742_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI
Richard Smith081bb592015-10-08 20:40:34 +0000743typename std::enable_if<std::is_integral<_A1>::value, double>::type
Nikolas Klauser04005952022-10-21 01:41:22 +0200744floor(_A1 __x) _NOEXCEPT {return __builtin_floor((double)__x);}
Richard Smith081bb592015-10-08 20:40:34 +0000745
746// fmod
747
David Tenty7249ac92022-02-07 18:22:35 -0500748# if !defined(__sun__)
Nikolas Klauser04005952022-10-21 01:41:22 +0200749inline _LIBCPP_HIDE_FROM_ABI float fmod(float __x, float __y) _NOEXCEPT {return __builtin_fmodf(__x, __y);}
Nikolas Klauser52399652022-11-01 22:29:57 +0100750
751template <class = int>
752_LIBCPP_HIDE_FROM_ABI double fmod(double __x, double __y) _NOEXCEPT {
753 return __builtin_fmod(__x, __y);
754}
755
Nikolas Klauser04005952022-10-21 01:41:22 +0200756inline _LIBCPP_HIDE_FROM_ABI long double fmod(long double __x, long double __y) _NOEXCEPT {return __builtin_fmodl(__x, __y);}
David Tenty7249ac92022-02-07 18:22:35 -0500757# endif
Richard Smith081bb592015-10-08 20:40:34 +0000758
759template <class _A1, class _A2>
Nikolas Klauser4956e722022-10-12 15:41:22 +0200760inline _LIBCPP_HIDE_FROM_ABI
Louis Dionne9ce598d2021-09-08 09:14:43 -0400761typename std::__enable_if_t
Richard Smith081bb592015-10-08 20:40:34 +0000762<
763 std::is_arithmetic<_A1>::value &&
764 std::is_arithmetic<_A2>::value,
765 std::__promote<_A1, _A2>
766>::type
Nikolas Klauser9806f452022-10-12 15:45:09 +0200767fmod(_A1 __x, _A2 __y) _NOEXCEPT
Richard Smith081bb592015-10-08 20:40:34 +0000768{
769 typedef typename std::__promote<_A1, _A2>::type __result_type;
Eric Fiselier3906a132019-06-23 20:28:29 +0000770 static_assert((!(std::_IsSame<_A1, __result_type>::value &&
771 std::_IsSame<_A2, __result_type>::value)), "");
Nikolas Klauser9806f452022-10-12 15:45:09 +0200772 return ::fmod((__result_type)__x, (__result_type)__y);
Richard Smith081bb592015-10-08 20:40:34 +0000773}
774
775// frexp
776
David Tenty7249ac92022-02-07 18:22:35 -0500777# if !defined(__sun__)
Nikolas Klauser04005952022-10-21 01:41:22 +0200778inline _LIBCPP_HIDE_FROM_ABI float frexp(float __x, int* __e) _NOEXCEPT {return __builtin_frexpf(__x, __e);}
Nikolas Klauser52399652022-11-01 22:29:57 +0100779
780template <class = int>
781_LIBCPP_HIDE_FROM_ABI double frexp(double __x, int* __e) _NOEXCEPT {
782 return __builtin_frexp(__x, __e);
783}
784
Nikolas Klauser04005952022-10-21 01:41:22 +0200785inline _LIBCPP_HIDE_FROM_ABI long double frexp(long double __x, int* __e) _NOEXCEPT {return __builtin_frexpl(__x, __e);}
David Tenty7249ac92022-02-07 18:22:35 -0500786# endif
Richard Smith081bb592015-10-08 20:40:34 +0000787
788template <class _A1>
Nikolas Klauser4956e722022-10-12 15:41:22 +0200789inline _LIBCPP_HIDE_FROM_ABI
Richard Smith081bb592015-10-08 20:40:34 +0000790typename std::enable_if<std::is_integral<_A1>::value, double>::type
Nikolas Klauser04005952022-10-21 01:41:22 +0200791frexp(_A1 __x, int* __e) _NOEXCEPT {return __builtin_frexp((double)__x, __e);}
Richard Smith081bb592015-10-08 20:40:34 +0000792
793// ldexp
794
David Tenty7249ac92022-02-07 18:22:35 -0500795# if !defined(__sun__)
Nikolas Klauser04005952022-10-21 01:41:22 +0200796inline _LIBCPP_HIDE_FROM_ABI float ldexp(float __x, int __e) _NOEXCEPT {return __builtin_ldexpf(__x, __e);}
Nikolas Klauser52399652022-11-01 22:29:57 +0100797
798template <class = int>
799_LIBCPP_HIDE_FROM_ABI double ldexp(double __x, int __e) _NOEXCEPT {
800 return __builtin_ldexp(__x, __e);
801}
802
Nikolas Klauser04005952022-10-21 01:41:22 +0200803inline _LIBCPP_HIDE_FROM_ABI long double ldexp(long double __x, int __e) _NOEXCEPT {return __builtin_ldexpl(__x, __e);}
David Tenty7249ac92022-02-07 18:22:35 -0500804# endif
Richard Smith081bb592015-10-08 20:40:34 +0000805
806template <class _A1>
Nikolas Klauser4956e722022-10-12 15:41:22 +0200807inline _LIBCPP_HIDE_FROM_ABI
Richard Smith081bb592015-10-08 20:40:34 +0000808typename std::enable_if<std::is_integral<_A1>::value, double>::type
Nikolas Klauser04005952022-10-21 01:41:22 +0200809ldexp(_A1 __x, int __e) _NOEXCEPT {return __builtin_ldexp((double)__x, __e);}
Richard Smith081bb592015-10-08 20:40:34 +0000810
811// log
812
David Tenty7249ac92022-02-07 18:22:35 -0500813# if !defined(__sun__)
Nikolas Klauser04005952022-10-21 01:41:22 +0200814inline _LIBCPP_HIDE_FROM_ABI float log(float __x) _NOEXCEPT {return __builtin_logf(__x);}
Nikolas Klauser52399652022-11-01 22:29:57 +0100815
816template <class = int>
817_LIBCPP_HIDE_FROM_ABI double log(double __x) _NOEXCEPT {
818 return __builtin_log(__x);
819}
820
Nikolas Klauser04005952022-10-21 01:41:22 +0200821inline _LIBCPP_HIDE_FROM_ABI long double log(long double __x) _NOEXCEPT {return __builtin_logl(__x);}
David Tenty7249ac92022-02-07 18:22:35 -0500822# endif
Richard Smith081bb592015-10-08 20:40:34 +0000823
824template <class _A1>
Nikolas Klauser4956e722022-10-12 15:41:22 +0200825inline _LIBCPP_HIDE_FROM_ABI
Richard Smith081bb592015-10-08 20:40:34 +0000826typename std::enable_if<std::is_integral<_A1>::value, double>::type
Nikolas Klauser04005952022-10-21 01:41:22 +0200827log(_A1 __x) _NOEXCEPT {return __builtin_log((double)__x);}
Richard Smith081bb592015-10-08 20:40:34 +0000828
829// log10
830
David Tenty7249ac92022-02-07 18:22:35 -0500831# if !defined(__sun__)
Nikolas Klauser04005952022-10-21 01:41:22 +0200832inline _LIBCPP_HIDE_FROM_ABI float log10(float __x) _NOEXCEPT {return __builtin_log10f(__x);}
Nikolas Klauser52399652022-11-01 22:29:57 +0100833
834
835template <class = int>
836_LIBCPP_HIDE_FROM_ABI double log10(double __x) _NOEXCEPT {
837 return __builtin_log10(__x);
838}
839
Nikolas Klauser04005952022-10-21 01:41:22 +0200840inline _LIBCPP_HIDE_FROM_ABI long double log10(long double __x) _NOEXCEPT {return __builtin_log10l(__x);}
David Tenty7249ac92022-02-07 18:22:35 -0500841# endif
Richard Smith081bb592015-10-08 20:40:34 +0000842
843template <class _A1>
Nikolas Klauser4956e722022-10-12 15:41:22 +0200844inline _LIBCPP_HIDE_FROM_ABI
Richard Smith081bb592015-10-08 20:40:34 +0000845typename std::enable_if<std::is_integral<_A1>::value, double>::type
Nikolas Klauser04005952022-10-21 01:41:22 +0200846log10(_A1 __x) _NOEXCEPT {return __builtin_log10((double)__x);}
Richard Smith081bb592015-10-08 20:40:34 +0000847
848// modf
849
David Tenty7249ac92022-02-07 18:22:35 -0500850# if !defined(__sun__)
Nikolas Klauser04005952022-10-21 01:41:22 +0200851inline _LIBCPP_HIDE_FROM_ABI float modf(float __x, float* __y) _NOEXCEPT {return __builtin_modff(__x, __y);}
Nikolas Klauser52399652022-11-01 22:29:57 +0100852
853template <class = int>
854_LIBCPP_HIDE_FROM_ABI double modf(double __x, double* __y) _NOEXCEPT {
855 return __builtin_modf(__x, __y);
856}
857
Nikolas Klauser04005952022-10-21 01:41:22 +0200858inline _LIBCPP_HIDE_FROM_ABI long double modf(long double __x, long double* __y) _NOEXCEPT {return __builtin_modfl(__x, __y);}
David Tenty7249ac92022-02-07 18:22:35 -0500859# endif
Richard Smith081bb592015-10-08 20:40:34 +0000860
861// pow
862
David Tenty7249ac92022-02-07 18:22:35 -0500863# if !defined(__sun__)
Nikolas Klauser04005952022-10-21 01:41:22 +0200864inline _LIBCPP_HIDE_FROM_ABI float pow(float __x, float __y) _NOEXCEPT {return __builtin_powf(__x, __y);}
Nikolas Klauser52399652022-11-01 22:29:57 +0100865
866template <class = int>
867_LIBCPP_HIDE_FROM_ABI double pow(double __x, double __y) _NOEXCEPT {
868 return __builtin_pow(__x, __y);
869}
870
Nikolas Klauser04005952022-10-21 01:41:22 +0200871inline _LIBCPP_HIDE_FROM_ABI long double pow(long double __x, long double __y) _NOEXCEPT {return __builtin_powl(__x, __y);}
David Tenty7249ac92022-02-07 18:22:35 -0500872# endif
Richard Smith081bb592015-10-08 20:40:34 +0000873
874template <class _A1, class _A2>
Nikolas Klauser4956e722022-10-12 15:41:22 +0200875inline _LIBCPP_HIDE_FROM_ABI
Louis Dionne9ce598d2021-09-08 09:14:43 -0400876typename std::__enable_if_t
Richard Smith081bb592015-10-08 20:40:34 +0000877<
878 std::is_arithmetic<_A1>::value &&
879 std::is_arithmetic<_A2>::value,
880 std::__promote<_A1, _A2>
881>::type
Nikolas Klauser9806f452022-10-12 15:45:09 +0200882pow(_A1 __x, _A2 __y) _NOEXCEPT
Richard Smith081bb592015-10-08 20:40:34 +0000883{
884 typedef typename std::__promote<_A1, _A2>::type __result_type;
Eric Fiselier3906a132019-06-23 20:28:29 +0000885 static_assert((!(std::_IsSame<_A1, __result_type>::value &&
886 std::_IsSame<_A2, __result_type>::value)), "");
Nikolas Klauser9806f452022-10-12 15:45:09 +0200887 return ::pow((__result_type)__x, (__result_type)__y);
Richard Smith081bb592015-10-08 20:40:34 +0000888}
889
890// sin
891
David Tenty7249ac92022-02-07 18:22:35 -0500892# if !defined(__sun__)
Nikolas Klauser04005952022-10-21 01:41:22 +0200893inline _LIBCPP_HIDE_FROM_ABI float sin(float __x) _NOEXCEPT {return __builtin_sinf(__x);}
Nikolas Klauser52399652022-11-01 22:29:57 +0100894
895template <class = int>
896_LIBCPP_HIDE_FROM_ABI double sin(double __x) _NOEXCEPT {
897 return __builtin_sin(__x);
898}
899
Nikolas Klauser04005952022-10-21 01:41:22 +0200900inline _LIBCPP_HIDE_FROM_ABI long double sin(long double __x) _NOEXCEPT {return __builtin_sinl(__x);}
Richard Smith081bb592015-10-08 20:40:34 +0000901#endif
902
903template <class _A1>
Nikolas Klauser4956e722022-10-12 15:41:22 +0200904inline _LIBCPP_HIDE_FROM_ABI
Richard Smith081bb592015-10-08 20:40:34 +0000905typename std::enable_if<std::is_integral<_A1>::value, double>::type
Nikolas Klauser04005952022-10-21 01:41:22 +0200906sin(_A1 __x) _NOEXCEPT {return __builtin_sin((double)__x);}
Richard Smith081bb592015-10-08 20:40:34 +0000907
908// sinh
909
David Tenty7249ac92022-02-07 18:22:35 -0500910# if !defined(__sun__)
Nikolas Klauser04005952022-10-21 01:41:22 +0200911inline _LIBCPP_HIDE_FROM_ABI float sinh(float __x) _NOEXCEPT {return __builtin_sinhf(__x);}
Nikolas Klauser52399652022-11-01 22:29:57 +0100912
913template <class = int>
914_LIBCPP_HIDE_FROM_ABI double sinh(double __x) _NOEXCEPT {
915 return __builtin_sinh(__x);
916}
917
Nikolas Klauser04005952022-10-21 01:41:22 +0200918inline _LIBCPP_HIDE_FROM_ABI long double sinh(long double __x) _NOEXCEPT {return __builtin_sinhl(__x);}
David Tenty7249ac92022-02-07 18:22:35 -0500919# endif
Richard Smith081bb592015-10-08 20:40:34 +0000920
921template <class _A1>
Nikolas Klauser4956e722022-10-12 15:41:22 +0200922inline _LIBCPP_HIDE_FROM_ABI
Richard Smith081bb592015-10-08 20:40:34 +0000923typename std::enable_if<std::is_integral<_A1>::value, double>::type
Nikolas Klauser04005952022-10-21 01:41:22 +0200924sinh(_A1 __x) _NOEXCEPT {return __builtin_sinh((double)__x);}
Richard Smith081bb592015-10-08 20:40:34 +0000925
926// sqrt
927
David Tenty7249ac92022-02-07 18:22:35 -0500928# if !defined(__sun__)
Nikolas Klauser04005952022-10-21 01:41:22 +0200929inline _LIBCPP_HIDE_FROM_ABI float sqrt(float __x) _NOEXCEPT {return __builtin_sqrtf(__x);}
Nikolas Klauser52399652022-11-01 22:29:57 +0100930
931template <class = int>
932_LIBCPP_HIDE_FROM_ABI double sqrt(double __x) _NOEXCEPT {
933 return __builtin_sqrt(__x);
934}
935
Nikolas Klauser04005952022-10-21 01:41:22 +0200936inline _LIBCPP_HIDE_FROM_ABI long double sqrt(long double __x) _NOEXCEPT {return __builtin_sqrtl(__x);}
David Tenty7249ac92022-02-07 18:22:35 -0500937# endif
Richard Smith081bb592015-10-08 20:40:34 +0000938
Richard Smith081bb592015-10-08 20:40:34 +0000939template <class _A1>
Nikolas Klauser4956e722022-10-12 15:41:22 +0200940inline _LIBCPP_HIDE_FROM_ABI
Richard Smith081bb592015-10-08 20:40:34 +0000941typename std::enable_if<std::is_integral<_A1>::value, double>::type
Nikolas Klauser04005952022-10-21 01:41:22 +0200942sqrt(_A1 __x) _NOEXCEPT {return __builtin_sqrt((double)__x);}
Richard Smith081bb592015-10-08 20:40:34 +0000943
944// tan
945
David Tenty7249ac92022-02-07 18:22:35 -0500946# if !defined(__sun__)
Nikolas Klauser04005952022-10-21 01:41:22 +0200947inline _LIBCPP_HIDE_FROM_ABI float tan(float __x) _NOEXCEPT {return __builtin_tanf(__x);}
Nikolas Klauser52399652022-11-01 22:29:57 +0100948
949template <class = int>
950_LIBCPP_HIDE_FROM_ABI double tan(double __x) _NOEXCEPT {
951 return __builtin_tan(__x);
952}
953
Nikolas Klauser04005952022-10-21 01:41:22 +0200954inline _LIBCPP_HIDE_FROM_ABI long double tan(long double __x) _NOEXCEPT {return __builtin_tanl(__x);}
David Tenty7249ac92022-02-07 18:22:35 -0500955# endif
Richard Smith081bb592015-10-08 20:40:34 +0000956
957template <class _A1>
Nikolas Klauser4956e722022-10-12 15:41:22 +0200958inline _LIBCPP_HIDE_FROM_ABI
Richard Smith081bb592015-10-08 20:40:34 +0000959typename std::enable_if<std::is_integral<_A1>::value, double>::type
Nikolas Klauser04005952022-10-21 01:41:22 +0200960tan(_A1 __x) _NOEXCEPT {return __builtin_tan((double)__x);}
Richard Smith081bb592015-10-08 20:40:34 +0000961
962// tanh
963
David Tenty7249ac92022-02-07 18:22:35 -0500964# if !defined(__sun__)
Nikolas Klauser04005952022-10-21 01:41:22 +0200965inline _LIBCPP_HIDE_FROM_ABI float tanh(float __x) _NOEXCEPT {return __builtin_tanhf(__x);}
Nikolas Klauser52399652022-11-01 22:29:57 +0100966
967template <class = int>
968_LIBCPP_HIDE_FROM_ABI double tanh(double __x) _NOEXCEPT {
969 return __builtin_tanh(__x);
970}
971
Nikolas Klauser04005952022-10-21 01:41:22 +0200972inline _LIBCPP_HIDE_FROM_ABI long double tanh(long double __x) _NOEXCEPT {return __builtin_tanhl(__x);}
David Tenty7249ac92022-02-07 18:22:35 -0500973# endif
Richard Smith081bb592015-10-08 20:40:34 +0000974
975template <class _A1>
Nikolas Klauser4956e722022-10-12 15:41:22 +0200976inline _LIBCPP_HIDE_FROM_ABI
Richard Smith081bb592015-10-08 20:40:34 +0000977typename std::enable_if<std::is_integral<_A1>::value, double>::type
Nikolas Klauser04005952022-10-21 01:41:22 +0200978tanh(_A1 __x) _NOEXCEPT {return __builtin_tanh((double)__x);}
Richard Smith081bb592015-10-08 20:40:34 +0000979
980// acosh
981
Nikolas Klauser04005952022-10-21 01:41:22 +0200982inline _LIBCPP_HIDE_FROM_ABI float acosh(float __x) _NOEXCEPT {return __builtin_acoshf(__x);}
Nikolas Klauser52399652022-11-01 22:29:57 +0100983
984template <class = int>
985_LIBCPP_HIDE_FROM_ABI double acosh(double __x) _NOEXCEPT {
986 return __builtin_acosh(__x);
987}
988
Nikolas Klauser04005952022-10-21 01:41:22 +0200989inline _LIBCPP_HIDE_FROM_ABI long double acosh(long double __x) _NOEXCEPT {return __builtin_acoshl(__x);}
Richard Smith081bb592015-10-08 20:40:34 +0000990
991template <class _A1>
Nikolas Klauser4956e722022-10-12 15:41:22 +0200992inline _LIBCPP_HIDE_FROM_ABI
Richard Smith081bb592015-10-08 20:40:34 +0000993typename std::enable_if<std::is_integral<_A1>::value, double>::type
Nikolas Klauser04005952022-10-21 01:41:22 +0200994acosh(_A1 __x) _NOEXCEPT {return __builtin_acosh((double)__x);}
Richard Smith081bb592015-10-08 20:40:34 +0000995
996// asinh
997
Nikolas Klauser04005952022-10-21 01:41:22 +0200998inline _LIBCPP_HIDE_FROM_ABI float asinh(float __x) _NOEXCEPT {return __builtin_asinhf(__x);}
Nikolas Klauser52399652022-11-01 22:29:57 +0100999
1000template <class = int>
1001_LIBCPP_HIDE_FROM_ABI double asinh(double __x) _NOEXCEPT {
1002 return __builtin_asinh(__x);
1003}
1004
Nikolas Klauser04005952022-10-21 01:41:22 +02001005inline _LIBCPP_HIDE_FROM_ABI long double asinh(long double __x) _NOEXCEPT {return __builtin_asinhl(__x);}
Richard Smith081bb592015-10-08 20:40:34 +00001006
1007template <class _A1>
Nikolas Klauser4956e722022-10-12 15:41:22 +02001008inline _LIBCPP_HIDE_FROM_ABI
Richard Smith081bb592015-10-08 20:40:34 +00001009typename std::enable_if<std::is_integral<_A1>::value, double>::type
Nikolas Klauser04005952022-10-21 01:41:22 +02001010asinh(_A1 __x) _NOEXCEPT {return __builtin_asinh((double)__x);}
Richard Smith081bb592015-10-08 20:40:34 +00001011
1012// atanh
1013
Nikolas Klauser04005952022-10-21 01:41:22 +02001014inline _LIBCPP_HIDE_FROM_ABI float atanh(float __x) _NOEXCEPT {return __builtin_atanhf(__x);}
Nikolas Klauser52399652022-11-01 22:29:57 +01001015
1016template <class = int>
1017_LIBCPP_HIDE_FROM_ABI double atanh(double __x) _NOEXCEPT {
1018 return __builtin_atanh(__x);
1019}
1020
Nikolas Klauser04005952022-10-21 01:41:22 +02001021inline _LIBCPP_HIDE_FROM_ABI long double atanh(long double __x) _NOEXCEPT {return __builtin_atanhl(__x);}
Richard Smith081bb592015-10-08 20:40:34 +00001022
1023template <class _A1>
Nikolas Klauser4956e722022-10-12 15:41:22 +02001024inline _LIBCPP_HIDE_FROM_ABI
Richard Smith081bb592015-10-08 20:40:34 +00001025typename std::enable_if<std::is_integral<_A1>::value, double>::type
Nikolas Klauser04005952022-10-21 01:41:22 +02001026atanh(_A1 __x) _NOEXCEPT {return __builtin_atanh((double)__x);}
Richard Smith081bb592015-10-08 20:40:34 +00001027
1028// cbrt
1029
Nikolas Klauserb0bb09c2022-12-25 20:13:39 +01001030_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI float cbrt(float __x) _NOEXCEPT {return __builtin_cbrtf(__x);}
Nikolas Klauser52399652022-11-01 22:29:57 +01001031
1032template <class = int>
Nikolas Klauserb0bb09c2022-12-25 20:13:39 +01001033_LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI double cbrt(double __x) _NOEXCEPT {
Nikolas Klauser52399652022-11-01 22:29:57 +01001034 return __builtin_cbrt(__x);
1035}
1036
Nikolas Klauserb0bb09c2022-12-25 20:13:39 +01001037_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI long double cbrt(long double __x) _NOEXCEPT {return __builtin_cbrtl(__x);}
Richard Smith081bb592015-10-08 20:40:34 +00001038
1039template <class _A1>
Nikolas Klauserb0bb09c2022-12-25 20:13:39 +01001040_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI
Richard Smith081bb592015-10-08 20:40:34 +00001041typename std::enable_if<std::is_integral<_A1>::value, double>::type
Nikolas Klauser04005952022-10-21 01:41:22 +02001042cbrt(_A1 __x) _NOEXCEPT {return __builtin_cbrt((double)__x);}
Richard Smith081bb592015-10-08 20:40:34 +00001043
1044// copysign
1045
Nikolas Klauserb0bb09c2022-12-25 20:13:39 +01001046_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI float copysign(float __x, float __y) _NOEXCEPT {
Marek Kurdej4d6c6e52022-12-15 02:19:59 +01001047 return ::__builtin_copysignf(__x, __y);
Marek Kurdeja933f0d2021-07-21 15:58:17 +02001048}
1049
Nikolas Klauserb0bb09c2022-12-25 20:13:39 +01001050_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI long double copysign(long double __x, long double __y) _NOEXCEPT {
Marek Kurdej4d6c6e52022-12-15 02:19:59 +01001051 return ::__builtin_copysignl(__x, __y);
Marek Kurdeja933f0d2021-07-21 15:58:17 +02001052}
1053
1054template <class _A1, class _A2>
Nikolas Klauserb0bb09c2022-12-25 20:13:39 +01001055_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI
Louis Dionne9ce598d2021-09-08 09:14:43 -04001056typename std::__enable_if_t
Richard Smith081bb592015-10-08 20:40:34 +00001057<
1058 std::is_arithmetic<_A1>::value &&
1059 std::is_arithmetic<_A2>::value,
1060 std::__promote<_A1, _A2>
1061>::type
Nikolas Klauser9806f452022-10-12 15:45:09 +02001062 copysign(_A1 __x, _A2 __y) _NOEXCEPT {
Marek Kurdej4d6c6e52022-12-15 02:19:59 +01001063 return ::__builtin_copysign(__x, __y);
Richard Smith081bb592015-10-08 20:40:34 +00001064}
1065
Richard Smith081bb592015-10-08 20:40:34 +00001066// erf
1067
Nikolas Klauser04005952022-10-21 01:41:22 +02001068inline _LIBCPP_HIDE_FROM_ABI float erf(float __x) _NOEXCEPT {return __builtin_erff(__x);}
Nikolas Klauser52399652022-11-01 22:29:57 +01001069
1070template <class = int>
1071_LIBCPP_HIDE_FROM_ABI double erf(double __x) _NOEXCEPT {
1072 return __builtin_erf(__x);
1073}
1074
Nikolas Klauser04005952022-10-21 01:41:22 +02001075inline _LIBCPP_HIDE_FROM_ABI long double erf(long double __x) _NOEXCEPT {return __builtin_erfl(__x);}
Richard Smith081bb592015-10-08 20:40:34 +00001076
1077template <class _A1>
Nikolas Klauser4956e722022-10-12 15:41:22 +02001078inline _LIBCPP_HIDE_FROM_ABI
Richard Smith081bb592015-10-08 20:40:34 +00001079typename std::enable_if<std::is_integral<_A1>::value, double>::type
Nikolas Klauser04005952022-10-21 01:41:22 +02001080erf(_A1 __x) _NOEXCEPT {return __builtin_erf((double)__x);}
Richard Smith081bb592015-10-08 20:40:34 +00001081
1082// erfc
1083
Nikolas Klauser04005952022-10-21 01:41:22 +02001084inline _LIBCPP_HIDE_FROM_ABI float erfc(float __x) _NOEXCEPT {return __builtin_erfcf(__x);}
Nikolas Klauser52399652022-11-01 22:29:57 +01001085
1086template <class = int>
1087_LIBCPP_HIDE_FROM_ABI double erfc(double __x) _NOEXCEPT {
1088 return __builtin_erfc(__x);
1089}
1090
Nikolas Klauser04005952022-10-21 01:41:22 +02001091inline _LIBCPP_HIDE_FROM_ABI long double erfc(long double __x) _NOEXCEPT {return __builtin_erfcl(__x);}
Richard Smith081bb592015-10-08 20:40:34 +00001092
1093template <class _A1>
Nikolas Klauser4956e722022-10-12 15:41:22 +02001094inline _LIBCPP_HIDE_FROM_ABI
Richard Smith081bb592015-10-08 20:40:34 +00001095typename std::enable_if<std::is_integral<_A1>::value, double>::type
Nikolas Klauser04005952022-10-21 01:41:22 +02001096erfc(_A1 __x) _NOEXCEPT {return __builtin_erfc((double)__x);}
Richard Smith081bb592015-10-08 20:40:34 +00001097
1098// exp2
1099
Nikolas Klauser04005952022-10-21 01:41:22 +02001100inline _LIBCPP_HIDE_FROM_ABI float exp2(float __x) _NOEXCEPT {return __builtin_exp2f(__x);}
Nikolas Klauser52399652022-11-01 22:29:57 +01001101
1102template <class = int>
1103_LIBCPP_HIDE_FROM_ABI double exp2(double __x) _NOEXCEPT {
1104 return __builtin_exp2(__x);
1105}
1106
Nikolas Klauser04005952022-10-21 01:41:22 +02001107inline _LIBCPP_HIDE_FROM_ABI long double exp2(long double __x) _NOEXCEPT {return __builtin_exp2l(__x);}
Richard Smith081bb592015-10-08 20:40:34 +00001108
1109template <class _A1>
Nikolas Klauser4956e722022-10-12 15:41:22 +02001110inline _LIBCPP_HIDE_FROM_ABI
Richard Smith081bb592015-10-08 20:40:34 +00001111typename std::enable_if<std::is_integral<_A1>::value, double>::type
Nikolas Klauser04005952022-10-21 01:41:22 +02001112exp2(_A1 __x) _NOEXCEPT {return __builtin_exp2((double)__x);}
Richard Smith081bb592015-10-08 20:40:34 +00001113
1114// expm1
1115
Nikolas Klauser04005952022-10-21 01:41:22 +02001116inline _LIBCPP_HIDE_FROM_ABI float expm1(float __x) _NOEXCEPT {return __builtin_expm1f(__x);}
Nikolas Klauser52399652022-11-01 22:29:57 +01001117
1118template <class = int>
1119_LIBCPP_HIDE_FROM_ABI double expm1(double __x) _NOEXCEPT {
1120 return __builtin_expm1(__x);
1121}
1122
Nikolas Klauser04005952022-10-21 01:41:22 +02001123inline _LIBCPP_HIDE_FROM_ABI long double expm1(long double __x) _NOEXCEPT {return __builtin_expm1l(__x);}
Richard Smith081bb592015-10-08 20:40:34 +00001124
1125template <class _A1>
Nikolas Klauser4956e722022-10-12 15:41:22 +02001126inline _LIBCPP_HIDE_FROM_ABI
Richard Smith081bb592015-10-08 20:40:34 +00001127typename std::enable_if<std::is_integral<_A1>::value, double>::type
Nikolas Klauser04005952022-10-21 01:41:22 +02001128expm1(_A1 __x) _NOEXCEPT {return __builtin_expm1((double)__x);}
Richard Smith081bb592015-10-08 20:40:34 +00001129
1130// fdim
1131
Nikolas Klauser04005952022-10-21 01:41:22 +02001132inline _LIBCPP_HIDE_FROM_ABI float fdim(float __x, float __y) _NOEXCEPT {return __builtin_fdimf(__x, __y);}
Nikolas Klauser52399652022-11-01 22:29:57 +01001133
1134template <class = int>
1135_LIBCPP_HIDE_FROM_ABI double fdim(double __x, double __y) _NOEXCEPT {
1136 return __builtin_fdim(__x, __y);
1137}
1138
Nikolas Klauser04005952022-10-21 01:41:22 +02001139inline _LIBCPP_HIDE_FROM_ABI long double fdim(long double __x, long double __y) _NOEXCEPT {return __builtin_fdiml(__x, __y);}
Richard Smith081bb592015-10-08 20:40:34 +00001140
1141template <class _A1, class _A2>
Nikolas Klauser4956e722022-10-12 15:41:22 +02001142inline _LIBCPP_HIDE_FROM_ABI
Louis Dionne9ce598d2021-09-08 09:14:43 -04001143typename std::__enable_if_t
Richard Smith081bb592015-10-08 20:40:34 +00001144<
1145 std::is_arithmetic<_A1>::value &&
1146 std::is_arithmetic<_A2>::value,
1147 std::__promote<_A1, _A2>
1148>::type
Nikolas Klauser9806f452022-10-12 15:45:09 +02001149fdim(_A1 __x, _A2 __y) _NOEXCEPT
Richard Smith081bb592015-10-08 20:40:34 +00001150{
1151 typedef typename std::__promote<_A1, _A2>::type __result_type;
Eric Fiselier3906a132019-06-23 20:28:29 +00001152 static_assert((!(std::_IsSame<_A1, __result_type>::value &&
1153 std::_IsSame<_A2, __result_type>::value)), "");
Nikolas Klauser9806f452022-10-12 15:45:09 +02001154 return ::fdim((__result_type)__x, (__result_type)__y);
Richard Smith081bb592015-10-08 20:40:34 +00001155}
1156
1157// fma
1158
Nikolas Klauser9806f452022-10-12 15:45:09 +02001159inline _LIBCPP_HIDE_FROM_ABI float fma(float __x, float __y, float __z) _NOEXCEPT
Ilya Tokarc3abffb2021-02-10 13:05:19 -05001160{
Nikolas Klauser9806f452022-10-12 15:45:09 +02001161 return __builtin_fmaf(__x, __y, __z);
Ilya Tokarc3abffb2021-02-10 13:05:19 -05001162}
Nikolas Klauser52399652022-11-01 22:29:57 +01001163
1164
1165template <class = int>
1166_LIBCPP_HIDE_FROM_ABI double fma(double __x, double __y, double __z) _NOEXCEPT {
1167 return __builtin_fma(__x, __y, __z);
1168}
1169
Nikolas Klauser9806f452022-10-12 15:45:09 +02001170inline _LIBCPP_HIDE_FROM_ABI long double fma(long double __x, long double __y, long double __z) _NOEXCEPT
Ilya Tokarc3abffb2021-02-10 13:05:19 -05001171{
Nikolas Klauser9806f452022-10-12 15:45:09 +02001172 return __builtin_fmal(__x, __y, __z);
Ilya Tokarc3abffb2021-02-10 13:05:19 -05001173}
Richard Smith081bb592015-10-08 20:40:34 +00001174
1175template <class _A1, class _A2, class _A3>
Nikolas Klauser4956e722022-10-12 15:41:22 +02001176inline _LIBCPP_HIDE_FROM_ABI
Louis Dionne9ce598d2021-09-08 09:14:43 -04001177typename std::__enable_if_t
Richard Smith081bb592015-10-08 20:40:34 +00001178<
1179 std::is_arithmetic<_A1>::value &&
1180 std::is_arithmetic<_A2>::value &&
1181 std::is_arithmetic<_A3>::value,
1182 std::__promote<_A1, _A2, _A3>
1183>::type
Nikolas Klauser9806f452022-10-12 15:45:09 +02001184fma(_A1 __x, _A2 __y, _A3 __z) _NOEXCEPT
Richard Smith081bb592015-10-08 20:40:34 +00001185{
1186 typedef typename std::__promote<_A1, _A2, _A3>::type __result_type;
Eric Fiselier3906a132019-06-23 20:28:29 +00001187 static_assert((!(std::_IsSame<_A1, __result_type>::value &&
1188 std::_IsSame<_A2, __result_type>::value &&
1189 std::_IsSame<_A3, __result_type>::value)), "");
Nikolas Klauser9806f452022-10-12 15:45:09 +02001190 return __builtin_fma((__result_type)__x, (__result_type)__y, (__result_type)__z);
Richard Smith081bb592015-10-08 20:40:34 +00001191}
1192
1193// fmax
1194
Nikolas Klauserb0bb09c2022-12-25 20:13:39 +01001195_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI float fmax(float __x, float __y) _NOEXCEPT {return __builtin_fmaxf(__x, __y);}
Nikolas Klauser52399652022-11-01 22:29:57 +01001196
1197template <class = int>
Nikolas Klauserb0bb09c2022-12-25 20:13:39 +01001198_LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI double fmax(double __x, double __y) _NOEXCEPT {
Nikolas Klauser52399652022-11-01 22:29:57 +01001199 return __builtin_fmax(__x, __y);
1200}
1201
Nikolas Klauserb0bb09c2022-12-25 20:13:39 +01001202_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI long double fmax(long double __x, long double __y) _NOEXCEPT {return __builtin_fmaxl(__x, __y);}
Richard Smith081bb592015-10-08 20:40:34 +00001203
1204template <class _A1, class _A2>
Nikolas Klauserb0bb09c2022-12-25 20:13:39 +01001205_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI
Louis Dionne9ce598d2021-09-08 09:14:43 -04001206typename std::__enable_if_t
Richard Smith081bb592015-10-08 20:40:34 +00001207<
1208 std::is_arithmetic<_A1>::value &&
1209 std::is_arithmetic<_A2>::value,
1210 std::__promote<_A1, _A2>
1211>::type
Nikolas Klauser9806f452022-10-12 15:45:09 +02001212fmax(_A1 __x, _A2 __y) _NOEXCEPT
Richard Smith081bb592015-10-08 20:40:34 +00001213{
1214 typedef typename std::__promote<_A1, _A2>::type __result_type;
Eric Fiselier3906a132019-06-23 20:28:29 +00001215 static_assert((!(std::_IsSame<_A1, __result_type>::value &&
1216 std::_IsSame<_A2, __result_type>::value)), "");
Nikolas Klauser9806f452022-10-12 15:45:09 +02001217 return ::fmax((__result_type)__x, (__result_type)__y);
Richard Smith081bb592015-10-08 20:40:34 +00001218}
1219
1220// fmin
1221
Nikolas Klauserb0bb09c2022-12-25 20:13:39 +01001222_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI float fmin(float __x, float __y) _NOEXCEPT {return __builtin_fminf(__x, __y);}
Nikolas Klauser52399652022-11-01 22:29:57 +01001223
1224template <class = int>
Nikolas Klauserb0bb09c2022-12-25 20:13:39 +01001225_LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI double fmin(double __x, double __y) _NOEXCEPT {
Nikolas Klauser52399652022-11-01 22:29:57 +01001226 return __builtin_fmin(__x, __y);
1227}
1228
Nikolas Klauserb0bb09c2022-12-25 20:13:39 +01001229_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI long double fmin(long double __x, long double __y) _NOEXCEPT {return __builtin_fminl(__x, __y);}
Richard Smith081bb592015-10-08 20:40:34 +00001230
1231template <class _A1, class _A2>
Nikolas Klauserb0bb09c2022-12-25 20:13:39 +01001232_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI
Louis Dionne9ce598d2021-09-08 09:14:43 -04001233typename std::__enable_if_t
Richard Smith081bb592015-10-08 20:40:34 +00001234<
1235 std::is_arithmetic<_A1>::value &&
1236 std::is_arithmetic<_A2>::value,
1237 std::__promote<_A1, _A2>
1238>::type
Nikolas Klauser9806f452022-10-12 15:45:09 +02001239fmin(_A1 __x, _A2 __y) _NOEXCEPT
Richard Smith081bb592015-10-08 20:40:34 +00001240{
1241 typedef typename std::__promote<_A1, _A2>::type __result_type;
Eric Fiselier3906a132019-06-23 20:28:29 +00001242 static_assert((!(std::_IsSame<_A1, __result_type>::value &&
1243 std::_IsSame<_A2, __result_type>::value)), "");
Nikolas Klauser9806f452022-10-12 15:45:09 +02001244 return ::fmin((__result_type)__x, (__result_type)__y);
Richard Smith081bb592015-10-08 20:40:34 +00001245}
1246
1247// hypot
1248
Nikolas Klauser04005952022-10-21 01:41:22 +02001249inline _LIBCPP_HIDE_FROM_ABI float hypot(float __x, float __y) _NOEXCEPT {return __builtin_hypotf(__x, __y);}
Nikolas Klauser52399652022-11-01 22:29:57 +01001250
1251template <class = int>
1252_LIBCPP_HIDE_FROM_ABI double hypot(double __x, double __y) _NOEXCEPT {
1253 return __builtin_hypot(__x, __y);
1254}
1255
Nikolas Klauser04005952022-10-21 01:41:22 +02001256inline _LIBCPP_HIDE_FROM_ABI long double hypot(long double __x, long double __y) _NOEXCEPT {return __builtin_hypotl(__x, __y);}
Richard Smith081bb592015-10-08 20:40:34 +00001257
1258template <class _A1, class _A2>
Nikolas Klauser4956e722022-10-12 15:41:22 +02001259inline _LIBCPP_HIDE_FROM_ABI
Louis Dionne9ce598d2021-09-08 09:14:43 -04001260typename std::__enable_if_t
Richard Smith081bb592015-10-08 20:40:34 +00001261<
1262 std::is_arithmetic<_A1>::value &&
1263 std::is_arithmetic<_A2>::value,
1264 std::__promote<_A1, _A2>
1265>::type
Nikolas Klauser9806f452022-10-12 15:45:09 +02001266hypot(_A1 __x, _A2 __y) _NOEXCEPT
Richard Smith081bb592015-10-08 20:40:34 +00001267{
1268 typedef typename std::__promote<_A1, _A2>::type __result_type;
Eric Fiselier3906a132019-06-23 20:28:29 +00001269 static_assert((!(std::_IsSame<_A1, __result_type>::value &&
1270 std::_IsSame<_A2, __result_type>::value)), "");
Nikolas Klauser9806f452022-10-12 15:45:09 +02001271 return ::hypot((__result_type)__x, (__result_type)__y);
Richard Smith081bb592015-10-08 20:40:34 +00001272}
1273
1274// ilogb
1275
Nikolas Klauser04005952022-10-21 01:41:22 +02001276inline _LIBCPP_HIDE_FROM_ABI int ilogb(float __x) _NOEXCEPT {return __builtin_ilogbf(__x);}
Nikolas Klauser52399652022-11-01 22:29:57 +01001277
1278template <class = int>
1279_LIBCPP_HIDE_FROM_ABI double ilogb(double __x) _NOEXCEPT {
1280 return __builtin_ilogb(__x);
1281}
1282
Nikolas Klauser04005952022-10-21 01:41:22 +02001283inline _LIBCPP_HIDE_FROM_ABI int ilogb(long double __x) _NOEXCEPT {return __builtin_ilogbl(__x);}
Richard Smith081bb592015-10-08 20:40:34 +00001284
1285template <class _A1>
Nikolas Klauser4956e722022-10-12 15:41:22 +02001286inline _LIBCPP_HIDE_FROM_ABI
Richard Smith081bb592015-10-08 20:40:34 +00001287typename std::enable_if<std::is_integral<_A1>::value, int>::type
Nikolas Klauser04005952022-10-21 01:41:22 +02001288ilogb(_A1 __x) _NOEXCEPT {return __builtin_ilogb((double)__x);}
Richard Smith081bb592015-10-08 20:40:34 +00001289
1290// lgamma
1291
Nikolas Klauser04005952022-10-21 01:41:22 +02001292inline _LIBCPP_HIDE_FROM_ABI float lgamma(float __x) _NOEXCEPT {return __builtin_lgammaf(__x);}
Nikolas Klauser52399652022-11-01 22:29:57 +01001293
1294template <class = int>
1295_LIBCPP_HIDE_FROM_ABI double lgamma(double __x) _NOEXCEPT {
1296 return __builtin_lgamma(__x);
1297}
1298
Nikolas Klauser04005952022-10-21 01:41:22 +02001299inline _LIBCPP_HIDE_FROM_ABI long double lgamma(long double __x) _NOEXCEPT {return __builtin_lgammal(__x);}
Richard Smith081bb592015-10-08 20:40:34 +00001300
1301template <class _A1>
Nikolas Klauser4956e722022-10-12 15:41:22 +02001302inline _LIBCPP_HIDE_FROM_ABI
Richard Smith081bb592015-10-08 20:40:34 +00001303typename std::enable_if<std::is_integral<_A1>::value, double>::type
Nikolas Klauser04005952022-10-21 01:41:22 +02001304lgamma(_A1 __x) _NOEXCEPT {return __builtin_lgamma((double)__x);}
Richard Smith081bb592015-10-08 20:40:34 +00001305
1306// llrint
1307
Nikolas Klauser9806f452022-10-12 15:45:09 +02001308inline _LIBCPP_HIDE_FROM_ABI long long llrint(float __x) _NOEXCEPT
Ilya Tokarc3abffb2021-02-10 13:05:19 -05001309{
Nikolas Klauser9806f452022-10-12 15:45:09 +02001310 return __builtin_llrintf(__x);
Ilya Tokarc3abffb2021-02-10 13:05:19 -05001311}
Nikolas Klauser52399652022-11-01 22:29:57 +01001312
1313template <class = int>
1314_LIBCPP_HIDE_FROM_ABI long long llrint(double __x) _NOEXCEPT {
1315 return __builtin_llrint(__x);
1316}
1317
Nikolas Klauser9806f452022-10-12 15:45:09 +02001318inline _LIBCPP_HIDE_FROM_ABI long long llrint(long double __x) _NOEXCEPT
Ilya Tokarc3abffb2021-02-10 13:05:19 -05001319{
Nikolas Klauser9806f452022-10-12 15:45:09 +02001320 return __builtin_llrintl(__x);
Ilya Tokarc3abffb2021-02-10 13:05:19 -05001321}
Richard Smith081bb592015-10-08 20:40:34 +00001322
1323template <class _A1>
Nikolas Klauser4956e722022-10-12 15:41:22 +02001324inline _LIBCPP_HIDE_FROM_ABI
Richard Smith081bb592015-10-08 20:40:34 +00001325typename std::enable_if<std::is_integral<_A1>::value, long long>::type
Nikolas Klauser9806f452022-10-12 15:45:09 +02001326llrint(_A1 __x) _NOEXCEPT
Ilya Tokarc3abffb2021-02-10 13:05:19 -05001327{
Nikolas Klauser9806f452022-10-12 15:45:09 +02001328 return __builtin_llrint((double)__x);
Ilya Tokarc3abffb2021-02-10 13:05:19 -05001329}
Richard Smith081bb592015-10-08 20:40:34 +00001330
1331// llround
1332
Nikolas Klauser9806f452022-10-12 15:45:09 +02001333inline _LIBCPP_HIDE_FROM_ABI long long llround(float __x) _NOEXCEPT
Ilya Tokarc3abffb2021-02-10 13:05:19 -05001334{
Nikolas Klauser9806f452022-10-12 15:45:09 +02001335 return __builtin_llroundf(__x);
Ilya Tokarc3abffb2021-02-10 13:05:19 -05001336}
Nikolas Klauser52399652022-11-01 22:29:57 +01001337
1338template <class = int>
1339_LIBCPP_HIDE_FROM_ABI long long llround(double __x) _NOEXCEPT {
1340 return __builtin_llround(__x);
1341}
1342
Nikolas Klauser9806f452022-10-12 15:45:09 +02001343inline _LIBCPP_HIDE_FROM_ABI long long llround(long double __x) _NOEXCEPT
Ilya Tokarc3abffb2021-02-10 13:05:19 -05001344{
Nikolas Klauser9806f452022-10-12 15:45:09 +02001345 return __builtin_llroundl(__x);
Ilya Tokarc3abffb2021-02-10 13:05:19 -05001346}
Richard Smith081bb592015-10-08 20:40:34 +00001347
1348template <class _A1>
Nikolas Klauser4956e722022-10-12 15:41:22 +02001349inline _LIBCPP_HIDE_FROM_ABI
Richard Smith081bb592015-10-08 20:40:34 +00001350typename std::enable_if<std::is_integral<_A1>::value, long long>::type
Nikolas Klauser9806f452022-10-12 15:45:09 +02001351llround(_A1 __x) _NOEXCEPT
Ilya Tokarc3abffb2021-02-10 13:05:19 -05001352{
Nikolas Klauser9806f452022-10-12 15:45:09 +02001353 return __builtin_llround((double)__x);
Ilya Tokarc3abffb2021-02-10 13:05:19 -05001354}
Richard Smith081bb592015-10-08 20:40:34 +00001355
1356// log1p
1357
Nikolas Klauser04005952022-10-21 01:41:22 +02001358inline _LIBCPP_HIDE_FROM_ABI float log1p(float __x) _NOEXCEPT {return __builtin_log1pf(__x);}
Nikolas Klauser52399652022-11-01 22:29:57 +01001359
1360template <class = int>
1361_LIBCPP_HIDE_FROM_ABI double log1p(double __x) _NOEXCEPT {
1362 return __builtin_log1p(__x);
1363}
1364
Nikolas Klauser04005952022-10-21 01:41:22 +02001365inline _LIBCPP_HIDE_FROM_ABI long double log1p(long double __x) _NOEXCEPT {return __builtin_log1pl(__x);}
Richard Smith081bb592015-10-08 20:40:34 +00001366
1367template <class _A1>
Nikolas Klauser4956e722022-10-12 15:41:22 +02001368inline _LIBCPP_HIDE_FROM_ABI
Richard Smith081bb592015-10-08 20:40:34 +00001369typename std::enable_if<std::is_integral<_A1>::value, double>::type
Nikolas Klauser04005952022-10-21 01:41:22 +02001370log1p(_A1 __x) _NOEXCEPT {return __builtin_log1p((double)__x);}
Richard Smith081bb592015-10-08 20:40:34 +00001371
1372// log2
1373
Nikolas Klauser04005952022-10-21 01:41:22 +02001374inline _LIBCPP_HIDE_FROM_ABI float log2(float __x) _NOEXCEPT {return __builtin_log2f(__x);}
Nikolas Klauser52399652022-11-01 22:29:57 +01001375
1376template <class = int>
1377_LIBCPP_HIDE_FROM_ABI double log2(double __x) _NOEXCEPT {
1378 return __builtin_log2(__x);
1379}
1380
Nikolas Klauser04005952022-10-21 01:41:22 +02001381inline _LIBCPP_HIDE_FROM_ABI long double log2(long double __x) _NOEXCEPT {return __builtin_log2l(__x);}
Richard Smith081bb592015-10-08 20:40:34 +00001382
1383template <class _A1>
Nikolas Klauser4956e722022-10-12 15:41:22 +02001384inline _LIBCPP_HIDE_FROM_ABI
Richard Smith081bb592015-10-08 20:40:34 +00001385typename std::enable_if<std::is_integral<_A1>::value, double>::type
Nikolas Klauser04005952022-10-21 01:41:22 +02001386log2(_A1 __x) _NOEXCEPT {return __builtin_log2((double)__x);}
Richard Smith081bb592015-10-08 20:40:34 +00001387
1388// logb
1389
Nikolas Klauser04005952022-10-21 01:41:22 +02001390inline _LIBCPP_HIDE_FROM_ABI float logb(float __x) _NOEXCEPT {return __builtin_logbf(__x);}
Nikolas Klauser52399652022-11-01 22:29:57 +01001391
1392template <class = int>
1393_LIBCPP_HIDE_FROM_ABI double logb(double __x) _NOEXCEPT {
1394 return __builtin_logb(__x);
1395}
1396
Nikolas Klauser04005952022-10-21 01:41:22 +02001397inline _LIBCPP_HIDE_FROM_ABI long double logb(long double __x) _NOEXCEPT {return __builtin_logbl(__x);}
Richard Smith081bb592015-10-08 20:40:34 +00001398
1399template <class _A1>
Nikolas Klauser4956e722022-10-12 15:41:22 +02001400inline _LIBCPP_HIDE_FROM_ABI
Richard Smith081bb592015-10-08 20:40:34 +00001401typename std::enable_if<std::is_integral<_A1>::value, double>::type
Nikolas Klauser04005952022-10-21 01:41:22 +02001402logb(_A1 __x) _NOEXCEPT {return __builtin_logb((double)__x);}
Richard Smith081bb592015-10-08 20:40:34 +00001403
1404// lrint
1405
Nikolas Klauser9806f452022-10-12 15:45:09 +02001406inline _LIBCPP_HIDE_FROM_ABI long lrint(float __x) _NOEXCEPT
Ilya Tokarc3abffb2021-02-10 13:05:19 -05001407{
Nikolas Klauser9806f452022-10-12 15:45:09 +02001408 return __builtin_lrintf(__x);
Ilya Tokarc3abffb2021-02-10 13:05:19 -05001409}
Nikolas Klauser52399652022-11-01 22:29:57 +01001410
1411template <class = int>
1412_LIBCPP_HIDE_FROM_ABI long lrint(double __x) _NOEXCEPT {
1413 return __builtin_lrint(__x);
1414}
1415
Nikolas Klauser9806f452022-10-12 15:45:09 +02001416inline _LIBCPP_HIDE_FROM_ABI long lrint(long double __x) _NOEXCEPT
Ilya Tokarc3abffb2021-02-10 13:05:19 -05001417{
Nikolas Klauser9806f452022-10-12 15:45:09 +02001418 return __builtin_lrintl(__x);
Ilya Tokarc3abffb2021-02-10 13:05:19 -05001419}
Richard Smith081bb592015-10-08 20:40:34 +00001420
1421template <class _A1>
Nikolas Klauser4956e722022-10-12 15:41:22 +02001422inline _LIBCPP_HIDE_FROM_ABI
Richard Smith081bb592015-10-08 20:40:34 +00001423typename std::enable_if<std::is_integral<_A1>::value, long>::type
Nikolas Klauser9806f452022-10-12 15:45:09 +02001424lrint(_A1 __x) _NOEXCEPT
Ilya Tokarc3abffb2021-02-10 13:05:19 -05001425{
Nikolas Klauser9806f452022-10-12 15:45:09 +02001426 return __builtin_lrint((double)__x);
Ilya Tokarc3abffb2021-02-10 13:05:19 -05001427}
Richard Smith081bb592015-10-08 20:40:34 +00001428
1429// lround
1430
Nikolas Klauser9806f452022-10-12 15:45:09 +02001431inline _LIBCPP_HIDE_FROM_ABI long lround(float __x) _NOEXCEPT
Ilya Tokarc3abffb2021-02-10 13:05:19 -05001432{
Nikolas Klauser9806f452022-10-12 15:45:09 +02001433 return __builtin_lroundf(__x);
Ilya Tokarc3abffb2021-02-10 13:05:19 -05001434}
Nikolas Klauser52399652022-11-01 22:29:57 +01001435
1436template <class = int>
1437_LIBCPP_HIDE_FROM_ABI long lround(double __x) _NOEXCEPT {
1438 return __builtin_lround(__x);
1439}
1440
Nikolas Klauser9806f452022-10-12 15:45:09 +02001441inline _LIBCPP_HIDE_FROM_ABI long lround(long double __x) _NOEXCEPT
Ilya Tokarc3abffb2021-02-10 13:05:19 -05001442{
Nikolas Klauser9806f452022-10-12 15:45:09 +02001443 return __builtin_lroundl(__x);
Ilya Tokarc3abffb2021-02-10 13:05:19 -05001444}
Richard Smith081bb592015-10-08 20:40:34 +00001445
1446template <class _A1>
Nikolas Klauser4956e722022-10-12 15:41:22 +02001447inline _LIBCPP_HIDE_FROM_ABI
Richard Smith081bb592015-10-08 20:40:34 +00001448typename std::enable_if<std::is_integral<_A1>::value, long>::type
Nikolas Klauser9806f452022-10-12 15:45:09 +02001449lround(_A1 __x) _NOEXCEPT
Ilya Tokarc3abffb2021-02-10 13:05:19 -05001450{
Nikolas Klauser9806f452022-10-12 15:45:09 +02001451 return __builtin_lround((double)__x);
Ilya Tokarc3abffb2021-02-10 13:05:19 -05001452}
Richard Smith081bb592015-10-08 20:40:34 +00001453
1454// nan
1455
1456// nearbyint
1457
Nikolas Klauserb0bb09c2022-12-25 20:13:39 +01001458_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI float nearbyint(float __x) _NOEXCEPT {return __builtin_nearbyintf(__x);}
Nikolas Klauser52399652022-11-01 22:29:57 +01001459
1460template <class = int>
Nikolas Klauserb0bb09c2022-12-25 20:13:39 +01001461_LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI double nearbyint(double __x) _NOEXCEPT {
Nikolas Klauser52399652022-11-01 22:29:57 +01001462 return __builtin_nearbyint(__x);
1463}
1464
Nikolas Klauserb0bb09c2022-12-25 20:13:39 +01001465_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI long double nearbyint(long double __x) _NOEXCEPT {return __builtin_nearbyintl(__x);}
Richard Smith081bb592015-10-08 20:40:34 +00001466
1467template <class _A1>
Nikolas Klauserb0bb09c2022-12-25 20:13:39 +01001468_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI
Richard Smith081bb592015-10-08 20:40:34 +00001469typename std::enable_if<std::is_integral<_A1>::value, double>::type
Nikolas Klauser04005952022-10-21 01:41:22 +02001470nearbyint(_A1 __x) _NOEXCEPT {return __builtin_nearbyint((double)__x);}
Richard Smith081bb592015-10-08 20:40:34 +00001471
1472// nextafter
1473
Nikolas Klauser04005952022-10-21 01:41:22 +02001474inline _LIBCPP_HIDE_FROM_ABI float nextafter(float __x, float __y) _NOEXCEPT {return __builtin_nextafterf(__x, __y);}
Nikolas Klauser52399652022-11-01 22:29:57 +01001475
1476template <class = int>
1477_LIBCPP_HIDE_FROM_ABI double nextafter(double __x, double __y) _NOEXCEPT {
1478 return __builtin_nextafter(__x, __y);
1479}
1480
Nikolas Klauser04005952022-10-21 01:41:22 +02001481inline _LIBCPP_HIDE_FROM_ABI long double nextafter(long double __x, long double __y) _NOEXCEPT {return __builtin_nextafterl(__x, __y);}
Richard Smith081bb592015-10-08 20:40:34 +00001482
1483template <class _A1, class _A2>
Nikolas Klauser4956e722022-10-12 15:41:22 +02001484inline _LIBCPP_HIDE_FROM_ABI
Louis Dionne9ce598d2021-09-08 09:14:43 -04001485typename std::__enable_if_t
Richard Smith081bb592015-10-08 20:40:34 +00001486<
1487 std::is_arithmetic<_A1>::value &&
1488 std::is_arithmetic<_A2>::value,
1489 std::__promote<_A1, _A2>
1490>::type
Nikolas Klauser9806f452022-10-12 15:45:09 +02001491nextafter(_A1 __x, _A2 __y) _NOEXCEPT
Richard Smith081bb592015-10-08 20:40:34 +00001492{
1493 typedef typename std::__promote<_A1, _A2>::type __result_type;
Eric Fiselier3906a132019-06-23 20:28:29 +00001494 static_assert((!(std::_IsSame<_A1, __result_type>::value &&
1495 std::_IsSame<_A2, __result_type>::value)), "");
Nikolas Klauser9806f452022-10-12 15:45:09 +02001496 return ::nextafter((__result_type)__x, (__result_type)__y);
Richard Smith081bb592015-10-08 20:40:34 +00001497}
1498
1499// nexttoward
1500
Nikolas Klauser04005952022-10-21 01:41:22 +02001501inline _LIBCPP_HIDE_FROM_ABI float nexttoward(float __x, long double __y) _NOEXCEPT {return __builtin_nexttowardf(__x, __y);}
Nikolas Klauser52399652022-11-01 22:29:57 +01001502
1503template <class = int>
1504_LIBCPP_HIDE_FROM_ABI double nexttoward(double __x, long double __y) _NOEXCEPT {
1505 return __builtin_nexttoward(__x, __y);
1506}
1507
Nikolas Klauser04005952022-10-21 01:41:22 +02001508inline _LIBCPP_HIDE_FROM_ABI long double nexttoward(long double __x, long double __y) _NOEXCEPT {return __builtin_nexttowardl(__x, __y);}
Richard Smith081bb592015-10-08 20:40:34 +00001509
1510template <class _A1>
Nikolas Klauser4956e722022-10-12 15:41:22 +02001511inline _LIBCPP_HIDE_FROM_ABI
Richard Smith081bb592015-10-08 20:40:34 +00001512typename std::enable_if<std::is_integral<_A1>::value, double>::type
Nikolas Klauser04005952022-10-21 01:41:22 +02001513nexttoward(_A1 __x, long double __y) _NOEXCEPT {return __builtin_nexttoward((double)__x, __y);}
Richard Smith081bb592015-10-08 20:40:34 +00001514
1515// remainder
1516
Nikolas Klauser04005952022-10-21 01:41:22 +02001517inline _LIBCPP_HIDE_FROM_ABI float remainder(float __x, float __y) _NOEXCEPT {return __builtin_remainderf(__x, __y);}
Nikolas Klauser52399652022-11-01 22:29:57 +01001518
1519template <class = int>
1520_LIBCPP_HIDE_FROM_ABI double remainder(double __x, double __y) _NOEXCEPT {
1521 return __builtin_remainder(__x, __y);
1522}
1523
Nikolas Klauser04005952022-10-21 01:41:22 +02001524inline _LIBCPP_HIDE_FROM_ABI long double remainder(long double __x, long double __y) _NOEXCEPT {return __builtin_remainderl(__x, __y);}
Richard Smith081bb592015-10-08 20:40:34 +00001525
1526template <class _A1, class _A2>
Nikolas Klauser4956e722022-10-12 15:41:22 +02001527inline _LIBCPP_HIDE_FROM_ABI
Louis Dionne9ce598d2021-09-08 09:14:43 -04001528typename std::__enable_if_t
Richard Smith081bb592015-10-08 20:40:34 +00001529<
1530 std::is_arithmetic<_A1>::value &&
1531 std::is_arithmetic<_A2>::value,
1532 std::__promote<_A1, _A2>
1533>::type
Nikolas Klauser9806f452022-10-12 15:45:09 +02001534remainder(_A1 __x, _A2 __y) _NOEXCEPT
Richard Smith081bb592015-10-08 20:40:34 +00001535{
1536 typedef typename std::__promote<_A1, _A2>::type __result_type;
Eric Fiselier3906a132019-06-23 20:28:29 +00001537 static_assert((!(std::_IsSame<_A1, __result_type>::value &&
1538 std::_IsSame<_A2, __result_type>::value)), "");
Nikolas Klauser9806f452022-10-12 15:45:09 +02001539 return ::remainder((__result_type)__x, (__result_type)__y);
Richard Smith081bb592015-10-08 20:40:34 +00001540}
1541
1542// remquo
1543
Nikolas Klauser04005952022-10-21 01:41:22 +02001544inline _LIBCPP_HIDE_FROM_ABI float remquo(float __x, float __y, int* __z) _NOEXCEPT {return __builtin_remquof(__x, __y, __z);}
Nikolas Klauser52399652022-11-01 22:29:57 +01001545
1546template <class = int>
1547_LIBCPP_HIDE_FROM_ABI double remquo(double __x, double __y, int* __z) _NOEXCEPT {
1548 return __builtin_remquo(__x, __y, __z);
1549}
1550
Nikolas Klauser04005952022-10-21 01:41:22 +02001551inline _LIBCPP_HIDE_FROM_ABI long double remquo(long double __x, long double __y, int* __z) _NOEXCEPT {return __builtin_remquol(__x, __y, __z);}
Richard Smith081bb592015-10-08 20:40:34 +00001552
1553template <class _A1, class _A2>
Nikolas Klauser4956e722022-10-12 15:41:22 +02001554inline _LIBCPP_HIDE_FROM_ABI
Louis Dionne9ce598d2021-09-08 09:14:43 -04001555typename std::__enable_if_t
Richard Smith081bb592015-10-08 20:40:34 +00001556<
1557 std::is_arithmetic<_A1>::value &&
1558 std::is_arithmetic<_A2>::value,
1559 std::__promote<_A1, _A2>
1560>::type
Nikolas Klauser9806f452022-10-12 15:45:09 +02001561remquo(_A1 __x, _A2 __y, int* __z) _NOEXCEPT
Richard Smith081bb592015-10-08 20:40:34 +00001562{
1563 typedef typename std::__promote<_A1, _A2>::type __result_type;
Eric Fiselier3906a132019-06-23 20:28:29 +00001564 static_assert((!(std::_IsSame<_A1, __result_type>::value &&
1565 std::_IsSame<_A2, __result_type>::value)), "");
Nikolas Klauser9806f452022-10-12 15:45:09 +02001566 return ::remquo((__result_type)__x, (__result_type)__y, __z);
Richard Smith081bb592015-10-08 20:40:34 +00001567}
1568
1569// rint
1570
Nikolas Klauserb0bb09c2022-12-25 20:13:39 +01001571_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI float rint(float __x) _NOEXCEPT
Ilya Tokarc3abffb2021-02-10 13:05:19 -05001572{
Nikolas Klauser9806f452022-10-12 15:45:09 +02001573 return __builtin_rintf(__x);
Ilya Tokarc3abffb2021-02-10 13:05:19 -05001574}
Nikolas Klauser52399652022-11-01 22:29:57 +01001575
1576template <class = int>
Nikolas Klauserb0bb09c2022-12-25 20:13:39 +01001577_LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI double rint(double __x) _NOEXCEPT {
Nikolas Klauser52399652022-11-01 22:29:57 +01001578 return __builtin_rint(__x);
1579}
1580
Nikolas Klauserb0bb09c2022-12-25 20:13:39 +01001581_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI long double rint(long double __x) _NOEXCEPT
Ilya Tokarc3abffb2021-02-10 13:05:19 -05001582{
Nikolas Klauser9806f452022-10-12 15:45:09 +02001583 return __builtin_rintl(__x);
Ilya Tokarc3abffb2021-02-10 13:05:19 -05001584}
Richard Smith081bb592015-10-08 20:40:34 +00001585
1586template <class _A1>
Nikolas Klauserb0bb09c2022-12-25 20:13:39 +01001587_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI
Richard Smith081bb592015-10-08 20:40:34 +00001588typename std::enable_if<std::is_integral<_A1>::value, double>::type
Nikolas Klauser9806f452022-10-12 15:45:09 +02001589rint(_A1 __x) _NOEXCEPT
Ilya Tokarc3abffb2021-02-10 13:05:19 -05001590{
Nikolas Klauser9806f452022-10-12 15:45:09 +02001591 return __builtin_rint((double)__x);
Ilya Tokarc3abffb2021-02-10 13:05:19 -05001592}
Richard Smith081bb592015-10-08 20:40:34 +00001593
1594// round
1595
Nikolas Klauserb0bb09c2022-12-25 20:13:39 +01001596_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI float round(float __x) _NOEXCEPT
Ilya Tokarc3abffb2021-02-10 13:05:19 -05001597{
Nikolas Klauser9806f452022-10-12 15:45:09 +02001598 return __builtin_round(__x);
Ilya Tokarc3abffb2021-02-10 13:05:19 -05001599}
Nikolas Klauser52399652022-11-01 22:29:57 +01001600
1601template <class = int>
Nikolas Klauserb0bb09c2022-12-25 20:13:39 +01001602_LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI double round(double __x) _NOEXCEPT {
Nikolas Klauser52399652022-11-01 22:29:57 +01001603 return __builtin_round(__x);
1604}
1605
Nikolas Klauserb0bb09c2022-12-25 20:13:39 +01001606_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI long double round(long double __x) _NOEXCEPT
Ilya Tokarc3abffb2021-02-10 13:05:19 -05001607{
Nikolas Klauser9806f452022-10-12 15:45:09 +02001608 return __builtin_roundl(__x);
Ilya Tokarc3abffb2021-02-10 13:05:19 -05001609}
Richard Smith081bb592015-10-08 20:40:34 +00001610
1611template <class _A1>
Nikolas Klauserb0bb09c2022-12-25 20:13:39 +01001612_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI
Richard Smith081bb592015-10-08 20:40:34 +00001613typename std::enable_if<std::is_integral<_A1>::value, double>::type
Nikolas Klauser9806f452022-10-12 15:45:09 +02001614round(_A1 __x) _NOEXCEPT
Ilya Tokarc3abffb2021-02-10 13:05:19 -05001615{
Nikolas Klauser9806f452022-10-12 15:45:09 +02001616 return __builtin_round((double)__x);
Ilya Tokarc3abffb2021-02-10 13:05:19 -05001617}
Richard Smith081bb592015-10-08 20:40:34 +00001618
1619// scalbln
1620
Nikolas Klauser04005952022-10-21 01:41:22 +02001621inline _LIBCPP_HIDE_FROM_ABI float scalbln(float __x, long __y) _NOEXCEPT {return __builtin_scalblnf(__x, __y);}
Nikolas Klauser52399652022-11-01 22:29:57 +01001622
1623template <class = int>
1624_LIBCPP_HIDE_FROM_ABI double scalbln(double __x, long __y) _NOEXCEPT {
1625 return __builtin_scalbln(__x, __y);
1626}
1627
Nikolas Klauser04005952022-10-21 01:41:22 +02001628inline _LIBCPP_HIDE_FROM_ABI long double scalbln(long double __x, long __y) _NOEXCEPT {return __builtin_scalblnl(__x, __y);}
Richard Smith081bb592015-10-08 20:40:34 +00001629
1630template <class _A1>
Nikolas Klauser4956e722022-10-12 15:41:22 +02001631inline _LIBCPP_HIDE_FROM_ABI
Richard Smith081bb592015-10-08 20:40:34 +00001632typename std::enable_if<std::is_integral<_A1>::value, double>::type
Nikolas Klauser04005952022-10-21 01:41:22 +02001633scalbln(_A1 __x, long __y) _NOEXCEPT {return __builtin_scalbln((double)__x, __y);}
Richard Smith081bb592015-10-08 20:40:34 +00001634
1635// scalbn
1636
Nikolas Klauser04005952022-10-21 01:41:22 +02001637inline _LIBCPP_HIDE_FROM_ABI float scalbn(float __x, int __y) _NOEXCEPT {return __builtin_scalbnf(__x, __y);}
Nikolas Klauser52399652022-11-01 22:29:57 +01001638
1639template <class = int>
1640_LIBCPP_HIDE_FROM_ABI double scalbn(double __x, int __y) _NOEXCEPT {
1641 return __builtin_scalbn(__x, __y);
1642}
1643
Nikolas Klauser04005952022-10-21 01:41:22 +02001644inline _LIBCPP_HIDE_FROM_ABI long double scalbn(long double __x, int __y) _NOEXCEPT {return __builtin_scalbnl(__x, __y);}
Richard Smith081bb592015-10-08 20:40:34 +00001645
1646template <class _A1>
Nikolas Klauser4956e722022-10-12 15:41:22 +02001647inline _LIBCPP_HIDE_FROM_ABI
Richard Smith081bb592015-10-08 20:40:34 +00001648typename std::enable_if<std::is_integral<_A1>::value, double>::type
Nikolas Klauser04005952022-10-21 01:41:22 +02001649scalbn(_A1 __x, int __y) _NOEXCEPT {return __builtin_scalbn((double)__x, __y);}
Richard Smith081bb592015-10-08 20:40:34 +00001650
1651// tgamma
1652
Nikolas Klauser04005952022-10-21 01:41:22 +02001653inline _LIBCPP_HIDE_FROM_ABI float tgamma(float __x) _NOEXCEPT {return __builtin_tgammaf(__x);}
Nikolas Klauser52399652022-11-01 22:29:57 +01001654
1655template <class = int>
1656_LIBCPP_HIDE_FROM_ABI double tgamma(double __x) _NOEXCEPT {
1657 return __builtin_tgamma(__x);
1658}
1659
Nikolas Klauser04005952022-10-21 01:41:22 +02001660inline _LIBCPP_HIDE_FROM_ABI long double tgamma(long double __x) _NOEXCEPT {return __builtin_tgammal(__x);}
Richard Smith081bb592015-10-08 20:40:34 +00001661
1662template <class _A1>
Nikolas Klauser4956e722022-10-12 15:41:22 +02001663inline _LIBCPP_HIDE_FROM_ABI
Richard Smith081bb592015-10-08 20:40:34 +00001664typename std::enable_if<std::is_integral<_A1>::value, double>::type
Nikolas Klauser04005952022-10-21 01:41:22 +02001665tgamma(_A1 __x) _NOEXCEPT {return __builtin_tgamma((double)__x);}
Richard Smith081bb592015-10-08 20:40:34 +00001666
1667// trunc
1668
Nikolas Klauserb0bb09c2022-12-25 20:13:39 +01001669_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI float trunc(float __x) _NOEXCEPT
Ilya Tokarc3abffb2021-02-10 13:05:19 -05001670{
Nikolas Klauser9806f452022-10-12 15:45:09 +02001671 return __builtin_trunc(__x);
Ilya Tokarc3abffb2021-02-10 13:05:19 -05001672}
Nikolas Klauser52399652022-11-01 22:29:57 +01001673
1674template <class = int>
Nikolas Klauserb0bb09c2022-12-25 20:13:39 +01001675_LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI double trunc(double __x) _NOEXCEPT {
Nikolas Klauser52399652022-11-01 22:29:57 +01001676 return __builtin_trunc(__x);
1677}
1678
Nikolas Klauserb0bb09c2022-12-25 20:13:39 +01001679_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI long double trunc(long double __x) _NOEXCEPT
Ilya Tokarc3abffb2021-02-10 13:05:19 -05001680{
Nikolas Klauser9806f452022-10-12 15:45:09 +02001681 return __builtin_truncl(__x);
Ilya Tokarc3abffb2021-02-10 13:05:19 -05001682}
Richard Smith081bb592015-10-08 20:40:34 +00001683
1684template <class _A1>
Nikolas Klauserb0bb09c2022-12-25 20:13:39 +01001685_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI
Richard Smith081bb592015-10-08 20:40:34 +00001686typename std::enable_if<std::is_integral<_A1>::value, double>::type
Nikolas Klauser9806f452022-10-12 15:45:09 +02001687trunc(_A1 __x) _NOEXCEPT
Ilya Tokarc3abffb2021-02-10 13:05:19 -05001688{
Nikolas Klauser9806f452022-10-12 15:45:09 +02001689 return __builtin_trunc((double)__x);
Ilya Tokarc3abffb2021-02-10 13:05:19 -05001690}
Richard Smith081bb592015-10-08 20:40:34 +00001691
Richard Smith081bb592015-10-08 20:40:34 +00001692} // extern "C++"
1693
1694#endif // __cplusplus
1695
Mikhail Maltsev34b4f972018-02-22 09:34:08 +00001696#else // _LIBCPP_MATH_H
1697
1698// This include lives outside the header guard in order to support an MSVC
1699// extension which allows users to do:
1700//
1701// #define _USE_MATH_DEFINES
1702// #include <math.h>
1703//
1704// and receive the definitions of mathematical constants, even if <math.h>
1705// has previously been included.
1706#if defined(_LIBCPP_MSVCRT) && defined(_USE_MATH_DEFINES)
1707#include_next <math.h>
1708#endif
1709
Louis Dionne2b1ceaa2021-04-20 12:03:32 -04001710#endif // _LIBCPP_MATH_H