blob: 14fa9e286ea30e1cd14c6bf32b0f8a9e5d3672d2 [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>
370inline _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>
375inline _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>
380inline _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>
387inline _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>
392inline _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 Klauserdfc04a32022-12-19 00:02:44 +0100403_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 Klauserdfc04a32022-12-19 00:02:44 +0100409_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 Klauserdfc04a32022-12-19 00:02:44 +0100417_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 Klauserdfc04a32022-12-19 00:02:44 +0100422_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 Klauserdfc04a32022-12-19 00:02:44 +0100429inline _LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI bool isinf(float __x) _NOEXCEPT {
430 return __builtin_isinf(__x);
431}
Richard Smithafccfd32018-05-01 03:05:40 +0000432
Nikolas Klauserdfc04a32022-12-19 00:02:44 +0100433inline _LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI _LIBCPP_PREFERRED_OVERLOAD bool isinf(double __x) _NOEXCEPT {
434 return __builtin_isinf(__x);
435}
Richard Smithafccfd32018-05-01 03:05:40 +0000436
Nikolas Klauserdfc04a32022-12-19 00:02:44 +0100437inline _LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI bool isinf(long double __x) _NOEXCEPT {
438 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 Klauserdfc04a32022-12-19 00:02:44 +0100445_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 Klauserdfc04a32022-12-19 00:02:44 +0100450_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 Klauserdfc04a32022-12-19 00:02:44 +0100455inline _LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI bool isnan(float __x) _NOEXCEPT {
456 return __builtin_isnan(__x);
457}
Richard Smithafccfd32018-05-01 03:05:40 +0000458
Nikolas Klauserdfc04a32022-12-19 00:02:44 +0100459inline _LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI _LIBCPP_PREFERRED_OVERLOAD bool isnan(double __x) _NOEXCEPT {
460 return __builtin_isnan(__x);
461}
Richard Smithafccfd32018-05-01 03:05:40 +0000462
Nikolas Klauserdfc04a32022-12-19 00:02:44 +0100463inline _LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI bool isnan(long double __x) _NOEXCEPT {
464 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 Klauserdfc04a32022-12-19 00:02:44 +0100471_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 Klauserdfc04a32022-12-19 00:02:44 +0100476_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>
485inline _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>
495inline _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>
505inline _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>
515inline _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>
525inline _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>
535inline _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 Klauser04005952022-10-21 01:41:22 +0200641inline _LIBCPP_HIDE_FROM_ABI float ceil(float __x) _NOEXCEPT {return __builtin_ceilf(__x);}
Nikolas Klauser52399652022-11-01 22:29:57 +0100642
643template <class = int>
644_LIBCPP_HIDE_FROM_ABI double ceil(double __x) _NOEXCEPT {
645 return __builtin_ceil(__x);
646}
647
Nikolas Klauser04005952022-10-21 01:41:22 +0200648inline _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 Klauser4956e722022-10-12 15:41:22 +0200652inline _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 Klauser04005952022-10-21 01:41:22 +0200713inline _LIBCPP_HIDE_FROM_ABI float fabs(float __x) _NOEXCEPT {return __builtin_fabsf(__x);}
Nikolas Klauser52399652022-11-01 22:29:57 +0100714
715template <class = int>
716_LIBCPP_HIDE_FROM_ABI double fabs(double __x) _NOEXCEPT {
717 return __builtin_fabs(__x);
718}
719
Nikolas Klauser04005952022-10-21 01:41:22 +0200720inline _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 Klauser4956e722022-10-12 15:41:22 +0200724inline _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 Klauser04005952022-10-21 01:41:22 +0200731inline _LIBCPP_HIDE_FROM_ABI float floor(float __x) _NOEXCEPT {return __builtin_floorf(__x);}
Nikolas Klauser52399652022-11-01 22:29:57 +0100732
733template <class = int>
734_LIBCPP_HIDE_FROM_ABI double floor(double __x) _NOEXCEPT {
735 return __builtin_floor(__x);
736}
737
Nikolas Klauser04005952022-10-21 01:41:22 +0200738inline _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 Klauser4956e722022-10-12 15:41:22 +0200742inline _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 Klauser04005952022-10-21 01:41:22 +02001030inline _LIBCPP_HIDE_FROM_ABI float cbrt(float __x) _NOEXCEPT {return __builtin_cbrtf(__x);}
Nikolas Klauser52399652022-11-01 22:29:57 +01001031
1032template <class = int>
1033_LIBCPP_HIDE_FROM_ABI double cbrt(double __x) _NOEXCEPT {
1034 return __builtin_cbrt(__x);
1035}
1036
Nikolas Klauser04005952022-10-21 01:41:22 +02001037inline _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 Klauser4956e722022-10-12 15:41:22 +02001040inline _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
Marek Kurdeja933f0d2021-07-21 15:58:17 +02001046_LIBCPP_CONSTEXPR
Nikolas Klauser9806f452022-10-12 15:45:09 +02001047inline _LIBCPP_HIDE_FROM_ABI float __libcpp_copysign(float __x, float __y) _NOEXCEPT {
Nikolas Klauser9806f452022-10-12 15:45:09 +02001048 return __builtin_copysignf(__x, __y);
Richard Smith081bb592015-10-08 20:40:34 +00001049}
Marek Kurdeja933f0d2021-07-21 15:58:17 +02001050
Marek Kurdeja933f0d2021-07-21 15:58:17 +02001051_LIBCPP_CONSTEXPR
Nikolas Klauser9806f452022-10-12 15:45:09 +02001052inline _LIBCPP_HIDE_FROM_ABI double __libcpp_copysign(double __x, double __y) _NOEXCEPT {
Nikolas Klauser9806f452022-10-12 15:45:09 +02001053 return __builtin_copysign(__x, __y);
Marek Kurdeja933f0d2021-07-21 15:58:17 +02001054}
1055
Marek Kurdeja933f0d2021-07-21 15:58:17 +02001056_LIBCPP_CONSTEXPR
Nikolas Klauser9806f452022-10-12 15:45:09 +02001057inline _LIBCPP_HIDE_FROM_ABI long double __libcpp_copysign(long double __x, long double __y) _NOEXCEPT {
Nikolas Klauser9806f452022-10-12 15:45:09 +02001058 return __builtin_copysignl(__x, __y);
Richard Smith081bb592015-10-08 20:40:34 +00001059}
Richard Smith081bb592015-10-08 20:40:34 +00001060
1061template <class _A1, class _A2>
Marek Kurdeja933f0d2021-07-21 15:58:17 +02001062_LIBCPP_CONSTEXPR
Nikolas Klauser4956e722022-10-12 15:41:22 +02001063inline _LIBCPP_HIDE_FROM_ABI
Louis Dionne9ce598d2021-09-08 09:14:43 -04001064typename std::__enable_if_t
Marek Kurdeja933f0d2021-07-21 15:58:17 +02001065<
1066 std::is_arithmetic<_A1>::value &&
1067 std::is_arithmetic<_A2>::value,
1068 std::__promote<_A1, _A2>
1069>::type
Nikolas Klauser9806f452022-10-12 15:45:09 +02001070__libcpp_copysign(_A1 __x, _A2 __y) _NOEXCEPT {
Marek Kurdeja933f0d2021-07-21 15:58:17 +02001071 typedef typename std::__promote<_A1, _A2>::type __result_type;
1072 static_assert((!(std::_IsSame<_A1, __result_type>::value &&
1073 std::_IsSame<_A2, __result_type>::value)), "");
Nikolas Klauser9806f452022-10-12 15:45:09 +02001074 return __builtin_copysign((__result_type)__x, (__result_type)__y);
Marek Kurdeja933f0d2021-07-21 15:58:17 +02001075}
1076
Nikolas Klauser9806f452022-10-12 15:45:09 +02001077inline _LIBCPP_HIDE_FROM_ABI float copysign(float __x, float __y) _NOEXCEPT {
1078 return ::__libcpp_copysign(__x, __y);
Marek Kurdeja933f0d2021-07-21 15:58:17 +02001079}
1080
Nikolas Klauser9806f452022-10-12 15:45:09 +02001081inline _LIBCPP_HIDE_FROM_ABI long double copysign(long double __x, long double __y) _NOEXCEPT {
1082 return ::__libcpp_copysign(__x, __y);
Marek Kurdeja933f0d2021-07-21 15:58:17 +02001083}
1084
1085template <class _A1, class _A2>
Nikolas Klauser4956e722022-10-12 15:41:22 +02001086inline _LIBCPP_HIDE_FROM_ABI
Louis Dionne9ce598d2021-09-08 09:14:43 -04001087typename std::__enable_if_t
Richard Smith081bb592015-10-08 20:40:34 +00001088<
1089 std::is_arithmetic<_A1>::value &&
1090 std::is_arithmetic<_A2>::value,
1091 std::__promote<_A1, _A2>
1092>::type
Nikolas Klauser9806f452022-10-12 15:45:09 +02001093 copysign(_A1 __x, _A2 __y) _NOEXCEPT {
1094 return ::__libcpp_copysign(__x, __y);
Richard Smith081bb592015-10-08 20:40:34 +00001095}
1096
Richard Smith081bb592015-10-08 20:40:34 +00001097// erf
1098
Nikolas Klauser04005952022-10-21 01:41:22 +02001099inline _LIBCPP_HIDE_FROM_ABI float erf(float __x) _NOEXCEPT {return __builtin_erff(__x);}
Nikolas Klauser52399652022-11-01 22:29:57 +01001100
1101template <class = int>
1102_LIBCPP_HIDE_FROM_ABI double erf(double __x) _NOEXCEPT {
1103 return __builtin_erf(__x);
1104}
1105
Nikolas Klauser04005952022-10-21 01:41:22 +02001106inline _LIBCPP_HIDE_FROM_ABI long double erf(long double __x) _NOEXCEPT {return __builtin_erfl(__x);}
Richard Smith081bb592015-10-08 20:40:34 +00001107
1108template <class _A1>
Nikolas Klauser4956e722022-10-12 15:41:22 +02001109inline _LIBCPP_HIDE_FROM_ABI
Richard Smith081bb592015-10-08 20:40:34 +00001110typename std::enable_if<std::is_integral<_A1>::value, double>::type
Nikolas Klauser04005952022-10-21 01:41:22 +02001111erf(_A1 __x) _NOEXCEPT {return __builtin_erf((double)__x);}
Richard Smith081bb592015-10-08 20:40:34 +00001112
1113// erfc
1114
Nikolas Klauser04005952022-10-21 01:41:22 +02001115inline _LIBCPP_HIDE_FROM_ABI float erfc(float __x) _NOEXCEPT {return __builtin_erfcf(__x);}
Nikolas Klauser52399652022-11-01 22:29:57 +01001116
1117template <class = int>
1118_LIBCPP_HIDE_FROM_ABI double erfc(double __x) _NOEXCEPT {
1119 return __builtin_erfc(__x);
1120}
1121
Nikolas Klauser04005952022-10-21 01:41:22 +02001122inline _LIBCPP_HIDE_FROM_ABI long double erfc(long double __x) _NOEXCEPT {return __builtin_erfcl(__x);}
Richard Smith081bb592015-10-08 20:40:34 +00001123
1124template <class _A1>
Nikolas Klauser4956e722022-10-12 15:41:22 +02001125inline _LIBCPP_HIDE_FROM_ABI
Richard Smith081bb592015-10-08 20:40:34 +00001126typename std::enable_if<std::is_integral<_A1>::value, double>::type
Nikolas Klauser04005952022-10-21 01:41:22 +02001127erfc(_A1 __x) _NOEXCEPT {return __builtin_erfc((double)__x);}
Richard Smith081bb592015-10-08 20:40:34 +00001128
1129// exp2
1130
Nikolas Klauser04005952022-10-21 01:41:22 +02001131inline _LIBCPP_HIDE_FROM_ABI float exp2(float __x) _NOEXCEPT {return __builtin_exp2f(__x);}
Nikolas Klauser52399652022-11-01 22:29:57 +01001132
1133template <class = int>
1134_LIBCPP_HIDE_FROM_ABI double exp2(double __x) _NOEXCEPT {
1135 return __builtin_exp2(__x);
1136}
1137
Nikolas Klauser04005952022-10-21 01:41:22 +02001138inline _LIBCPP_HIDE_FROM_ABI long double exp2(long double __x) _NOEXCEPT {return __builtin_exp2l(__x);}
Richard Smith081bb592015-10-08 20:40:34 +00001139
1140template <class _A1>
Nikolas Klauser4956e722022-10-12 15:41:22 +02001141inline _LIBCPP_HIDE_FROM_ABI
Richard Smith081bb592015-10-08 20:40:34 +00001142typename std::enable_if<std::is_integral<_A1>::value, double>::type
Nikolas Klauser04005952022-10-21 01:41:22 +02001143exp2(_A1 __x) _NOEXCEPT {return __builtin_exp2((double)__x);}
Richard Smith081bb592015-10-08 20:40:34 +00001144
1145// expm1
1146
Nikolas Klauser04005952022-10-21 01:41:22 +02001147inline _LIBCPP_HIDE_FROM_ABI float expm1(float __x) _NOEXCEPT {return __builtin_expm1f(__x);}
Nikolas Klauser52399652022-11-01 22:29:57 +01001148
1149template <class = int>
1150_LIBCPP_HIDE_FROM_ABI double expm1(double __x) _NOEXCEPT {
1151 return __builtin_expm1(__x);
1152}
1153
Nikolas Klauser04005952022-10-21 01:41:22 +02001154inline _LIBCPP_HIDE_FROM_ABI long double expm1(long double __x) _NOEXCEPT {return __builtin_expm1l(__x);}
Richard Smith081bb592015-10-08 20:40:34 +00001155
1156template <class _A1>
Nikolas Klauser4956e722022-10-12 15:41:22 +02001157inline _LIBCPP_HIDE_FROM_ABI
Richard Smith081bb592015-10-08 20:40:34 +00001158typename std::enable_if<std::is_integral<_A1>::value, double>::type
Nikolas Klauser04005952022-10-21 01:41:22 +02001159expm1(_A1 __x) _NOEXCEPT {return __builtin_expm1((double)__x);}
Richard Smith081bb592015-10-08 20:40:34 +00001160
1161// fdim
1162
Nikolas Klauser04005952022-10-21 01:41:22 +02001163inline _LIBCPP_HIDE_FROM_ABI float fdim(float __x, float __y) _NOEXCEPT {return __builtin_fdimf(__x, __y);}
Nikolas Klauser52399652022-11-01 22:29:57 +01001164
1165template <class = int>
1166_LIBCPP_HIDE_FROM_ABI double fdim(double __x, double __y) _NOEXCEPT {
1167 return __builtin_fdim(__x, __y);
1168}
1169
Nikolas Klauser04005952022-10-21 01:41:22 +02001170inline _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 +00001171
1172template <class _A1, class _A2>
Nikolas Klauser4956e722022-10-12 15:41:22 +02001173inline _LIBCPP_HIDE_FROM_ABI
Louis Dionne9ce598d2021-09-08 09:14:43 -04001174typename std::__enable_if_t
Richard Smith081bb592015-10-08 20:40:34 +00001175<
1176 std::is_arithmetic<_A1>::value &&
1177 std::is_arithmetic<_A2>::value,
1178 std::__promote<_A1, _A2>
1179>::type
Nikolas Klauser9806f452022-10-12 15:45:09 +02001180fdim(_A1 __x, _A2 __y) _NOEXCEPT
Richard Smith081bb592015-10-08 20:40:34 +00001181{
1182 typedef typename std::__promote<_A1, _A2>::type __result_type;
Eric Fiselier3906a132019-06-23 20:28:29 +00001183 static_assert((!(std::_IsSame<_A1, __result_type>::value &&
1184 std::_IsSame<_A2, __result_type>::value)), "");
Nikolas Klauser9806f452022-10-12 15:45:09 +02001185 return ::fdim((__result_type)__x, (__result_type)__y);
Richard Smith081bb592015-10-08 20:40:34 +00001186}
1187
1188// fma
1189
Nikolas Klauser9806f452022-10-12 15:45:09 +02001190inline _LIBCPP_HIDE_FROM_ABI float fma(float __x, float __y, float __z) _NOEXCEPT
Ilya Tokarc3abffb2021-02-10 13:05:19 -05001191{
Nikolas Klauser9806f452022-10-12 15:45:09 +02001192 return __builtin_fmaf(__x, __y, __z);
Ilya Tokarc3abffb2021-02-10 13:05:19 -05001193}
Nikolas Klauser52399652022-11-01 22:29:57 +01001194
1195
1196template <class = int>
1197_LIBCPP_HIDE_FROM_ABI double fma(double __x, double __y, double __z) _NOEXCEPT {
1198 return __builtin_fma(__x, __y, __z);
1199}
1200
Nikolas Klauser9806f452022-10-12 15:45:09 +02001201inline _LIBCPP_HIDE_FROM_ABI long double fma(long double __x, long double __y, long double __z) _NOEXCEPT
Ilya Tokarc3abffb2021-02-10 13:05:19 -05001202{
Nikolas Klauser9806f452022-10-12 15:45:09 +02001203 return __builtin_fmal(__x, __y, __z);
Ilya Tokarc3abffb2021-02-10 13:05:19 -05001204}
Richard Smith081bb592015-10-08 20:40:34 +00001205
1206template <class _A1, class _A2, class _A3>
Nikolas Klauser4956e722022-10-12 15:41:22 +02001207inline _LIBCPP_HIDE_FROM_ABI
Louis Dionne9ce598d2021-09-08 09:14:43 -04001208typename std::__enable_if_t
Richard Smith081bb592015-10-08 20:40:34 +00001209<
1210 std::is_arithmetic<_A1>::value &&
1211 std::is_arithmetic<_A2>::value &&
1212 std::is_arithmetic<_A3>::value,
1213 std::__promote<_A1, _A2, _A3>
1214>::type
Nikolas Klauser9806f452022-10-12 15:45:09 +02001215fma(_A1 __x, _A2 __y, _A3 __z) _NOEXCEPT
Richard Smith081bb592015-10-08 20:40:34 +00001216{
1217 typedef typename std::__promote<_A1, _A2, _A3>::type __result_type;
Eric Fiselier3906a132019-06-23 20:28:29 +00001218 static_assert((!(std::_IsSame<_A1, __result_type>::value &&
1219 std::_IsSame<_A2, __result_type>::value &&
1220 std::_IsSame<_A3, __result_type>::value)), "");
Nikolas Klauser9806f452022-10-12 15:45:09 +02001221 return __builtin_fma((__result_type)__x, (__result_type)__y, (__result_type)__z);
Richard Smith081bb592015-10-08 20:40:34 +00001222}
1223
1224// fmax
1225
Nikolas Klauser04005952022-10-21 01:41:22 +02001226inline _LIBCPP_HIDE_FROM_ABI float fmax(float __x, float __y) _NOEXCEPT {return __builtin_fmaxf(__x, __y);}
Nikolas Klauser52399652022-11-01 22:29:57 +01001227
1228template <class = int>
1229_LIBCPP_HIDE_FROM_ABI double fmax(double __x, double __y) _NOEXCEPT {
1230 return __builtin_fmax(__x, __y);
1231}
1232
Nikolas Klauser04005952022-10-21 01:41:22 +02001233inline _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 +00001234
1235template <class _A1, class _A2>
Nikolas Klauser4956e722022-10-12 15:41:22 +02001236inline _LIBCPP_HIDE_FROM_ABI
Louis Dionne9ce598d2021-09-08 09:14:43 -04001237typename std::__enable_if_t
Richard Smith081bb592015-10-08 20:40:34 +00001238<
1239 std::is_arithmetic<_A1>::value &&
1240 std::is_arithmetic<_A2>::value,
1241 std::__promote<_A1, _A2>
1242>::type
Nikolas Klauser9806f452022-10-12 15:45:09 +02001243fmax(_A1 __x, _A2 __y) _NOEXCEPT
Richard Smith081bb592015-10-08 20:40:34 +00001244{
1245 typedef typename std::__promote<_A1, _A2>::type __result_type;
Eric Fiselier3906a132019-06-23 20:28:29 +00001246 static_assert((!(std::_IsSame<_A1, __result_type>::value &&
1247 std::_IsSame<_A2, __result_type>::value)), "");
Nikolas Klauser9806f452022-10-12 15:45:09 +02001248 return ::fmax((__result_type)__x, (__result_type)__y);
Richard Smith081bb592015-10-08 20:40:34 +00001249}
1250
1251// fmin
1252
Nikolas Klauser04005952022-10-21 01:41:22 +02001253inline _LIBCPP_HIDE_FROM_ABI float fmin(float __x, float __y) _NOEXCEPT {return __builtin_fminf(__x, __y);}
Nikolas Klauser52399652022-11-01 22:29:57 +01001254
1255template <class = int>
1256_LIBCPP_HIDE_FROM_ABI double fmin(double __x, double __y) _NOEXCEPT {
1257 return __builtin_fmin(__x, __y);
1258}
1259
Nikolas Klauser04005952022-10-21 01:41:22 +02001260inline _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 +00001261
1262template <class _A1, class _A2>
Nikolas Klauser4956e722022-10-12 15:41:22 +02001263inline _LIBCPP_HIDE_FROM_ABI
Louis Dionne9ce598d2021-09-08 09:14:43 -04001264typename std::__enable_if_t
Richard Smith081bb592015-10-08 20:40:34 +00001265<
1266 std::is_arithmetic<_A1>::value &&
1267 std::is_arithmetic<_A2>::value,
1268 std::__promote<_A1, _A2>
1269>::type
Nikolas Klauser9806f452022-10-12 15:45:09 +02001270fmin(_A1 __x, _A2 __y) _NOEXCEPT
Richard Smith081bb592015-10-08 20:40:34 +00001271{
1272 typedef typename std::__promote<_A1, _A2>::type __result_type;
Eric Fiselier3906a132019-06-23 20:28:29 +00001273 static_assert((!(std::_IsSame<_A1, __result_type>::value &&
1274 std::_IsSame<_A2, __result_type>::value)), "");
Nikolas Klauser9806f452022-10-12 15:45:09 +02001275 return ::fmin((__result_type)__x, (__result_type)__y);
Richard Smith081bb592015-10-08 20:40:34 +00001276}
1277
1278// hypot
1279
Nikolas Klauser04005952022-10-21 01:41:22 +02001280inline _LIBCPP_HIDE_FROM_ABI float hypot(float __x, float __y) _NOEXCEPT {return __builtin_hypotf(__x, __y);}
Nikolas Klauser52399652022-11-01 22:29:57 +01001281
1282template <class = int>
1283_LIBCPP_HIDE_FROM_ABI double hypot(double __x, double __y) _NOEXCEPT {
1284 return __builtin_hypot(__x, __y);
1285}
1286
Nikolas Klauser04005952022-10-21 01:41:22 +02001287inline _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 +00001288
1289template <class _A1, class _A2>
Nikolas Klauser4956e722022-10-12 15:41:22 +02001290inline _LIBCPP_HIDE_FROM_ABI
Louis Dionne9ce598d2021-09-08 09:14:43 -04001291typename std::__enable_if_t
Richard Smith081bb592015-10-08 20:40:34 +00001292<
1293 std::is_arithmetic<_A1>::value &&
1294 std::is_arithmetic<_A2>::value,
1295 std::__promote<_A1, _A2>
1296>::type
Nikolas Klauser9806f452022-10-12 15:45:09 +02001297hypot(_A1 __x, _A2 __y) _NOEXCEPT
Richard Smith081bb592015-10-08 20:40:34 +00001298{
1299 typedef typename std::__promote<_A1, _A2>::type __result_type;
Eric Fiselier3906a132019-06-23 20:28:29 +00001300 static_assert((!(std::_IsSame<_A1, __result_type>::value &&
1301 std::_IsSame<_A2, __result_type>::value)), "");
Nikolas Klauser9806f452022-10-12 15:45:09 +02001302 return ::hypot((__result_type)__x, (__result_type)__y);
Richard Smith081bb592015-10-08 20:40:34 +00001303}
1304
1305// ilogb
1306
Nikolas Klauser04005952022-10-21 01:41:22 +02001307inline _LIBCPP_HIDE_FROM_ABI int ilogb(float __x) _NOEXCEPT {return __builtin_ilogbf(__x);}
Nikolas Klauser52399652022-11-01 22:29:57 +01001308
1309template <class = int>
1310_LIBCPP_HIDE_FROM_ABI double ilogb(double __x) _NOEXCEPT {
1311 return __builtin_ilogb(__x);
1312}
1313
Nikolas Klauser04005952022-10-21 01:41:22 +02001314inline _LIBCPP_HIDE_FROM_ABI int ilogb(long double __x) _NOEXCEPT {return __builtin_ilogbl(__x);}
Richard Smith081bb592015-10-08 20:40:34 +00001315
1316template <class _A1>
Nikolas Klauser4956e722022-10-12 15:41:22 +02001317inline _LIBCPP_HIDE_FROM_ABI
Richard Smith081bb592015-10-08 20:40:34 +00001318typename std::enable_if<std::is_integral<_A1>::value, int>::type
Nikolas Klauser04005952022-10-21 01:41:22 +02001319ilogb(_A1 __x) _NOEXCEPT {return __builtin_ilogb((double)__x);}
Richard Smith081bb592015-10-08 20:40:34 +00001320
1321// lgamma
1322
Nikolas Klauser04005952022-10-21 01:41:22 +02001323inline _LIBCPP_HIDE_FROM_ABI float lgamma(float __x) _NOEXCEPT {return __builtin_lgammaf(__x);}
Nikolas Klauser52399652022-11-01 22:29:57 +01001324
1325template <class = int>
1326_LIBCPP_HIDE_FROM_ABI double lgamma(double __x) _NOEXCEPT {
1327 return __builtin_lgamma(__x);
1328}
1329
Nikolas Klauser04005952022-10-21 01:41:22 +02001330inline _LIBCPP_HIDE_FROM_ABI long double lgamma(long double __x) _NOEXCEPT {return __builtin_lgammal(__x);}
Richard Smith081bb592015-10-08 20:40:34 +00001331
1332template <class _A1>
Nikolas Klauser4956e722022-10-12 15:41:22 +02001333inline _LIBCPP_HIDE_FROM_ABI
Richard Smith081bb592015-10-08 20:40:34 +00001334typename std::enable_if<std::is_integral<_A1>::value, double>::type
Nikolas Klauser04005952022-10-21 01:41:22 +02001335lgamma(_A1 __x) _NOEXCEPT {return __builtin_lgamma((double)__x);}
Richard Smith081bb592015-10-08 20:40:34 +00001336
1337// llrint
1338
Nikolas Klauser9806f452022-10-12 15:45:09 +02001339inline _LIBCPP_HIDE_FROM_ABI long long llrint(float __x) _NOEXCEPT
Ilya Tokarc3abffb2021-02-10 13:05:19 -05001340{
Nikolas Klauser9806f452022-10-12 15:45:09 +02001341 return __builtin_llrintf(__x);
Ilya Tokarc3abffb2021-02-10 13:05:19 -05001342}
Nikolas Klauser52399652022-11-01 22:29:57 +01001343
1344template <class = int>
1345_LIBCPP_HIDE_FROM_ABI long long llrint(double __x) _NOEXCEPT {
1346 return __builtin_llrint(__x);
1347}
1348
Nikolas Klauser9806f452022-10-12 15:45:09 +02001349inline _LIBCPP_HIDE_FROM_ABI long long llrint(long double __x) _NOEXCEPT
Ilya Tokarc3abffb2021-02-10 13:05:19 -05001350{
Nikolas Klauser9806f452022-10-12 15:45:09 +02001351 return __builtin_llrintl(__x);
Ilya Tokarc3abffb2021-02-10 13:05:19 -05001352}
Richard Smith081bb592015-10-08 20:40:34 +00001353
1354template <class _A1>
Nikolas Klauser4956e722022-10-12 15:41:22 +02001355inline _LIBCPP_HIDE_FROM_ABI
Richard Smith081bb592015-10-08 20:40:34 +00001356typename std::enable_if<std::is_integral<_A1>::value, long long>::type
Nikolas Klauser9806f452022-10-12 15:45:09 +02001357llrint(_A1 __x) _NOEXCEPT
Ilya Tokarc3abffb2021-02-10 13:05:19 -05001358{
Nikolas Klauser9806f452022-10-12 15:45:09 +02001359 return __builtin_llrint((double)__x);
Ilya Tokarc3abffb2021-02-10 13:05:19 -05001360}
Richard Smith081bb592015-10-08 20:40:34 +00001361
1362// llround
1363
Nikolas Klauser9806f452022-10-12 15:45:09 +02001364inline _LIBCPP_HIDE_FROM_ABI long long llround(float __x) _NOEXCEPT
Ilya Tokarc3abffb2021-02-10 13:05:19 -05001365{
Nikolas Klauser9806f452022-10-12 15:45:09 +02001366 return __builtin_llroundf(__x);
Ilya Tokarc3abffb2021-02-10 13:05:19 -05001367}
Nikolas Klauser52399652022-11-01 22:29:57 +01001368
1369template <class = int>
1370_LIBCPP_HIDE_FROM_ABI long long llround(double __x) _NOEXCEPT {
1371 return __builtin_llround(__x);
1372}
1373
Nikolas Klauser9806f452022-10-12 15:45:09 +02001374inline _LIBCPP_HIDE_FROM_ABI long long llround(long double __x) _NOEXCEPT
Ilya Tokarc3abffb2021-02-10 13:05:19 -05001375{
Nikolas Klauser9806f452022-10-12 15:45:09 +02001376 return __builtin_llroundl(__x);
Ilya Tokarc3abffb2021-02-10 13:05:19 -05001377}
Richard Smith081bb592015-10-08 20:40:34 +00001378
1379template <class _A1>
Nikolas Klauser4956e722022-10-12 15:41:22 +02001380inline _LIBCPP_HIDE_FROM_ABI
Richard Smith081bb592015-10-08 20:40:34 +00001381typename std::enable_if<std::is_integral<_A1>::value, long long>::type
Nikolas Klauser9806f452022-10-12 15:45:09 +02001382llround(_A1 __x) _NOEXCEPT
Ilya Tokarc3abffb2021-02-10 13:05:19 -05001383{
Nikolas Klauser9806f452022-10-12 15:45:09 +02001384 return __builtin_llround((double)__x);
Ilya Tokarc3abffb2021-02-10 13:05:19 -05001385}
Richard Smith081bb592015-10-08 20:40:34 +00001386
1387// log1p
1388
Nikolas Klauser04005952022-10-21 01:41:22 +02001389inline _LIBCPP_HIDE_FROM_ABI float log1p(float __x) _NOEXCEPT {return __builtin_log1pf(__x);}
Nikolas Klauser52399652022-11-01 22:29:57 +01001390
1391template <class = int>
1392_LIBCPP_HIDE_FROM_ABI double log1p(double __x) _NOEXCEPT {
1393 return __builtin_log1p(__x);
1394}
1395
Nikolas Klauser04005952022-10-21 01:41:22 +02001396inline _LIBCPP_HIDE_FROM_ABI long double log1p(long double __x) _NOEXCEPT {return __builtin_log1pl(__x);}
Richard Smith081bb592015-10-08 20:40:34 +00001397
1398template <class _A1>
Nikolas Klauser4956e722022-10-12 15:41:22 +02001399inline _LIBCPP_HIDE_FROM_ABI
Richard Smith081bb592015-10-08 20:40:34 +00001400typename std::enable_if<std::is_integral<_A1>::value, double>::type
Nikolas Klauser04005952022-10-21 01:41:22 +02001401log1p(_A1 __x) _NOEXCEPT {return __builtin_log1p((double)__x);}
Richard Smith081bb592015-10-08 20:40:34 +00001402
1403// log2
1404
Nikolas Klauser04005952022-10-21 01:41:22 +02001405inline _LIBCPP_HIDE_FROM_ABI float log2(float __x) _NOEXCEPT {return __builtin_log2f(__x);}
Nikolas Klauser52399652022-11-01 22:29:57 +01001406
1407template <class = int>
1408_LIBCPP_HIDE_FROM_ABI double log2(double __x) _NOEXCEPT {
1409 return __builtin_log2(__x);
1410}
1411
Nikolas Klauser04005952022-10-21 01:41:22 +02001412inline _LIBCPP_HIDE_FROM_ABI long double log2(long double __x) _NOEXCEPT {return __builtin_log2l(__x);}
Richard Smith081bb592015-10-08 20:40:34 +00001413
1414template <class _A1>
Nikolas Klauser4956e722022-10-12 15:41:22 +02001415inline _LIBCPP_HIDE_FROM_ABI
Richard Smith081bb592015-10-08 20:40:34 +00001416typename std::enable_if<std::is_integral<_A1>::value, double>::type
Nikolas Klauser04005952022-10-21 01:41:22 +02001417log2(_A1 __x) _NOEXCEPT {return __builtin_log2((double)__x);}
Richard Smith081bb592015-10-08 20:40:34 +00001418
1419// logb
1420
Nikolas Klauser04005952022-10-21 01:41:22 +02001421inline _LIBCPP_HIDE_FROM_ABI float logb(float __x) _NOEXCEPT {return __builtin_logbf(__x);}
Nikolas Klauser52399652022-11-01 22:29:57 +01001422
1423template <class = int>
1424_LIBCPP_HIDE_FROM_ABI double logb(double __x) _NOEXCEPT {
1425 return __builtin_logb(__x);
1426}
1427
Nikolas Klauser04005952022-10-21 01:41:22 +02001428inline _LIBCPP_HIDE_FROM_ABI long double logb(long double __x) _NOEXCEPT {return __builtin_logbl(__x);}
Richard Smith081bb592015-10-08 20:40:34 +00001429
1430template <class _A1>
Nikolas Klauser4956e722022-10-12 15:41:22 +02001431inline _LIBCPP_HIDE_FROM_ABI
Richard Smith081bb592015-10-08 20:40:34 +00001432typename std::enable_if<std::is_integral<_A1>::value, double>::type
Nikolas Klauser04005952022-10-21 01:41:22 +02001433logb(_A1 __x) _NOEXCEPT {return __builtin_logb((double)__x);}
Richard Smith081bb592015-10-08 20:40:34 +00001434
1435// lrint
1436
Nikolas Klauser9806f452022-10-12 15:45:09 +02001437inline _LIBCPP_HIDE_FROM_ABI long lrint(float __x) _NOEXCEPT
Ilya Tokarc3abffb2021-02-10 13:05:19 -05001438{
Nikolas Klauser9806f452022-10-12 15:45:09 +02001439 return __builtin_lrintf(__x);
Ilya Tokarc3abffb2021-02-10 13:05:19 -05001440}
Nikolas Klauser52399652022-11-01 22:29:57 +01001441
1442template <class = int>
1443_LIBCPP_HIDE_FROM_ABI long lrint(double __x) _NOEXCEPT {
1444 return __builtin_lrint(__x);
1445}
1446
Nikolas Klauser9806f452022-10-12 15:45:09 +02001447inline _LIBCPP_HIDE_FROM_ABI long lrint(long double __x) _NOEXCEPT
Ilya Tokarc3abffb2021-02-10 13:05:19 -05001448{
Nikolas Klauser9806f452022-10-12 15:45:09 +02001449 return __builtin_lrintl(__x);
Ilya Tokarc3abffb2021-02-10 13:05:19 -05001450}
Richard Smith081bb592015-10-08 20:40:34 +00001451
1452template <class _A1>
Nikolas Klauser4956e722022-10-12 15:41:22 +02001453inline _LIBCPP_HIDE_FROM_ABI
Richard Smith081bb592015-10-08 20:40:34 +00001454typename std::enable_if<std::is_integral<_A1>::value, long>::type
Nikolas Klauser9806f452022-10-12 15:45:09 +02001455lrint(_A1 __x) _NOEXCEPT
Ilya Tokarc3abffb2021-02-10 13:05:19 -05001456{
Nikolas Klauser9806f452022-10-12 15:45:09 +02001457 return __builtin_lrint((double)__x);
Ilya Tokarc3abffb2021-02-10 13:05:19 -05001458}
Richard Smith081bb592015-10-08 20:40:34 +00001459
1460// lround
1461
Nikolas Klauser9806f452022-10-12 15:45:09 +02001462inline _LIBCPP_HIDE_FROM_ABI long lround(float __x) _NOEXCEPT
Ilya Tokarc3abffb2021-02-10 13:05:19 -05001463{
Nikolas Klauser9806f452022-10-12 15:45:09 +02001464 return __builtin_lroundf(__x);
Ilya Tokarc3abffb2021-02-10 13:05:19 -05001465}
Nikolas Klauser52399652022-11-01 22:29:57 +01001466
1467template <class = int>
1468_LIBCPP_HIDE_FROM_ABI long lround(double __x) _NOEXCEPT {
1469 return __builtin_lround(__x);
1470}
1471
Nikolas Klauser9806f452022-10-12 15:45:09 +02001472inline _LIBCPP_HIDE_FROM_ABI long lround(long double __x) _NOEXCEPT
Ilya Tokarc3abffb2021-02-10 13:05:19 -05001473{
Nikolas Klauser9806f452022-10-12 15:45:09 +02001474 return __builtin_lroundl(__x);
Ilya Tokarc3abffb2021-02-10 13:05:19 -05001475}
Richard Smith081bb592015-10-08 20:40:34 +00001476
1477template <class _A1>
Nikolas Klauser4956e722022-10-12 15:41:22 +02001478inline _LIBCPP_HIDE_FROM_ABI
Richard Smith081bb592015-10-08 20:40:34 +00001479typename std::enable_if<std::is_integral<_A1>::value, long>::type
Nikolas Klauser9806f452022-10-12 15:45:09 +02001480lround(_A1 __x) _NOEXCEPT
Ilya Tokarc3abffb2021-02-10 13:05:19 -05001481{
Nikolas Klauser9806f452022-10-12 15:45:09 +02001482 return __builtin_lround((double)__x);
Ilya Tokarc3abffb2021-02-10 13:05:19 -05001483}
Richard Smith081bb592015-10-08 20:40:34 +00001484
1485// nan
1486
1487// nearbyint
1488
Nikolas Klauser04005952022-10-21 01:41:22 +02001489inline _LIBCPP_HIDE_FROM_ABI float nearbyint(float __x) _NOEXCEPT {return __builtin_nearbyintf(__x);}
Nikolas Klauser52399652022-11-01 22:29:57 +01001490
1491template <class = int>
1492_LIBCPP_HIDE_FROM_ABI double nearbyint(double __x) _NOEXCEPT {
1493 return __builtin_nearbyint(__x);
1494}
1495
Nikolas Klauser04005952022-10-21 01:41:22 +02001496inline _LIBCPP_HIDE_FROM_ABI long double nearbyint(long double __x) _NOEXCEPT {return __builtin_nearbyintl(__x);}
Richard Smith081bb592015-10-08 20:40:34 +00001497
1498template <class _A1>
Nikolas Klauser4956e722022-10-12 15:41:22 +02001499inline _LIBCPP_HIDE_FROM_ABI
Richard Smith081bb592015-10-08 20:40:34 +00001500typename std::enable_if<std::is_integral<_A1>::value, double>::type
Nikolas Klauser04005952022-10-21 01:41:22 +02001501nearbyint(_A1 __x) _NOEXCEPT {return __builtin_nearbyint((double)__x);}
Richard Smith081bb592015-10-08 20:40:34 +00001502
1503// nextafter
1504
Nikolas Klauser04005952022-10-21 01:41:22 +02001505inline _LIBCPP_HIDE_FROM_ABI float nextafter(float __x, float __y) _NOEXCEPT {return __builtin_nextafterf(__x, __y);}
Nikolas Klauser52399652022-11-01 22:29:57 +01001506
1507template <class = int>
1508_LIBCPP_HIDE_FROM_ABI double nextafter(double __x, double __y) _NOEXCEPT {
1509 return __builtin_nextafter(__x, __y);
1510}
1511
Nikolas Klauser04005952022-10-21 01:41:22 +02001512inline _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 +00001513
1514template <class _A1, class _A2>
Nikolas Klauser4956e722022-10-12 15:41:22 +02001515inline _LIBCPP_HIDE_FROM_ABI
Louis Dionne9ce598d2021-09-08 09:14:43 -04001516typename std::__enable_if_t
Richard Smith081bb592015-10-08 20:40:34 +00001517<
1518 std::is_arithmetic<_A1>::value &&
1519 std::is_arithmetic<_A2>::value,
1520 std::__promote<_A1, _A2>
1521>::type
Nikolas Klauser9806f452022-10-12 15:45:09 +02001522nextafter(_A1 __x, _A2 __y) _NOEXCEPT
Richard Smith081bb592015-10-08 20:40:34 +00001523{
1524 typedef typename std::__promote<_A1, _A2>::type __result_type;
Eric Fiselier3906a132019-06-23 20:28:29 +00001525 static_assert((!(std::_IsSame<_A1, __result_type>::value &&
1526 std::_IsSame<_A2, __result_type>::value)), "");
Nikolas Klauser9806f452022-10-12 15:45:09 +02001527 return ::nextafter((__result_type)__x, (__result_type)__y);
Richard Smith081bb592015-10-08 20:40:34 +00001528}
1529
1530// nexttoward
1531
Nikolas Klauser04005952022-10-21 01:41:22 +02001532inline _LIBCPP_HIDE_FROM_ABI float nexttoward(float __x, long double __y) _NOEXCEPT {return __builtin_nexttowardf(__x, __y);}
Nikolas Klauser52399652022-11-01 22:29:57 +01001533
1534template <class = int>
1535_LIBCPP_HIDE_FROM_ABI double nexttoward(double __x, long double __y) _NOEXCEPT {
1536 return __builtin_nexttoward(__x, __y);
1537}
1538
Nikolas Klauser04005952022-10-21 01:41:22 +02001539inline _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 +00001540
1541template <class _A1>
Nikolas Klauser4956e722022-10-12 15:41:22 +02001542inline _LIBCPP_HIDE_FROM_ABI
Richard Smith081bb592015-10-08 20:40:34 +00001543typename std::enable_if<std::is_integral<_A1>::value, double>::type
Nikolas Klauser04005952022-10-21 01:41:22 +02001544nexttoward(_A1 __x, long double __y) _NOEXCEPT {return __builtin_nexttoward((double)__x, __y);}
Richard Smith081bb592015-10-08 20:40:34 +00001545
1546// remainder
1547
Nikolas Klauser04005952022-10-21 01:41:22 +02001548inline _LIBCPP_HIDE_FROM_ABI float remainder(float __x, float __y) _NOEXCEPT {return __builtin_remainderf(__x, __y);}
Nikolas Klauser52399652022-11-01 22:29:57 +01001549
1550template <class = int>
1551_LIBCPP_HIDE_FROM_ABI double remainder(double __x, double __y) _NOEXCEPT {
1552 return __builtin_remainder(__x, __y);
1553}
1554
Nikolas Klauser04005952022-10-21 01:41:22 +02001555inline _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 +00001556
1557template <class _A1, class _A2>
Nikolas Klauser4956e722022-10-12 15:41:22 +02001558inline _LIBCPP_HIDE_FROM_ABI
Louis Dionne9ce598d2021-09-08 09:14:43 -04001559typename std::__enable_if_t
Richard Smith081bb592015-10-08 20:40:34 +00001560<
1561 std::is_arithmetic<_A1>::value &&
1562 std::is_arithmetic<_A2>::value,
1563 std::__promote<_A1, _A2>
1564>::type
Nikolas Klauser9806f452022-10-12 15:45:09 +02001565remainder(_A1 __x, _A2 __y) _NOEXCEPT
Richard Smith081bb592015-10-08 20:40:34 +00001566{
1567 typedef typename std::__promote<_A1, _A2>::type __result_type;
Eric Fiselier3906a132019-06-23 20:28:29 +00001568 static_assert((!(std::_IsSame<_A1, __result_type>::value &&
1569 std::_IsSame<_A2, __result_type>::value)), "");
Nikolas Klauser9806f452022-10-12 15:45:09 +02001570 return ::remainder((__result_type)__x, (__result_type)__y);
Richard Smith081bb592015-10-08 20:40:34 +00001571}
1572
1573// remquo
1574
Nikolas Klauser04005952022-10-21 01:41:22 +02001575inline _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 +01001576
1577template <class = int>
1578_LIBCPP_HIDE_FROM_ABI double remquo(double __x, double __y, int* __z) _NOEXCEPT {
1579 return __builtin_remquo(__x, __y, __z);
1580}
1581
Nikolas Klauser04005952022-10-21 01:41:22 +02001582inline _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 +00001583
1584template <class _A1, class _A2>
Nikolas Klauser4956e722022-10-12 15:41:22 +02001585inline _LIBCPP_HIDE_FROM_ABI
Louis Dionne9ce598d2021-09-08 09:14:43 -04001586typename std::__enable_if_t
Richard Smith081bb592015-10-08 20:40:34 +00001587<
1588 std::is_arithmetic<_A1>::value &&
1589 std::is_arithmetic<_A2>::value,
1590 std::__promote<_A1, _A2>
1591>::type
Nikolas Klauser9806f452022-10-12 15:45:09 +02001592remquo(_A1 __x, _A2 __y, int* __z) _NOEXCEPT
Richard Smith081bb592015-10-08 20:40:34 +00001593{
1594 typedef typename std::__promote<_A1, _A2>::type __result_type;
Eric Fiselier3906a132019-06-23 20:28:29 +00001595 static_assert((!(std::_IsSame<_A1, __result_type>::value &&
1596 std::_IsSame<_A2, __result_type>::value)), "");
Nikolas Klauser9806f452022-10-12 15:45:09 +02001597 return ::remquo((__result_type)__x, (__result_type)__y, __z);
Richard Smith081bb592015-10-08 20:40:34 +00001598}
1599
1600// rint
1601
Nikolas Klauser9806f452022-10-12 15:45:09 +02001602inline _LIBCPP_HIDE_FROM_ABI float rint(float __x) _NOEXCEPT
Ilya Tokarc3abffb2021-02-10 13:05:19 -05001603{
Nikolas Klauser9806f452022-10-12 15:45:09 +02001604 return __builtin_rintf(__x);
Ilya Tokarc3abffb2021-02-10 13:05:19 -05001605}
Nikolas Klauser52399652022-11-01 22:29:57 +01001606
1607template <class = int>
1608_LIBCPP_HIDE_FROM_ABI double rint(double __x) _NOEXCEPT {
1609 return __builtin_rint(__x);
1610}
1611
Nikolas Klauser9806f452022-10-12 15:45:09 +02001612inline _LIBCPP_HIDE_FROM_ABI long double rint(long double __x) _NOEXCEPT
Ilya Tokarc3abffb2021-02-10 13:05:19 -05001613{
Nikolas Klauser9806f452022-10-12 15:45:09 +02001614 return __builtin_rintl(__x);
Ilya Tokarc3abffb2021-02-10 13:05:19 -05001615}
Richard Smith081bb592015-10-08 20:40:34 +00001616
1617template <class _A1>
Nikolas Klauser4956e722022-10-12 15:41:22 +02001618inline _LIBCPP_HIDE_FROM_ABI
Richard Smith081bb592015-10-08 20:40:34 +00001619typename std::enable_if<std::is_integral<_A1>::value, double>::type
Nikolas Klauser9806f452022-10-12 15:45:09 +02001620rint(_A1 __x) _NOEXCEPT
Ilya Tokarc3abffb2021-02-10 13:05:19 -05001621{
Nikolas Klauser9806f452022-10-12 15:45:09 +02001622 return __builtin_rint((double)__x);
Ilya Tokarc3abffb2021-02-10 13:05:19 -05001623}
Richard Smith081bb592015-10-08 20:40:34 +00001624
1625// round
1626
Nikolas Klauser9806f452022-10-12 15:45:09 +02001627inline _LIBCPP_HIDE_FROM_ABI float round(float __x) _NOEXCEPT
Ilya Tokarc3abffb2021-02-10 13:05:19 -05001628{
Nikolas Klauser9806f452022-10-12 15:45:09 +02001629 return __builtin_round(__x);
Ilya Tokarc3abffb2021-02-10 13:05:19 -05001630}
Nikolas Klauser52399652022-11-01 22:29:57 +01001631
1632template <class = int>
1633_LIBCPP_HIDE_FROM_ABI double round(double __x) _NOEXCEPT {
1634 return __builtin_round(__x);
1635}
1636
Nikolas Klauser9806f452022-10-12 15:45:09 +02001637inline _LIBCPP_HIDE_FROM_ABI long double round(long double __x) _NOEXCEPT
Ilya Tokarc3abffb2021-02-10 13:05:19 -05001638{
Nikolas Klauser9806f452022-10-12 15:45:09 +02001639 return __builtin_roundl(__x);
Ilya Tokarc3abffb2021-02-10 13:05:19 -05001640}
Richard Smith081bb592015-10-08 20:40:34 +00001641
1642template <class _A1>
Nikolas Klauser4956e722022-10-12 15:41:22 +02001643inline _LIBCPP_HIDE_FROM_ABI
Richard Smith081bb592015-10-08 20:40:34 +00001644typename std::enable_if<std::is_integral<_A1>::value, double>::type
Nikolas Klauser9806f452022-10-12 15:45:09 +02001645round(_A1 __x) _NOEXCEPT
Ilya Tokarc3abffb2021-02-10 13:05:19 -05001646{
Nikolas Klauser9806f452022-10-12 15:45:09 +02001647 return __builtin_round((double)__x);
Ilya Tokarc3abffb2021-02-10 13:05:19 -05001648}
Richard Smith081bb592015-10-08 20:40:34 +00001649
1650// scalbln
1651
Nikolas Klauser04005952022-10-21 01:41:22 +02001652inline _LIBCPP_HIDE_FROM_ABI float scalbln(float __x, long __y) _NOEXCEPT {return __builtin_scalblnf(__x, __y);}
Nikolas Klauser52399652022-11-01 22:29:57 +01001653
1654template <class = int>
1655_LIBCPP_HIDE_FROM_ABI double scalbln(double __x, long __y) _NOEXCEPT {
1656 return __builtin_scalbln(__x, __y);
1657}
1658
Nikolas Klauser04005952022-10-21 01:41:22 +02001659inline _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 +00001660
1661template <class _A1>
Nikolas Klauser4956e722022-10-12 15:41:22 +02001662inline _LIBCPP_HIDE_FROM_ABI
Richard Smith081bb592015-10-08 20:40:34 +00001663typename std::enable_if<std::is_integral<_A1>::value, double>::type
Nikolas Klauser04005952022-10-21 01:41:22 +02001664scalbln(_A1 __x, long __y) _NOEXCEPT {return __builtin_scalbln((double)__x, __y);}
Richard Smith081bb592015-10-08 20:40:34 +00001665
1666// scalbn
1667
Nikolas Klauser04005952022-10-21 01:41:22 +02001668inline _LIBCPP_HIDE_FROM_ABI float scalbn(float __x, int __y) _NOEXCEPT {return __builtin_scalbnf(__x, __y);}
Nikolas Klauser52399652022-11-01 22:29:57 +01001669
1670template <class = int>
1671_LIBCPP_HIDE_FROM_ABI double scalbn(double __x, int __y) _NOEXCEPT {
1672 return __builtin_scalbn(__x, __y);
1673}
1674
Nikolas Klauser04005952022-10-21 01:41:22 +02001675inline _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 +00001676
1677template <class _A1>
Nikolas Klauser4956e722022-10-12 15:41:22 +02001678inline _LIBCPP_HIDE_FROM_ABI
Richard Smith081bb592015-10-08 20:40:34 +00001679typename std::enable_if<std::is_integral<_A1>::value, double>::type
Nikolas Klauser04005952022-10-21 01:41:22 +02001680scalbn(_A1 __x, int __y) _NOEXCEPT {return __builtin_scalbn((double)__x, __y);}
Richard Smith081bb592015-10-08 20:40:34 +00001681
1682// tgamma
1683
Nikolas Klauser04005952022-10-21 01:41:22 +02001684inline _LIBCPP_HIDE_FROM_ABI float tgamma(float __x) _NOEXCEPT {return __builtin_tgammaf(__x);}
Nikolas Klauser52399652022-11-01 22:29:57 +01001685
1686template <class = int>
1687_LIBCPP_HIDE_FROM_ABI double tgamma(double __x) _NOEXCEPT {
1688 return __builtin_tgamma(__x);
1689}
1690
Nikolas Klauser04005952022-10-21 01:41:22 +02001691inline _LIBCPP_HIDE_FROM_ABI long double tgamma(long double __x) _NOEXCEPT {return __builtin_tgammal(__x);}
Richard Smith081bb592015-10-08 20:40:34 +00001692
1693template <class _A1>
Nikolas Klauser4956e722022-10-12 15:41:22 +02001694inline _LIBCPP_HIDE_FROM_ABI
Richard Smith081bb592015-10-08 20:40:34 +00001695typename std::enable_if<std::is_integral<_A1>::value, double>::type
Nikolas Klauser04005952022-10-21 01:41:22 +02001696tgamma(_A1 __x) _NOEXCEPT {return __builtin_tgamma((double)__x);}
Richard Smith081bb592015-10-08 20:40:34 +00001697
1698// trunc
1699
Nikolas Klauser9806f452022-10-12 15:45:09 +02001700inline _LIBCPP_HIDE_FROM_ABI float trunc(float __x) _NOEXCEPT
Ilya Tokarc3abffb2021-02-10 13:05:19 -05001701{
Nikolas Klauser9806f452022-10-12 15:45:09 +02001702 return __builtin_trunc(__x);
Ilya Tokarc3abffb2021-02-10 13:05:19 -05001703}
Nikolas Klauser52399652022-11-01 22:29:57 +01001704
1705template <class = int>
1706_LIBCPP_HIDE_FROM_ABI double trunc(double __x) _NOEXCEPT {
1707 return __builtin_trunc(__x);
1708}
1709
Nikolas Klauser9806f452022-10-12 15:45:09 +02001710inline _LIBCPP_HIDE_FROM_ABI long double trunc(long double __x) _NOEXCEPT
Ilya Tokarc3abffb2021-02-10 13:05:19 -05001711{
Nikolas Klauser9806f452022-10-12 15:45:09 +02001712 return __builtin_truncl(__x);
Ilya Tokarc3abffb2021-02-10 13:05:19 -05001713}
Richard Smith081bb592015-10-08 20:40:34 +00001714
1715template <class _A1>
Nikolas Klauser4956e722022-10-12 15:41:22 +02001716inline _LIBCPP_HIDE_FROM_ABI
Richard Smith081bb592015-10-08 20:40:34 +00001717typename std::enable_if<std::is_integral<_A1>::value, double>::type
Nikolas Klauser9806f452022-10-12 15:45:09 +02001718trunc(_A1 __x) _NOEXCEPT
Ilya Tokarc3abffb2021-02-10 13:05:19 -05001719{
Nikolas Klauser9806f452022-10-12 15:45:09 +02001720 return __builtin_trunc((double)__x);
Ilya Tokarc3abffb2021-02-10 13:05:19 -05001721}
Richard Smith081bb592015-10-08 20:40:34 +00001722
Richard Smith081bb592015-10-08 20:40:34 +00001723} // extern "C++"
1724
1725#endif // __cplusplus
1726
Mikhail Maltsev34b4f972018-02-22 09:34:08 +00001727#else // _LIBCPP_MATH_H
1728
1729// This include lives outside the header guard in order to support an MSVC
1730// extension which allows users to do:
1731//
1732// #define _USE_MATH_DEFINES
1733// #include <math.h>
1734//
1735// and receive the definitions of mathematical constants, even if <math.h>
1736// has previously been included.
1737#if defined(_LIBCPP_MSVCRT) && defined(_USE_MATH_DEFINES)
1738#include_next <math.h>
1739#endif
1740
Louis Dionne2b1ceaa2021-04-20 12:03:32 -04001741#endif // _LIBCPP_MATH_H