blob: ac55983bb0169080b4d39a42a3b8deb5a7aaa90d [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 Klauser6c8f7122022-07-24 16:03:12 +0200310#include <__type_traits/promote.h>
Arthur O'Dwyer65077c02022-01-07 09:45:05 -0500311#include <limits>
Eric Fiselier6c9e1a72020-02-15 18:55:07 -0500312#include <stdlib.h>
Richard Smith081bb592015-10-08 20:40:34 +0000313#include <type_traits>
314
Nikolas Klauserae1fbc42022-11-04 20:19:20 +0100315
316# ifdef fpclassify
317# undef fpclassify
318# endif
Richard Smith081bb592015-10-08 20:40:34 +0000319
Nikolas Klauser9a97dd72022-11-04 16:36:34 +0100320# ifdef signbit
Nikolas Klauser9a97dd72022-11-04 16:36:34 +0100321# undef signbit
Nikolas Klauserae1fbc42022-11-04 20:19:20 +0100322# endif
323
324# ifdef isfinite
325# undef isfinite
326# endif
327
328# ifdef isinf
329# undef isinf
330# endif
331
332# ifdef isnan
333# undef isnan
334# endif
335
336# ifdef isnormal
337# undef isnormal
338# endif
339
340# ifdef isgreater
341# undef isgreater
342# endif
343
344# ifdef isgreaterequal
345# undef isgreaterequal
346# endif
347
348# ifdef isless
349# undef isless
350# endif
351
352# ifdef islessequal
353# undef islessequal
354# endif
355
356# ifdef islessgreater
357# undef islessgreater
358# endif
359
360# ifdef isunordered
361# undef isunordered
362# endif
363
364// signbit
Richard Smith081bb592015-10-08 20:40:34 +0000365
Nikolas Klausere96070f2022-11-04 20:08:56 +0100366template <class _A1, std::__enable_if_t<std::is_floating_point<_A1>::value, int> = 0>
367inline _LIBCPP_HIDE_FROM_ABI bool signbit(_A1 __x) _NOEXCEPT {
Nikolas Klauser25fbc472022-11-04 16:56:51 +0100368 return __builtin_signbit(__x);
Richard Smith081bb592015-10-08 20:40:34 +0000369}
370
Nikolas Klausere96070f2022-11-04 20:08:56 +0100371template <class _A1, std::__enable_if_t<std::is_integral<_A1>::value && std::is_signed<_A1>::value, int> = 0>
372inline _LIBCPP_HIDE_FROM_ABI bool signbit(_A1 __x) _NOEXCEPT {
Nikolas Klauser9a97dd72022-11-04 16:36:34 +0100373 return __x < 0;
374}
Duncan P. N. Exon Smith321d6bf2017-04-21 23:14:55 +0000375
Nikolas Klausere96070f2022-11-04 20:08:56 +0100376template <class _A1, std::__enable_if_t<std::is_integral<_A1>::value && !std::is_signed<_A1>::value, int> = 0>
377inline _LIBCPP_HIDE_FROM_ABI bool signbit(_A1) _NOEXCEPT {
Nikolas Klauser9a97dd72022-11-04 16:36:34 +0100378 return false;
379}
Duncan P. N. Exon Smith321d6bf2017-04-21 23:14:55 +0000380
Richard Smith081bb592015-10-08 20:40:34 +0000381// fpclassify
382
Nikolas Klausere96070f2022-11-04 20:08:56 +0100383template <class _A1, std::__enable_if_t<std::is_floating_point<_A1>::value, int> = 0>
384inline _LIBCPP_HIDE_FROM_ABI int fpclassify(_A1 __x) _NOEXCEPT {
Nikolas Klauser25fbc472022-11-04 16:56:51 +0100385 return __builtin_fpclassify(FP_NAN, FP_INFINITE, FP_NORMAL, FP_SUBNORMAL, FP_ZERO, __x);
Richard Smith081bb592015-10-08 20:40:34 +0000386}
387
Nikolas Klausere96070f2022-11-04 20:08:56 +0100388template <class _A1, std::__enable_if_t<std::is_integral<_A1>::value, int> = 0>
389inline _LIBCPP_HIDE_FROM_ABI int fpclassify(_A1 __x) _NOEXCEPT {
Nikolas Klauser9a97dd72022-11-04 16:36:34 +0100390 return __x == 0 ? FP_ZERO : FP_NORMAL;
391}
Duncan P. N. Exon Smith321d6bf2017-04-21 23:14:55 +0000392
Nikolas Klauserae1fbc42022-11-04 20:19:20 +0100393// The MSVC runtime already provides these functions as templates
394#ifndef _LIBCPP_MSVCRT
Richard Smith081bb592015-10-08 20:40:34 +0000395
Nikolas Klauserae1fbc42022-11-04 20:19:20 +0100396// isfinite
Richard Smith081bb592015-10-08 20:40:34 +0000397
Nikolas Klausere96070f2022-11-04 20:08:56 +0100398template <class _A1,
399 std::__enable_if_t<std::is_arithmetic<_A1>::value && std::numeric_limits<_A1>::has_infinity, int> = 0>
400inline _LIBCPP_HIDE_FROM_ABI bool isfinite(_A1 __x) _NOEXCEPT {
Nikolas Klauser25fbc472022-11-04 16:56:51 +0100401 return __builtin_isfinite((typename std::__promote<_A1>::type)__x);
Richard Smith081bb592015-10-08 20:40:34 +0000402}
403
Nikolas Klausere96070f2022-11-04 20:08:56 +0100404template <class _A1,
405 std::__enable_if_t<std::is_arithmetic<_A1>::value && !std::numeric_limits<_A1>::has_infinity, int> = 0>
406inline _LIBCPP_HIDE_FROM_ABI bool isfinite(_A1) _NOEXCEPT {
Nikolas Klauser9a97dd72022-11-04 16:36:34 +0100407 return true;
408}
Duncan P. N. Exon Smith321d6bf2017-04-21 23:14:55 +0000409
Richard Smith081bb592015-10-08 20:40:34 +0000410// isinf
411
Nikolas Klausere96070f2022-11-04 20:08:56 +0100412template <class _A1,
413 std::__enable_if_t<std::is_arithmetic<_A1>::value && std::numeric_limits<_A1>::has_infinity, int> = 0>
414inline _LIBCPP_HIDE_FROM_ABI bool isinf(_A1 __x) _NOEXCEPT {
Nikolas Klauser25fbc472022-11-04 16:56:51 +0100415 return __builtin_isinf((typename std::__promote<_A1>::type)__x);
Richard Smith081bb592015-10-08 20:40:34 +0000416}
417
Duncan P. N. Exon Smith321d6bf2017-04-21 23:14:55 +0000418template <class _A1>
Nikolas Klauser4956e722022-10-12 15:41:22 +0200419inline _LIBCPP_HIDE_FROM_ABI
Nikolas Klauser9a97dd72022-11-04 16:36:34 +0100420 typename std::enable_if< std::is_arithmetic<_A1>::value && !std::numeric_limits<_A1>::has_infinity, bool>::type
421 isinf(_A1) _NOEXCEPT {
422 return false;
423}
Duncan P. N. Exon Smith321d6bf2017-04-21 23:14:55 +0000424
Nikolas Klauser9a97dd72022-11-04 16:36:34 +0100425# ifdef _LIBCPP_PREFERRED_OVERLOAD
Nikolas Klauser25fbc472022-11-04 16:56:51 +0100426inline _LIBCPP_HIDE_FROM_ABI bool isinf(float __x) _NOEXCEPT { return __builtin_isinf(__x); }
Richard Smithafccfd32018-05-01 03:05:40 +0000427
Nikolas Klauser25fbc472022-11-04 16:56:51 +0100428inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_PREFERRED_OVERLOAD bool isinf(double __x) _NOEXCEPT { return __builtin_isinf(__x); }
Richard Smithafccfd32018-05-01 03:05:40 +0000429
Nikolas Klauser25fbc472022-11-04 16:56:51 +0100430inline _LIBCPP_HIDE_FROM_ABI bool isinf(long double __x) _NOEXCEPT { return __builtin_isinf(__x); }
Nikolas Klauser9a97dd72022-11-04 16:36:34 +0100431# endif
Richard Smithafccfd32018-05-01 03:05:40 +0000432
Richard Smith081bb592015-10-08 20:40:34 +0000433// isnan
434
Nikolas Klausere96070f2022-11-04 20:08:56 +0100435template <class _A1, std::__enable_if_t<std::is_floating_point<_A1>::value, int> = 0>
436inline _LIBCPP_HIDE_FROM_ABI bool isnan(_A1 __x) _NOEXCEPT {
Nikolas Klauser25fbc472022-11-04 16:56:51 +0100437 return __builtin_isnan(__x);
Richard Smith081bb592015-10-08 20:40:34 +0000438}
439
Nikolas Klausere96070f2022-11-04 20:08:56 +0100440template <class _A1, std::__enable_if_t<std::is_integral<_A1>::value, int> = 0>
441inline _LIBCPP_HIDE_FROM_ABI bool isnan(_A1) _NOEXCEPT {
Nikolas Klauser9a97dd72022-11-04 16:36:34 +0100442 return false;
443}
Duncan P. N. Exon Smith321d6bf2017-04-21 23:14:55 +0000444
Nikolas Klauser9a97dd72022-11-04 16:36:34 +0100445# ifdef _LIBCPP_PREFERRED_OVERLOAD
Nikolas Klauser25fbc472022-11-04 16:56:51 +0100446inline _LIBCPP_HIDE_FROM_ABI bool isnan(float __x) _NOEXCEPT { return __builtin_isnan(__x); }
Richard Smithafccfd32018-05-01 03:05:40 +0000447
Nikolas Klauser25fbc472022-11-04 16:56:51 +0100448inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_PREFERRED_OVERLOAD bool isnan(double __x) _NOEXCEPT { return __builtin_isnan(__x); }
Richard Smithafccfd32018-05-01 03:05:40 +0000449
Nikolas Klauser25fbc472022-11-04 16:56:51 +0100450inline _LIBCPP_HIDE_FROM_ABI bool isnan(long double __x) _NOEXCEPT { return __builtin_isnan(__x); }
Nikolas Klauser9a97dd72022-11-04 16:36:34 +0100451# endif
Richard Smithafccfd32018-05-01 03:05:40 +0000452
Richard Smith081bb592015-10-08 20:40:34 +0000453// isnormal
454
Nikolas Klausere96070f2022-11-04 20:08:56 +0100455template <class _A1, std::__enable_if_t<std::is_floating_point<_A1>::value, int> = 0>
456inline _LIBCPP_HIDE_FROM_ABI bool isnormal(_A1 __x) _NOEXCEPT {
Nikolas Klauser25fbc472022-11-04 16:56:51 +0100457 return __builtin_isnormal(__x);
Richard Smith081bb592015-10-08 20:40:34 +0000458}
459
Nikolas Klausere96070f2022-11-04 20:08:56 +0100460template <class _A1, std::__enable_if_t<std::is_integral<_A1>::value, int> = 0>
461inline _LIBCPP_HIDE_FROM_ABI bool isnormal(_A1 __x) _NOEXCEPT {
Nikolas Klauser9a97dd72022-11-04 16:36:34 +0100462 return __x != 0;
463}
Duncan P. N. Exon Smith321d6bf2017-04-21 23:14:55 +0000464
Richard Smith081bb592015-10-08 20:40:34 +0000465// isgreater
466
Nikolas Klausere96070f2022-11-04 20:08:56 +0100467template <class _A1,
468 class _A2,
469 std::__enable_if_t<std::is_arithmetic<_A1>::value && std::is_arithmetic<_A2>::value, int> = 0>
470inline _LIBCPP_HIDE_FROM_ABI bool isgreater(_A1 __x, _A2 __y) _NOEXCEPT {
Nikolas Klauser9a97dd72022-11-04 16:36:34 +0100471 typedef typename std::__promote<_A1, _A2>::type type;
Nikolas Klauser25fbc472022-11-04 16:56:51 +0100472 return __builtin_isgreater((type)__x, (type)__y);
Richard Smith081bb592015-10-08 20:40:34 +0000473}
474
Richard Smith081bb592015-10-08 20:40:34 +0000475// isgreaterequal
476
Nikolas Klausere96070f2022-11-04 20:08:56 +0100477template <class _A1,
478 class _A2,
479 std::__enable_if_t<std::is_arithmetic<_A1>::value && std::is_arithmetic<_A2>::value, int> = 0>
480inline _LIBCPP_HIDE_FROM_ABI bool isgreaterequal(_A1 __x, _A2 __y) _NOEXCEPT {
Nikolas Klauser9a97dd72022-11-04 16:36:34 +0100481 typedef typename std::__promote<_A1, _A2>::type type;
Nikolas Klauser25fbc472022-11-04 16:56:51 +0100482 return __builtin_isgreaterequal((type)__x, (type)__y);
Richard Smith081bb592015-10-08 20:40:34 +0000483}
484
Richard Smith081bb592015-10-08 20:40:34 +0000485// isless
486
Nikolas Klausere96070f2022-11-04 20:08:56 +0100487template <class _A1,
488 class _A2,
489 std::__enable_if_t<std::is_arithmetic<_A1>::value && std::is_arithmetic<_A2>::value, int> = 0>
490inline _LIBCPP_HIDE_FROM_ABI bool isless(_A1 __x, _A2 __y) _NOEXCEPT {
Nikolas Klauser9a97dd72022-11-04 16:36:34 +0100491 typedef typename std::__promote<_A1, _A2>::type type;
Nikolas Klauser25fbc472022-11-04 16:56:51 +0100492 return __builtin_isless((type)__x, (type)__y);
Richard Smith081bb592015-10-08 20:40:34 +0000493}
494
Richard Smith081bb592015-10-08 20:40:34 +0000495// islessequal
496
Nikolas Klausere96070f2022-11-04 20:08:56 +0100497template <class _A1,
498 class _A2,
499 std::__enable_if_t<std::is_arithmetic<_A1>::value && std::is_arithmetic<_A2>::value, int> = 0>
500inline _LIBCPP_HIDE_FROM_ABI bool islessequal(_A1 __x, _A2 __y) _NOEXCEPT {
Nikolas Klauser9a97dd72022-11-04 16:36:34 +0100501 typedef typename std::__promote<_A1, _A2>::type type;
Nikolas Klauser25fbc472022-11-04 16:56:51 +0100502 return __builtin_islessequal((type)__x, (type)__y);
Richard Smith081bb592015-10-08 20:40:34 +0000503}
504
Richard Smith081bb592015-10-08 20:40:34 +0000505// islessgreater
506
Nikolas Klausere96070f2022-11-04 20:08:56 +0100507template <class _A1,
508 class _A2,
509 std::__enable_if_t<std::is_arithmetic<_A1>::value && std::is_arithmetic<_A2>::value, int> = 0>
510inline _LIBCPP_HIDE_FROM_ABI bool islessgreater(_A1 __x, _A2 __y) _NOEXCEPT {
Nikolas Klauser9a97dd72022-11-04 16:36:34 +0100511 typedef typename std::__promote<_A1, _A2>::type type;
Nikolas Klauser25fbc472022-11-04 16:56:51 +0100512 return __builtin_islessgreater((type)__x, (type)__y);
Richard Smith081bb592015-10-08 20:40:34 +0000513}
514
Richard Smith081bb592015-10-08 20:40:34 +0000515// isunordered
516
Nikolas Klausere96070f2022-11-04 20:08:56 +0100517template <class _A1,
518 class _A2,
519 std::__enable_if_t<std::is_arithmetic<_A1>::value && std::is_arithmetic<_A2>::value, int> = 0>
520inline _LIBCPP_HIDE_FROM_ABI bool isunordered(_A1 __x, _A2 __y) _NOEXCEPT {
Nikolas Klauser9a97dd72022-11-04 16:36:34 +0100521 typedef typename std::__promote<_A1, _A2>::type type;
Nikolas Klauser25fbc472022-11-04 16:56:51 +0100522 return __builtin_isunordered((type)__x, (type)__y);
Richard Smith081bb592015-10-08 20:40:34 +0000523}
524
Nikolas Klauserae1fbc42022-11-04 20:19:20 +0100525#endif // _LIBCPP_MSVCRT
Richard Smith081bb592015-10-08 20:40:34 +0000526
Richard Smith081bb592015-10-08 20:40:34 +0000527// abs
Eric Fiselier6c9e1a72020-02-15 18:55:07 -0500528//
529// handled in stdlib.h
Richard Smith081bb592015-10-08 20:40:34 +0000530
Eric Fiselier2b85c6e2019-04-23 18:01:58 +0000531// div
Eric Fiselier6c9e1a72020-02-15 18:55:07 -0500532//
533// handled in stdlib.h
Eric Fiselier2b85c6e2019-04-23 18:01:58 +0000534
Nikolas Klauser52399652022-11-01 22:29:57 +0100535// We have to provide double overloads for <math.h> to work on platforms that don't provide the full set of math
536// functions. To make the overload set work with multiple functions that take the same arguments, we make our overloads
537// templates. Functions are preferred over function templates during overload resolution, which means that our overload
538// will only be selected when the C library doesn't provide one.
539
Richard Smith081bb592015-10-08 20:40:34 +0000540// acos
541
David Tenty7249ac92022-02-07 18:22:35 -0500542# if !defined(__sun__)
Nikolas Klauser04005952022-10-21 01:41:22 +0200543inline _LIBCPP_HIDE_FROM_ABI float acos(float __x) _NOEXCEPT {return __builtin_acosf(__x);}
Nikolas Klauser52399652022-11-01 22:29:57 +0100544
545template <class = int>
546_LIBCPP_HIDE_FROM_ABI double acos(double __x) _NOEXCEPT {
547 return __builtin_acos(__x);
548}
549
Nikolas Klauser04005952022-10-21 01:41:22 +0200550inline _LIBCPP_HIDE_FROM_ABI long double acos(long double __x) _NOEXCEPT {return __builtin_acosl(__x);}
David Tenty7249ac92022-02-07 18:22:35 -0500551# endif
Richard Smith081bb592015-10-08 20:40:34 +0000552
553template <class _A1>
Nikolas Klauser4956e722022-10-12 15:41:22 +0200554inline _LIBCPP_HIDE_FROM_ABI
Richard Smith081bb592015-10-08 20:40:34 +0000555typename std::enable_if<std::is_integral<_A1>::value, double>::type
Nikolas Klauser04005952022-10-21 01:41:22 +0200556acos(_A1 __x) _NOEXCEPT {return __builtin_acos((double)__x);}
Richard Smith081bb592015-10-08 20:40:34 +0000557
558// asin
559
David Tenty7249ac92022-02-07 18:22:35 -0500560# if !defined(__sun__)
Nikolas Klauser04005952022-10-21 01:41:22 +0200561inline _LIBCPP_HIDE_FROM_ABI float asin(float __x) _NOEXCEPT {return __builtin_asinf(__x);}
Nikolas Klauser52399652022-11-01 22:29:57 +0100562
563template <class = int>
564_LIBCPP_HIDE_FROM_ABI double asin(double __x) _NOEXCEPT {
565 return __builtin_asin(__x);
566}
567
Nikolas Klauser04005952022-10-21 01:41:22 +0200568inline _LIBCPP_HIDE_FROM_ABI long double asin(long double __x) _NOEXCEPT {return __builtin_asinl(__x);}
David Tenty7249ac92022-02-07 18:22:35 -0500569# endif
Richard Smith081bb592015-10-08 20:40:34 +0000570
571template <class _A1>
Nikolas Klauser4956e722022-10-12 15:41:22 +0200572inline _LIBCPP_HIDE_FROM_ABI
Richard Smith081bb592015-10-08 20:40:34 +0000573typename std::enable_if<std::is_integral<_A1>::value, double>::type
Nikolas Klauser04005952022-10-21 01:41:22 +0200574asin(_A1 __x) _NOEXCEPT {return __builtin_asin((double)__x);}
Richard Smith081bb592015-10-08 20:40:34 +0000575
576// atan
577
David Tenty7249ac92022-02-07 18:22:35 -0500578# if !defined(__sun__)
Nikolas Klauser04005952022-10-21 01:41:22 +0200579inline _LIBCPP_HIDE_FROM_ABI float atan(float __x) _NOEXCEPT {return __builtin_atanf(__x);}
Nikolas Klauser52399652022-11-01 22:29:57 +0100580
581template <class = int>
582_LIBCPP_HIDE_FROM_ABI double atan(double __x) _NOEXCEPT {
583 return __builtin_atan(__x);
584}
585
Nikolas Klauser04005952022-10-21 01:41:22 +0200586inline _LIBCPP_HIDE_FROM_ABI long double atan(long double __x) _NOEXCEPT {return __builtin_atanl(__x);}
David Tenty7249ac92022-02-07 18:22:35 -0500587# endif
Richard Smith081bb592015-10-08 20:40:34 +0000588
589template <class _A1>
Nikolas Klauser4956e722022-10-12 15:41:22 +0200590inline _LIBCPP_HIDE_FROM_ABI
Richard Smith081bb592015-10-08 20:40:34 +0000591typename std::enable_if<std::is_integral<_A1>::value, double>::type
Nikolas Klauser04005952022-10-21 01:41:22 +0200592atan(_A1 __x) _NOEXCEPT {return __builtin_atan((double)__x);}
Richard Smith081bb592015-10-08 20:40:34 +0000593
594// atan2
595
David Tenty7249ac92022-02-07 18:22:35 -0500596# if !defined(__sun__)
Nikolas Klauser04005952022-10-21 01:41:22 +0200597inline _LIBCPP_HIDE_FROM_ABI float atan2(float __y, float __x) _NOEXCEPT {return __builtin_atan2f(__y, __x);}
Nikolas Klauser52399652022-11-01 22:29:57 +0100598
599template <class = int>
600_LIBCPP_HIDE_FROM_ABI double atan2(double __x, double __y) _NOEXCEPT {
601 return __builtin_atan2(__x, __y);
602}
603
Nikolas Klauser04005952022-10-21 01:41:22 +0200604inline _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 -0500605# endif
Richard Smith081bb592015-10-08 20:40:34 +0000606
607template <class _A1, class _A2>
Nikolas Klauser4956e722022-10-12 15:41:22 +0200608inline _LIBCPP_HIDE_FROM_ABI
Louis Dionne9ce598d2021-09-08 09:14:43 -0400609typename std::__enable_if_t
Richard Smith081bb592015-10-08 20:40:34 +0000610<
611 std::is_arithmetic<_A1>::value &&
612 std::is_arithmetic<_A2>::value,
613 std::__promote<_A1, _A2>
614>::type
Nikolas Klauser9806f452022-10-12 15:45:09 +0200615atan2(_A1 __y, _A2 __x) _NOEXCEPT
Richard Smith081bb592015-10-08 20:40:34 +0000616{
617 typedef typename std::__promote<_A1, _A2>::type __result_type;
Eric Fiselier3906a132019-06-23 20:28:29 +0000618 static_assert((!(std::_IsSame<_A1, __result_type>::value &&
619 std::_IsSame<_A2, __result_type>::value)), "");
Nikolas Klauser9806f452022-10-12 15:45:09 +0200620 return ::atan2((__result_type)__y, (__result_type)__x);
Richard Smith081bb592015-10-08 20:40:34 +0000621}
622
623// ceil
624
David Tenty7249ac92022-02-07 18:22:35 -0500625# if !defined(__sun__)
Nikolas Klauser04005952022-10-21 01:41:22 +0200626inline _LIBCPP_HIDE_FROM_ABI float ceil(float __x) _NOEXCEPT {return __builtin_ceilf(__x);}
Nikolas Klauser52399652022-11-01 22:29:57 +0100627
628template <class = int>
629_LIBCPP_HIDE_FROM_ABI double ceil(double __x) _NOEXCEPT {
630 return __builtin_ceil(__x);
631}
632
Nikolas Klauser04005952022-10-21 01:41:22 +0200633inline _LIBCPP_HIDE_FROM_ABI long double ceil(long double __x) _NOEXCEPT {return __builtin_ceill(__x);}
David Tenty7249ac92022-02-07 18:22:35 -0500634# endif
Richard Smith081bb592015-10-08 20:40:34 +0000635
636template <class _A1>
Nikolas Klauser4956e722022-10-12 15:41:22 +0200637inline _LIBCPP_HIDE_FROM_ABI
Richard Smith081bb592015-10-08 20:40:34 +0000638typename std::enable_if<std::is_integral<_A1>::value, double>::type
Nikolas Klauser04005952022-10-21 01:41:22 +0200639ceil(_A1 __x) _NOEXCEPT {return __builtin_ceil((double)__x);}
Richard Smith081bb592015-10-08 20:40:34 +0000640
641// cos
642
David Tenty7249ac92022-02-07 18:22:35 -0500643# if !defined(__sun__)
Nikolas Klauser04005952022-10-21 01:41:22 +0200644inline _LIBCPP_HIDE_FROM_ABI float cos(float __x) _NOEXCEPT {return __builtin_cosf(__x);}
Nikolas Klauser52399652022-11-01 22:29:57 +0100645
646template <class = int>
647_LIBCPP_HIDE_FROM_ABI double cos(double __x) _NOEXCEPT {
648 return __builtin_cos(__x);
649}
650
Nikolas Klauser04005952022-10-21 01:41:22 +0200651inline _LIBCPP_HIDE_FROM_ABI long double cos(long double __x) _NOEXCEPT {return __builtin_cosl(__x);}
David Tenty7249ac92022-02-07 18:22:35 -0500652# endif
Richard Smith081bb592015-10-08 20:40:34 +0000653
654template <class _A1>
Nikolas Klauser4956e722022-10-12 15:41:22 +0200655inline _LIBCPP_HIDE_FROM_ABI
Richard Smith081bb592015-10-08 20:40:34 +0000656typename std::enable_if<std::is_integral<_A1>::value, double>::type
Nikolas Klauser04005952022-10-21 01:41:22 +0200657cos(_A1 __x) _NOEXCEPT {return __builtin_cos((double)__x);}
Richard Smith081bb592015-10-08 20:40:34 +0000658
659// cosh
660
David Tenty7249ac92022-02-07 18:22:35 -0500661# if !defined(__sun__)
Nikolas Klauser04005952022-10-21 01:41:22 +0200662inline _LIBCPP_HIDE_FROM_ABI float cosh(float __x) _NOEXCEPT {return __builtin_coshf(__x);}
Nikolas Klauser52399652022-11-01 22:29:57 +0100663
664template <class = int>
665_LIBCPP_HIDE_FROM_ABI double cosh(double __x) _NOEXCEPT {
666 return __builtin_cosh(__x);
667}
668
Nikolas Klauser04005952022-10-21 01:41:22 +0200669inline _LIBCPP_HIDE_FROM_ABI long double cosh(long double __x) _NOEXCEPT {return __builtin_coshl(__x);}
David Tenty7249ac92022-02-07 18:22:35 -0500670# endif
Richard Smith081bb592015-10-08 20:40:34 +0000671
672template <class _A1>
Nikolas Klauser4956e722022-10-12 15:41:22 +0200673inline _LIBCPP_HIDE_FROM_ABI
Richard Smith081bb592015-10-08 20:40:34 +0000674typename std::enable_if<std::is_integral<_A1>::value, double>::type
Nikolas Klauser04005952022-10-21 01:41:22 +0200675cosh(_A1 __x) _NOEXCEPT {return __builtin_cosh((double)__x);}
Richard Smith081bb592015-10-08 20:40:34 +0000676
677// exp
678
David Tenty7249ac92022-02-07 18:22:35 -0500679# if !defined(__sun__)
Nikolas Klauser04005952022-10-21 01:41:22 +0200680inline _LIBCPP_HIDE_FROM_ABI float exp(float __x) _NOEXCEPT {return __builtin_expf(__x);}
Nikolas Klauser52399652022-11-01 22:29:57 +0100681
682template <class = int>
683_LIBCPP_HIDE_FROM_ABI double exp(double __x) _NOEXCEPT {
684 return __builtin_exp(__x);
685}
686
Nikolas Klauser04005952022-10-21 01:41:22 +0200687inline _LIBCPP_HIDE_FROM_ABI long double exp(long double __x) _NOEXCEPT {return __builtin_expl(__x);}
David Tenty7249ac92022-02-07 18:22:35 -0500688# endif
Richard Smith081bb592015-10-08 20:40:34 +0000689
690template <class _A1>
Nikolas Klauser4956e722022-10-12 15:41:22 +0200691inline _LIBCPP_HIDE_FROM_ABI
Richard Smith081bb592015-10-08 20:40:34 +0000692typename std::enable_if<std::is_integral<_A1>::value, double>::type
Nikolas Klauser04005952022-10-21 01:41:22 +0200693exp(_A1 __x) _NOEXCEPT {return __builtin_exp((double)__x);}
Richard Smith081bb592015-10-08 20:40:34 +0000694
695// fabs
696
David Tenty7249ac92022-02-07 18:22:35 -0500697# if !defined(__sun__)
Nikolas Klauser04005952022-10-21 01:41:22 +0200698inline _LIBCPP_HIDE_FROM_ABI float fabs(float __x) _NOEXCEPT {return __builtin_fabsf(__x);}
Nikolas Klauser52399652022-11-01 22:29:57 +0100699
700template <class = int>
701_LIBCPP_HIDE_FROM_ABI double fabs(double __x) _NOEXCEPT {
702 return __builtin_fabs(__x);
703}
704
Nikolas Klauser04005952022-10-21 01:41:22 +0200705inline _LIBCPP_HIDE_FROM_ABI long double fabs(long double __x) _NOEXCEPT {return __builtin_fabsl(__x);}
David Tenty7249ac92022-02-07 18:22:35 -0500706# endif
Richard Smith081bb592015-10-08 20:40:34 +0000707
708template <class _A1>
Nikolas Klauser4956e722022-10-12 15:41:22 +0200709inline _LIBCPP_HIDE_FROM_ABI
Richard Smith081bb592015-10-08 20:40:34 +0000710typename std::enable_if<std::is_integral<_A1>::value, double>::type
Nikolas Klauser04005952022-10-21 01:41:22 +0200711fabs(_A1 __x) _NOEXCEPT {return __builtin_fabs((double)__x);}
Richard Smith081bb592015-10-08 20:40:34 +0000712
713// floor
714
David Tenty7249ac92022-02-07 18:22:35 -0500715# if !defined(__sun__)
Nikolas Klauser04005952022-10-21 01:41:22 +0200716inline _LIBCPP_HIDE_FROM_ABI float floor(float __x) _NOEXCEPT {return __builtin_floorf(__x);}
Nikolas Klauser52399652022-11-01 22:29:57 +0100717
718template <class = int>
719_LIBCPP_HIDE_FROM_ABI double floor(double __x) _NOEXCEPT {
720 return __builtin_floor(__x);
721}
722
Nikolas Klauser04005952022-10-21 01:41:22 +0200723inline _LIBCPP_HIDE_FROM_ABI long double floor(long double __x) _NOEXCEPT {return __builtin_floorl(__x);}
David Tenty7249ac92022-02-07 18:22:35 -0500724# endif
Richard Smith081bb592015-10-08 20:40:34 +0000725
726template <class _A1>
Nikolas Klauser4956e722022-10-12 15:41:22 +0200727inline _LIBCPP_HIDE_FROM_ABI
Richard Smith081bb592015-10-08 20:40:34 +0000728typename std::enable_if<std::is_integral<_A1>::value, double>::type
Nikolas Klauser04005952022-10-21 01:41:22 +0200729floor(_A1 __x) _NOEXCEPT {return __builtin_floor((double)__x);}
Richard Smith081bb592015-10-08 20:40:34 +0000730
731// fmod
732
David Tenty7249ac92022-02-07 18:22:35 -0500733# if !defined(__sun__)
Nikolas Klauser04005952022-10-21 01:41:22 +0200734inline _LIBCPP_HIDE_FROM_ABI float fmod(float __x, float __y) _NOEXCEPT {return __builtin_fmodf(__x, __y);}
Nikolas Klauser52399652022-11-01 22:29:57 +0100735
736template <class = int>
737_LIBCPP_HIDE_FROM_ABI double fmod(double __x, double __y) _NOEXCEPT {
738 return __builtin_fmod(__x, __y);
739}
740
Nikolas Klauser04005952022-10-21 01:41:22 +0200741inline _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 -0500742# endif
Richard Smith081bb592015-10-08 20:40:34 +0000743
744template <class _A1, class _A2>
Nikolas Klauser4956e722022-10-12 15:41:22 +0200745inline _LIBCPP_HIDE_FROM_ABI
Louis Dionne9ce598d2021-09-08 09:14:43 -0400746typename std::__enable_if_t
Richard Smith081bb592015-10-08 20:40:34 +0000747<
748 std::is_arithmetic<_A1>::value &&
749 std::is_arithmetic<_A2>::value,
750 std::__promote<_A1, _A2>
751>::type
Nikolas Klauser9806f452022-10-12 15:45:09 +0200752fmod(_A1 __x, _A2 __y) _NOEXCEPT
Richard Smith081bb592015-10-08 20:40:34 +0000753{
754 typedef typename std::__promote<_A1, _A2>::type __result_type;
Eric Fiselier3906a132019-06-23 20:28:29 +0000755 static_assert((!(std::_IsSame<_A1, __result_type>::value &&
756 std::_IsSame<_A2, __result_type>::value)), "");
Nikolas Klauser9806f452022-10-12 15:45:09 +0200757 return ::fmod((__result_type)__x, (__result_type)__y);
Richard Smith081bb592015-10-08 20:40:34 +0000758}
759
760// frexp
761
David Tenty7249ac92022-02-07 18:22:35 -0500762# if !defined(__sun__)
Nikolas Klauser04005952022-10-21 01:41:22 +0200763inline _LIBCPP_HIDE_FROM_ABI float frexp(float __x, int* __e) _NOEXCEPT {return __builtin_frexpf(__x, __e);}
Nikolas Klauser52399652022-11-01 22:29:57 +0100764
765template <class = int>
766_LIBCPP_HIDE_FROM_ABI double frexp(double __x, int* __e) _NOEXCEPT {
767 return __builtin_frexp(__x, __e);
768}
769
Nikolas Klauser04005952022-10-21 01:41:22 +0200770inline _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 -0500771# endif
Richard Smith081bb592015-10-08 20:40:34 +0000772
773template <class _A1>
Nikolas Klauser4956e722022-10-12 15:41:22 +0200774inline _LIBCPP_HIDE_FROM_ABI
Richard Smith081bb592015-10-08 20:40:34 +0000775typename std::enable_if<std::is_integral<_A1>::value, double>::type
Nikolas Klauser04005952022-10-21 01:41:22 +0200776frexp(_A1 __x, int* __e) _NOEXCEPT {return __builtin_frexp((double)__x, __e);}
Richard Smith081bb592015-10-08 20:40:34 +0000777
778// ldexp
779
David Tenty7249ac92022-02-07 18:22:35 -0500780# if !defined(__sun__)
Nikolas Klauser04005952022-10-21 01:41:22 +0200781inline _LIBCPP_HIDE_FROM_ABI float ldexp(float __x, int __e) _NOEXCEPT {return __builtin_ldexpf(__x, __e);}
Nikolas Klauser52399652022-11-01 22:29:57 +0100782
783template <class = int>
784_LIBCPP_HIDE_FROM_ABI double ldexp(double __x, int __e) _NOEXCEPT {
785 return __builtin_ldexp(__x, __e);
786}
787
Nikolas Klauser04005952022-10-21 01:41:22 +0200788inline _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 -0500789# endif
Richard Smith081bb592015-10-08 20:40:34 +0000790
791template <class _A1>
Nikolas Klauser4956e722022-10-12 15:41:22 +0200792inline _LIBCPP_HIDE_FROM_ABI
Richard Smith081bb592015-10-08 20:40:34 +0000793typename std::enable_if<std::is_integral<_A1>::value, double>::type
Nikolas Klauser04005952022-10-21 01:41:22 +0200794ldexp(_A1 __x, int __e) _NOEXCEPT {return __builtin_ldexp((double)__x, __e);}
Richard Smith081bb592015-10-08 20:40:34 +0000795
796// log
797
David Tenty7249ac92022-02-07 18:22:35 -0500798# if !defined(__sun__)
Nikolas Klauser04005952022-10-21 01:41:22 +0200799inline _LIBCPP_HIDE_FROM_ABI float log(float __x) _NOEXCEPT {return __builtin_logf(__x);}
Nikolas Klauser52399652022-11-01 22:29:57 +0100800
801template <class = int>
802_LIBCPP_HIDE_FROM_ABI double log(double __x) _NOEXCEPT {
803 return __builtin_log(__x);
804}
805
Nikolas Klauser04005952022-10-21 01:41:22 +0200806inline _LIBCPP_HIDE_FROM_ABI long double log(long double __x) _NOEXCEPT {return __builtin_logl(__x);}
David Tenty7249ac92022-02-07 18:22:35 -0500807# endif
Richard Smith081bb592015-10-08 20:40:34 +0000808
809template <class _A1>
Nikolas Klauser4956e722022-10-12 15:41:22 +0200810inline _LIBCPP_HIDE_FROM_ABI
Richard Smith081bb592015-10-08 20:40:34 +0000811typename std::enable_if<std::is_integral<_A1>::value, double>::type
Nikolas Klauser04005952022-10-21 01:41:22 +0200812log(_A1 __x) _NOEXCEPT {return __builtin_log((double)__x);}
Richard Smith081bb592015-10-08 20:40:34 +0000813
814// log10
815
David Tenty7249ac92022-02-07 18:22:35 -0500816# if !defined(__sun__)
Nikolas Klauser04005952022-10-21 01:41:22 +0200817inline _LIBCPP_HIDE_FROM_ABI float log10(float __x) _NOEXCEPT {return __builtin_log10f(__x);}
Nikolas Klauser52399652022-11-01 22:29:57 +0100818
819
820template <class = int>
821_LIBCPP_HIDE_FROM_ABI double log10(double __x) _NOEXCEPT {
822 return __builtin_log10(__x);
823}
824
Nikolas Klauser04005952022-10-21 01:41:22 +0200825inline _LIBCPP_HIDE_FROM_ABI long double log10(long double __x) _NOEXCEPT {return __builtin_log10l(__x);}
David Tenty7249ac92022-02-07 18:22:35 -0500826# endif
Richard Smith081bb592015-10-08 20:40:34 +0000827
828template <class _A1>
Nikolas Klauser4956e722022-10-12 15:41:22 +0200829inline _LIBCPP_HIDE_FROM_ABI
Richard Smith081bb592015-10-08 20:40:34 +0000830typename std::enable_if<std::is_integral<_A1>::value, double>::type
Nikolas Klauser04005952022-10-21 01:41:22 +0200831log10(_A1 __x) _NOEXCEPT {return __builtin_log10((double)__x);}
Richard Smith081bb592015-10-08 20:40:34 +0000832
833// modf
834
David Tenty7249ac92022-02-07 18:22:35 -0500835# if !defined(__sun__)
Nikolas Klauser04005952022-10-21 01:41:22 +0200836inline _LIBCPP_HIDE_FROM_ABI float modf(float __x, float* __y) _NOEXCEPT {return __builtin_modff(__x, __y);}
Nikolas Klauser52399652022-11-01 22:29:57 +0100837
838template <class = int>
839_LIBCPP_HIDE_FROM_ABI double modf(double __x, double* __y) _NOEXCEPT {
840 return __builtin_modf(__x, __y);
841}
842
Nikolas Klauser04005952022-10-21 01:41:22 +0200843inline _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 -0500844# endif
Richard Smith081bb592015-10-08 20:40:34 +0000845
846// pow
847
David Tenty7249ac92022-02-07 18:22:35 -0500848# if !defined(__sun__)
Nikolas Klauser04005952022-10-21 01:41:22 +0200849inline _LIBCPP_HIDE_FROM_ABI float pow(float __x, float __y) _NOEXCEPT {return __builtin_powf(__x, __y);}
Nikolas Klauser52399652022-11-01 22:29:57 +0100850
851template <class = int>
852_LIBCPP_HIDE_FROM_ABI double pow(double __x, double __y) _NOEXCEPT {
853 return __builtin_pow(__x, __y);
854}
855
Nikolas Klauser04005952022-10-21 01:41:22 +0200856inline _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 -0500857# endif
Richard Smith081bb592015-10-08 20:40:34 +0000858
859template <class _A1, class _A2>
Nikolas Klauser4956e722022-10-12 15:41:22 +0200860inline _LIBCPP_HIDE_FROM_ABI
Louis Dionne9ce598d2021-09-08 09:14:43 -0400861typename std::__enable_if_t
Richard Smith081bb592015-10-08 20:40:34 +0000862<
863 std::is_arithmetic<_A1>::value &&
864 std::is_arithmetic<_A2>::value,
865 std::__promote<_A1, _A2>
866>::type
Nikolas Klauser9806f452022-10-12 15:45:09 +0200867pow(_A1 __x, _A2 __y) _NOEXCEPT
Richard Smith081bb592015-10-08 20:40:34 +0000868{
869 typedef typename std::__promote<_A1, _A2>::type __result_type;
Eric Fiselier3906a132019-06-23 20:28:29 +0000870 static_assert((!(std::_IsSame<_A1, __result_type>::value &&
871 std::_IsSame<_A2, __result_type>::value)), "");
Nikolas Klauser9806f452022-10-12 15:45:09 +0200872 return ::pow((__result_type)__x, (__result_type)__y);
Richard Smith081bb592015-10-08 20:40:34 +0000873}
874
875// sin
876
David Tenty7249ac92022-02-07 18:22:35 -0500877# if !defined(__sun__)
Nikolas Klauser04005952022-10-21 01:41:22 +0200878inline _LIBCPP_HIDE_FROM_ABI float sin(float __x) _NOEXCEPT {return __builtin_sinf(__x);}
Nikolas Klauser52399652022-11-01 22:29:57 +0100879
880template <class = int>
881_LIBCPP_HIDE_FROM_ABI double sin(double __x) _NOEXCEPT {
882 return __builtin_sin(__x);
883}
884
Nikolas Klauser04005952022-10-21 01:41:22 +0200885inline _LIBCPP_HIDE_FROM_ABI long double sin(long double __x) _NOEXCEPT {return __builtin_sinl(__x);}
Richard Smith081bb592015-10-08 20:40:34 +0000886#endif
887
888template <class _A1>
Nikolas Klauser4956e722022-10-12 15:41:22 +0200889inline _LIBCPP_HIDE_FROM_ABI
Richard Smith081bb592015-10-08 20:40:34 +0000890typename std::enable_if<std::is_integral<_A1>::value, double>::type
Nikolas Klauser04005952022-10-21 01:41:22 +0200891sin(_A1 __x) _NOEXCEPT {return __builtin_sin((double)__x);}
Richard Smith081bb592015-10-08 20:40:34 +0000892
893// sinh
894
David Tenty7249ac92022-02-07 18:22:35 -0500895# if !defined(__sun__)
Nikolas Klauser04005952022-10-21 01:41:22 +0200896inline _LIBCPP_HIDE_FROM_ABI float sinh(float __x) _NOEXCEPT {return __builtin_sinhf(__x);}
Nikolas Klauser52399652022-11-01 22:29:57 +0100897
898template <class = int>
899_LIBCPP_HIDE_FROM_ABI double sinh(double __x) _NOEXCEPT {
900 return __builtin_sinh(__x);
901}
902
Nikolas Klauser04005952022-10-21 01:41:22 +0200903inline _LIBCPP_HIDE_FROM_ABI long double sinh(long double __x) _NOEXCEPT {return __builtin_sinhl(__x);}
David Tenty7249ac92022-02-07 18:22:35 -0500904# endif
Richard Smith081bb592015-10-08 20:40:34 +0000905
906template <class _A1>
Nikolas Klauser4956e722022-10-12 15:41:22 +0200907inline _LIBCPP_HIDE_FROM_ABI
Richard Smith081bb592015-10-08 20:40:34 +0000908typename std::enable_if<std::is_integral<_A1>::value, double>::type
Nikolas Klauser04005952022-10-21 01:41:22 +0200909sinh(_A1 __x) _NOEXCEPT {return __builtin_sinh((double)__x);}
Richard Smith081bb592015-10-08 20:40:34 +0000910
911// sqrt
912
David Tenty7249ac92022-02-07 18:22:35 -0500913# if !defined(__sun__)
Nikolas Klauser04005952022-10-21 01:41:22 +0200914inline _LIBCPP_HIDE_FROM_ABI float sqrt(float __x) _NOEXCEPT {return __builtin_sqrtf(__x);}
Nikolas Klauser52399652022-11-01 22:29:57 +0100915
916template <class = int>
917_LIBCPP_HIDE_FROM_ABI double sqrt(double __x) _NOEXCEPT {
918 return __builtin_sqrt(__x);
919}
920
Nikolas Klauser04005952022-10-21 01:41:22 +0200921inline _LIBCPP_HIDE_FROM_ABI long double sqrt(long double __x) _NOEXCEPT {return __builtin_sqrtl(__x);}
David Tenty7249ac92022-02-07 18:22:35 -0500922# endif
Richard Smith081bb592015-10-08 20:40:34 +0000923
Richard Smith081bb592015-10-08 20:40:34 +0000924template <class _A1>
Nikolas Klauser4956e722022-10-12 15:41:22 +0200925inline _LIBCPP_HIDE_FROM_ABI
Richard Smith081bb592015-10-08 20:40:34 +0000926typename std::enable_if<std::is_integral<_A1>::value, double>::type
Nikolas Klauser04005952022-10-21 01:41:22 +0200927sqrt(_A1 __x) _NOEXCEPT {return __builtin_sqrt((double)__x);}
Richard Smith081bb592015-10-08 20:40:34 +0000928
929// tan
930
David Tenty7249ac92022-02-07 18:22:35 -0500931# if !defined(__sun__)
Nikolas Klauser04005952022-10-21 01:41:22 +0200932inline _LIBCPP_HIDE_FROM_ABI float tan(float __x) _NOEXCEPT {return __builtin_tanf(__x);}
Nikolas Klauser52399652022-11-01 22:29:57 +0100933
934template <class = int>
935_LIBCPP_HIDE_FROM_ABI double tan(double __x) _NOEXCEPT {
936 return __builtin_tan(__x);
937}
938
Nikolas Klauser04005952022-10-21 01:41:22 +0200939inline _LIBCPP_HIDE_FROM_ABI long double tan(long double __x) _NOEXCEPT {return __builtin_tanl(__x);}
David Tenty7249ac92022-02-07 18:22:35 -0500940# endif
Richard Smith081bb592015-10-08 20:40:34 +0000941
942template <class _A1>
Nikolas Klauser4956e722022-10-12 15:41:22 +0200943inline _LIBCPP_HIDE_FROM_ABI
Richard Smith081bb592015-10-08 20:40:34 +0000944typename std::enable_if<std::is_integral<_A1>::value, double>::type
Nikolas Klauser04005952022-10-21 01:41:22 +0200945tan(_A1 __x) _NOEXCEPT {return __builtin_tan((double)__x);}
Richard Smith081bb592015-10-08 20:40:34 +0000946
947// tanh
948
David Tenty7249ac92022-02-07 18:22:35 -0500949# if !defined(__sun__)
Nikolas Klauser04005952022-10-21 01:41:22 +0200950inline _LIBCPP_HIDE_FROM_ABI float tanh(float __x) _NOEXCEPT {return __builtin_tanhf(__x);}
Nikolas Klauser52399652022-11-01 22:29:57 +0100951
952template <class = int>
953_LIBCPP_HIDE_FROM_ABI double tanh(double __x) _NOEXCEPT {
954 return __builtin_tanh(__x);
955}
956
Nikolas Klauser04005952022-10-21 01:41:22 +0200957inline _LIBCPP_HIDE_FROM_ABI long double tanh(long double __x) _NOEXCEPT {return __builtin_tanhl(__x);}
David Tenty7249ac92022-02-07 18:22:35 -0500958# endif
Richard Smith081bb592015-10-08 20:40:34 +0000959
960template <class _A1>
Nikolas Klauser4956e722022-10-12 15:41:22 +0200961inline _LIBCPP_HIDE_FROM_ABI
Richard Smith081bb592015-10-08 20:40:34 +0000962typename std::enable_if<std::is_integral<_A1>::value, double>::type
Nikolas Klauser04005952022-10-21 01:41:22 +0200963tanh(_A1 __x) _NOEXCEPT {return __builtin_tanh((double)__x);}
Richard Smith081bb592015-10-08 20:40:34 +0000964
965// acosh
966
Nikolas Klauser04005952022-10-21 01:41:22 +0200967inline _LIBCPP_HIDE_FROM_ABI float acosh(float __x) _NOEXCEPT {return __builtin_acoshf(__x);}
Nikolas Klauser52399652022-11-01 22:29:57 +0100968
969template <class = int>
970_LIBCPP_HIDE_FROM_ABI double acosh(double __x) _NOEXCEPT {
971 return __builtin_acosh(__x);
972}
973
Nikolas Klauser04005952022-10-21 01:41:22 +0200974inline _LIBCPP_HIDE_FROM_ABI long double acosh(long double __x) _NOEXCEPT {return __builtin_acoshl(__x);}
Richard Smith081bb592015-10-08 20:40:34 +0000975
976template <class _A1>
Nikolas Klauser4956e722022-10-12 15:41:22 +0200977inline _LIBCPP_HIDE_FROM_ABI
Richard Smith081bb592015-10-08 20:40:34 +0000978typename std::enable_if<std::is_integral<_A1>::value, double>::type
Nikolas Klauser04005952022-10-21 01:41:22 +0200979acosh(_A1 __x) _NOEXCEPT {return __builtin_acosh((double)__x);}
Richard Smith081bb592015-10-08 20:40:34 +0000980
981// asinh
982
Nikolas Klauser04005952022-10-21 01:41:22 +0200983inline _LIBCPP_HIDE_FROM_ABI float asinh(float __x) _NOEXCEPT {return __builtin_asinhf(__x);}
Nikolas Klauser52399652022-11-01 22:29:57 +0100984
985template <class = int>
986_LIBCPP_HIDE_FROM_ABI double asinh(double __x) _NOEXCEPT {
987 return __builtin_asinh(__x);
988}
989
Nikolas Klauser04005952022-10-21 01:41:22 +0200990inline _LIBCPP_HIDE_FROM_ABI long double asinh(long double __x) _NOEXCEPT {return __builtin_asinhl(__x);}
Richard Smith081bb592015-10-08 20:40:34 +0000991
992template <class _A1>
Nikolas Klauser4956e722022-10-12 15:41:22 +0200993inline _LIBCPP_HIDE_FROM_ABI
Richard Smith081bb592015-10-08 20:40:34 +0000994typename std::enable_if<std::is_integral<_A1>::value, double>::type
Nikolas Klauser04005952022-10-21 01:41:22 +0200995asinh(_A1 __x) _NOEXCEPT {return __builtin_asinh((double)__x);}
Richard Smith081bb592015-10-08 20:40:34 +0000996
997// atanh
998
Nikolas Klauser04005952022-10-21 01:41:22 +0200999inline _LIBCPP_HIDE_FROM_ABI float atanh(float __x) _NOEXCEPT {return __builtin_atanhf(__x);}
Nikolas Klauser52399652022-11-01 22:29:57 +01001000
1001template <class = int>
1002_LIBCPP_HIDE_FROM_ABI double atanh(double __x) _NOEXCEPT {
1003 return __builtin_atanh(__x);
1004}
1005
Nikolas Klauser04005952022-10-21 01:41:22 +02001006inline _LIBCPP_HIDE_FROM_ABI long double atanh(long double __x) _NOEXCEPT {return __builtin_atanhl(__x);}
Richard Smith081bb592015-10-08 20:40:34 +00001007
1008template <class _A1>
Nikolas Klauser4956e722022-10-12 15:41:22 +02001009inline _LIBCPP_HIDE_FROM_ABI
Richard Smith081bb592015-10-08 20:40:34 +00001010typename std::enable_if<std::is_integral<_A1>::value, double>::type
Nikolas Klauser04005952022-10-21 01:41:22 +02001011atanh(_A1 __x) _NOEXCEPT {return __builtin_atanh((double)__x);}
Richard Smith081bb592015-10-08 20:40:34 +00001012
1013// cbrt
1014
Nikolas Klauser04005952022-10-21 01:41:22 +02001015inline _LIBCPP_HIDE_FROM_ABI float cbrt(float __x) _NOEXCEPT {return __builtin_cbrtf(__x);}
Nikolas Klauser52399652022-11-01 22:29:57 +01001016
1017template <class = int>
1018_LIBCPP_HIDE_FROM_ABI double cbrt(double __x) _NOEXCEPT {
1019 return __builtin_cbrt(__x);
1020}
1021
Nikolas Klauser04005952022-10-21 01:41:22 +02001022inline _LIBCPP_HIDE_FROM_ABI long double cbrt(long double __x) _NOEXCEPT {return __builtin_cbrtl(__x);}
Richard Smith081bb592015-10-08 20:40:34 +00001023
1024template <class _A1>
Nikolas Klauser4956e722022-10-12 15:41:22 +02001025inline _LIBCPP_HIDE_FROM_ABI
Richard Smith081bb592015-10-08 20:40:34 +00001026typename std::enable_if<std::is_integral<_A1>::value, double>::type
Nikolas Klauser04005952022-10-21 01:41:22 +02001027cbrt(_A1 __x) _NOEXCEPT {return __builtin_cbrt((double)__x);}
Richard Smith081bb592015-10-08 20:40:34 +00001028
1029// copysign
1030
Marek Kurdeja933f0d2021-07-21 15:58:17 +02001031_LIBCPP_CONSTEXPR
Nikolas Klauser9806f452022-10-12 15:45:09 +02001032inline _LIBCPP_HIDE_FROM_ABI float __libcpp_copysign(float __x, float __y) _NOEXCEPT {
Nikolas Klauser9806f452022-10-12 15:45:09 +02001033 return __builtin_copysignf(__x, __y);
Richard Smith081bb592015-10-08 20:40:34 +00001034}
Marek Kurdeja933f0d2021-07-21 15:58:17 +02001035
Marek Kurdeja933f0d2021-07-21 15:58:17 +02001036_LIBCPP_CONSTEXPR
Nikolas Klauser9806f452022-10-12 15:45:09 +02001037inline _LIBCPP_HIDE_FROM_ABI double __libcpp_copysign(double __x, double __y) _NOEXCEPT {
Nikolas Klauser9806f452022-10-12 15:45:09 +02001038 return __builtin_copysign(__x, __y);
Marek Kurdeja933f0d2021-07-21 15:58:17 +02001039}
1040
Marek Kurdeja933f0d2021-07-21 15:58:17 +02001041_LIBCPP_CONSTEXPR
Nikolas Klauser9806f452022-10-12 15:45:09 +02001042inline _LIBCPP_HIDE_FROM_ABI long double __libcpp_copysign(long double __x, long double __y) _NOEXCEPT {
Nikolas Klauser9806f452022-10-12 15:45:09 +02001043 return __builtin_copysignl(__x, __y);
Richard Smith081bb592015-10-08 20:40:34 +00001044}
Richard Smith081bb592015-10-08 20:40:34 +00001045
1046template <class _A1, class _A2>
Marek Kurdeja933f0d2021-07-21 15:58:17 +02001047_LIBCPP_CONSTEXPR
Nikolas Klauser4956e722022-10-12 15:41:22 +02001048inline _LIBCPP_HIDE_FROM_ABI
Louis Dionne9ce598d2021-09-08 09:14:43 -04001049typename std::__enable_if_t
Marek Kurdeja933f0d2021-07-21 15:58:17 +02001050<
1051 std::is_arithmetic<_A1>::value &&
1052 std::is_arithmetic<_A2>::value,
1053 std::__promote<_A1, _A2>
1054>::type
Nikolas Klauser9806f452022-10-12 15:45:09 +02001055__libcpp_copysign(_A1 __x, _A2 __y) _NOEXCEPT {
Marek Kurdeja933f0d2021-07-21 15:58:17 +02001056 typedef typename std::__promote<_A1, _A2>::type __result_type;
1057 static_assert((!(std::_IsSame<_A1, __result_type>::value &&
1058 std::_IsSame<_A2, __result_type>::value)), "");
Nikolas Klauser9806f452022-10-12 15:45:09 +02001059 return __builtin_copysign((__result_type)__x, (__result_type)__y);
Marek Kurdeja933f0d2021-07-21 15:58:17 +02001060}
1061
Nikolas Klauser9806f452022-10-12 15:45:09 +02001062inline _LIBCPP_HIDE_FROM_ABI float copysign(float __x, float __y) _NOEXCEPT {
1063 return ::__libcpp_copysign(__x, __y);
Marek Kurdeja933f0d2021-07-21 15:58:17 +02001064}
1065
Nikolas Klauser9806f452022-10-12 15:45:09 +02001066inline _LIBCPP_HIDE_FROM_ABI long double copysign(long double __x, long double __y) _NOEXCEPT {
1067 return ::__libcpp_copysign(__x, __y);
Marek Kurdeja933f0d2021-07-21 15:58:17 +02001068}
1069
1070template <class _A1, class _A2>
Nikolas Klauser4956e722022-10-12 15:41:22 +02001071inline _LIBCPP_HIDE_FROM_ABI
Louis Dionne9ce598d2021-09-08 09:14:43 -04001072typename std::__enable_if_t
Richard Smith081bb592015-10-08 20:40:34 +00001073<
1074 std::is_arithmetic<_A1>::value &&
1075 std::is_arithmetic<_A2>::value,
1076 std::__promote<_A1, _A2>
1077>::type
Nikolas Klauser9806f452022-10-12 15:45:09 +02001078 copysign(_A1 __x, _A2 __y) _NOEXCEPT {
1079 return ::__libcpp_copysign(__x, __y);
Richard Smith081bb592015-10-08 20:40:34 +00001080}
1081
Richard Smith081bb592015-10-08 20:40:34 +00001082// erf
1083
Nikolas Klauser04005952022-10-21 01:41:22 +02001084inline _LIBCPP_HIDE_FROM_ABI float erf(float __x) _NOEXCEPT {return __builtin_erff(__x);}
Nikolas Klauser52399652022-11-01 22:29:57 +01001085
1086template <class = int>
1087_LIBCPP_HIDE_FROM_ABI double erf(double __x) _NOEXCEPT {
1088 return __builtin_erf(__x);
1089}
1090
Nikolas Klauser04005952022-10-21 01:41:22 +02001091inline _LIBCPP_HIDE_FROM_ABI long double erf(long double __x) _NOEXCEPT {return __builtin_erfl(__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 +02001096erf(_A1 __x) _NOEXCEPT {return __builtin_erf((double)__x);}
Richard Smith081bb592015-10-08 20:40:34 +00001097
1098// erfc
1099
Nikolas Klauser04005952022-10-21 01:41:22 +02001100inline _LIBCPP_HIDE_FROM_ABI float erfc(float __x) _NOEXCEPT {return __builtin_erfcf(__x);}
Nikolas Klauser52399652022-11-01 22:29:57 +01001101
1102template <class = int>
1103_LIBCPP_HIDE_FROM_ABI double erfc(double __x) _NOEXCEPT {
1104 return __builtin_erfc(__x);
1105}
1106
Nikolas Klauser04005952022-10-21 01:41:22 +02001107inline _LIBCPP_HIDE_FROM_ABI long double erfc(long double __x) _NOEXCEPT {return __builtin_erfcl(__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 +02001112erfc(_A1 __x) _NOEXCEPT {return __builtin_erfc((double)__x);}
Richard Smith081bb592015-10-08 20:40:34 +00001113
1114// exp2
1115
Nikolas Klauser04005952022-10-21 01:41:22 +02001116inline _LIBCPP_HIDE_FROM_ABI float exp2(float __x) _NOEXCEPT {return __builtin_exp2f(__x);}
Nikolas Klauser52399652022-11-01 22:29:57 +01001117
1118template <class = int>
1119_LIBCPP_HIDE_FROM_ABI double exp2(double __x) _NOEXCEPT {
1120 return __builtin_exp2(__x);
1121}
1122
Nikolas Klauser04005952022-10-21 01:41:22 +02001123inline _LIBCPP_HIDE_FROM_ABI long double exp2(long double __x) _NOEXCEPT {return __builtin_exp2l(__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 +02001128exp2(_A1 __x) _NOEXCEPT {return __builtin_exp2((double)__x);}
Richard Smith081bb592015-10-08 20:40:34 +00001129
1130// expm1
1131
Nikolas Klauser04005952022-10-21 01:41:22 +02001132inline _LIBCPP_HIDE_FROM_ABI float expm1(float __x) _NOEXCEPT {return __builtin_expm1f(__x);}
Nikolas Klauser52399652022-11-01 22:29:57 +01001133
1134template <class = int>
1135_LIBCPP_HIDE_FROM_ABI double expm1(double __x) _NOEXCEPT {
1136 return __builtin_expm1(__x);
1137}
1138
Nikolas Klauser04005952022-10-21 01:41:22 +02001139inline _LIBCPP_HIDE_FROM_ABI long double expm1(long double __x) _NOEXCEPT {return __builtin_expm1l(__x);}
Richard Smith081bb592015-10-08 20:40:34 +00001140
1141template <class _A1>
Nikolas Klauser4956e722022-10-12 15:41:22 +02001142inline _LIBCPP_HIDE_FROM_ABI
Richard Smith081bb592015-10-08 20:40:34 +00001143typename std::enable_if<std::is_integral<_A1>::value, double>::type
Nikolas Klauser04005952022-10-21 01:41:22 +02001144expm1(_A1 __x) _NOEXCEPT {return __builtin_expm1((double)__x);}
Richard Smith081bb592015-10-08 20:40:34 +00001145
1146// fdim
1147
Nikolas Klauser04005952022-10-21 01:41:22 +02001148inline _LIBCPP_HIDE_FROM_ABI float fdim(float __x, float __y) _NOEXCEPT {return __builtin_fdimf(__x, __y);}
Nikolas Klauser52399652022-11-01 22:29:57 +01001149
1150template <class = int>
1151_LIBCPP_HIDE_FROM_ABI double fdim(double __x, double __y) _NOEXCEPT {
1152 return __builtin_fdim(__x, __y);
1153}
1154
Nikolas Klauser04005952022-10-21 01:41:22 +02001155inline _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 +00001156
1157template <class _A1, class _A2>
Nikolas Klauser4956e722022-10-12 15:41:22 +02001158inline _LIBCPP_HIDE_FROM_ABI
Louis Dionne9ce598d2021-09-08 09:14:43 -04001159typename std::__enable_if_t
Richard Smith081bb592015-10-08 20:40:34 +00001160<
1161 std::is_arithmetic<_A1>::value &&
1162 std::is_arithmetic<_A2>::value,
1163 std::__promote<_A1, _A2>
1164>::type
Nikolas Klauser9806f452022-10-12 15:45:09 +02001165fdim(_A1 __x, _A2 __y) _NOEXCEPT
Richard Smith081bb592015-10-08 20:40:34 +00001166{
1167 typedef typename std::__promote<_A1, _A2>::type __result_type;
Eric Fiselier3906a132019-06-23 20:28:29 +00001168 static_assert((!(std::_IsSame<_A1, __result_type>::value &&
1169 std::_IsSame<_A2, __result_type>::value)), "");
Nikolas Klauser9806f452022-10-12 15:45:09 +02001170 return ::fdim((__result_type)__x, (__result_type)__y);
Richard Smith081bb592015-10-08 20:40:34 +00001171}
1172
1173// fma
1174
Nikolas Klauser9806f452022-10-12 15:45:09 +02001175inline _LIBCPP_HIDE_FROM_ABI float fma(float __x, float __y, float __z) _NOEXCEPT
Ilya Tokarc3abffb2021-02-10 13:05:19 -05001176{
Nikolas Klauser9806f452022-10-12 15:45:09 +02001177 return __builtin_fmaf(__x, __y, __z);
Ilya Tokarc3abffb2021-02-10 13:05:19 -05001178}
Nikolas Klauser52399652022-11-01 22:29:57 +01001179
1180
1181template <class = int>
1182_LIBCPP_HIDE_FROM_ABI double fma(double __x, double __y, double __z) _NOEXCEPT {
1183 return __builtin_fma(__x, __y, __z);
1184}
1185
Nikolas Klauser9806f452022-10-12 15:45:09 +02001186inline _LIBCPP_HIDE_FROM_ABI long double fma(long double __x, long double __y, long double __z) _NOEXCEPT
Ilya Tokarc3abffb2021-02-10 13:05:19 -05001187{
Nikolas Klauser9806f452022-10-12 15:45:09 +02001188 return __builtin_fmal(__x, __y, __z);
Ilya Tokarc3abffb2021-02-10 13:05:19 -05001189}
Richard Smith081bb592015-10-08 20:40:34 +00001190
1191template <class _A1, class _A2, class _A3>
Nikolas Klauser4956e722022-10-12 15:41:22 +02001192inline _LIBCPP_HIDE_FROM_ABI
Louis Dionne9ce598d2021-09-08 09:14:43 -04001193typename std::__enable_if_t
Richard Smith081bb592015-10-08 20:40:34 +00001194<
1195 std::is_arithmetic<_A1>::value &&
1196 std::is_arithmetic<_A2>::value &&
1197 std::is_arithmetic<_A3>::value,
1198 std::__promote<_A1, _A2, _A3>
1199>::type
Nikolas Klauser9806f452022-10-12 15:45:09 +02001200fma(_A1 __x, _A2 __y, _A3 __z) _NOEXCEPT
Richard Smith081bb592015-10-08 20:40:34 +00001201{
1202 typedef typename std::__promote<_A1, _A2, _A3>::type __result_type;
Eric Fiselier3906a132019-06-23 20:28:29 +00001203 static_assert((!(std::_IsSame<_A1, __result_type>::value &&
1204 std::_IsSame<_A2, __result_type>::value &&
1205 std::_IsSame<_A3, __result_type>::value)), "");
Nikolas Klauser9806f452022-10-12 15:45:09 +02001206 return __builtin_fma((__result_type)__x, (__result_type)__y, (__result_type)__z);
Richard Smith081bb592015-10-08 20:40:34 +00001207}
1208
1209// fmax
1210
Nikolas Klauser04005952022-10-21 01:41:22 +02001211inline _LIBCPP_HIDE_FROM_ABI float fmax(float __x, float __y) _NOEXCEPT {return __builtin_fmaxf(__x, __y);}
Nikolas Klauser52399652022-11-01 22:29:57 +01001212
1213template <class = int>
1214_LIBCPP_HIDE_FROM_ABI double fmax(double __x, double __y) _NOEXCEPT {
1215 return __builtin_fmax(__x, __y);
1216}
1217
Nikolas Klauser04005952022-10-21 01:41:22 +02001218inline _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 +00001219
1220template <class _A1, class _A2>
Nikolas Klauser4956e722022-10-12 15:41:22 +02001221inline _LIBCPP_HIDE_FROM_ABI
Louis Dionne9ce598d2021-09-08 09:14:43 -04001222typename std::__enable_if_t
Richard Smith081bb592015-10-08 20:40:34 +00001223<
1224 std::is_arithmetic<_A1>::value &&
1225 std::is_arithmetic<_A2>::value,
1226 std::__promote<_A1, _A2>
1227>::type
Nikolas Klauser9806f452022-10-12 15:45:09 +02001228fmax(_A1 __x, _A2 __y) _NOEXCEPT
Richard Smith081bb592015-10-08 20:40:34 +00001229{
1230 typedef typename std::__promote<_A1, _A2>::type __result_type;
Eric Fiselier3906a132019-06-23 20:28:29 +00001231 static_assert((!(std::_IsSame<_A1, __result_type>::value &&
1232 std::_IsSame<_A2, __result_type>::value)), "");
Nikolas Klauser9806f452022-10-12 15:45:09 +02001233 return ::fmax((__result_type)__x, (__result_type)__y);
Richard Smith081bb592015-10-08 20:40:34 +00001234}
1235
1236// fmin
1237
Nikolas Klauser04005952022-10-21 01:41:22 +02001238inline _LIBCPP_HIDE_FROM_ABI float fmin(float __x, float __y) _NOEXCEPT {return __builtin_fminf(__x, __y);}
Nikolas Klauser52399652022-11-01 22:29:57 +01001239
1240template <class = int>
1241_LIBCPP_HIDE_FROM_ABI double fmin(double __x, double __y) _NOEXCEPT {
1242 return __builtin_fmin(__x, __y);
1243}
1244
Nikolas Klauser04005952022-10-21 01:41:22 +02001245inline _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 +00001246
1247template <class _A1, class _A2>
Nikolas Klauser4956e722022-10-12 15:41:22 +02001248inline _LIBCPP_HIDE_FROM_ABI
Louis Dionne9ce598d2021-09-08 09:14:43 -04001249typename std::__enable_if_t
Richard Smith081bb592015-10-08 20:40:34 +00001250<
1251 std::is_arithmetic<_A1>::value &&
1252 std::is_arithmetic<_A2>::value,
1253 std::__promote<_A1, _A2>
1254>::type
Nikolas Klauser9806f452022-10-12 15:45:09 +02001255fmin(_A1 __x, _A2 __y) _NOEXCEPT
Richard Smith081bb592015-10-08 20:40:34 +00001256{
1257 typedef typename std::__promote<_A1, _A2>::type __result_type;
Eric Fiselier3906a132019-06-23 20:28:29 +00001258 static_assert((!(std::_IsSame<_A1, __result_type>::value &&
1259 std::_IsSame<_A2, __result_type>::value)), "");
Nikolas Klauser9806f452022-10-12 15:45:09 +02001260 return ::fmin((__result_type)__x, (__result_type)__y);
Richard Smith081bb592015-10-08 20:40:34 +00001261}
1262
1263// hypot
1264
Nikolas Klauser04005952022-10-21 01:41:22 +02001265inline _LIBCPP_HIDE_FROM_ABI float hypot(float __x, float __y) _NOEXCEPT {return __builtin_hypotf(__x, __y);}
Nikolas Klauser52399652022-11-01 22:29:57 +01001266
1267template <class = int>
1268_LIBCPP_HIDE_FROM_ABI double hypot(double __x, double __y) _NOEXCEPT {
1269 return __builtin_hypot(__x, __y);
1270}
1271
Nikolas Klauser04005952022-10-21 01:41:22 +02001272inline _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 +00001273
1274template <class _A1, class _A2>
Nikolas Klauser4956e722022-10-12 15:41:22 +02001275inline _LIBCPP_HIDE_FROM_ABI
Louis Dionne9ce598d2021-09-08 09:14:43 -04001276typename std::__enable_if_t
Richard Smith081bb592015-10-08 20:40:34 +00001277<
1278 std::is_arithmetic<_A1>::value &&
1279 std::is_arithmetic<_A2>::value,
1280 std::__promote<_A1, _A2>
1281>::type
Nikolas Klauser9806f452022-10-12 15:45:09 +02001282hypot(_A1 __x, _A2 __y) _NOEXCEPT
Richard Smith081bb592015-10-08 20:40:34 +00001283{
1284 typedef typename std::__promote<_A1, _A2>::type __result_type;
Eric Fiselier3906a132019-06-23 20:28:29 +00001285 static_assert((!(std::_IsSame<_A1, __result_type>::value &&
1286 std::_IsSame<_A2, __result_type>::value)), "");
Nikolas Klauser9806f452022-10-12 15:45:09 +02001287 return ::hypot((__result_type)__x, (__result_type)__y);
Richard Smith081bb592015-10-08 20:40:34 +00001288}
1289
1290// ilogb
1291
Nikolas Klauser04005952022-10-21 01:41:22 +02001292inline _LIBCPP_HIDE_FROM_ABI int ilogb(float __x) _NOEXCEPT {return __builtin_ilogbf(__x);}
Nikolas Klauser52399652022-11-01 22:29:57 +01001293
1294template <class = int>
1295_LIBCPP_HIDE_FROM_ABI double ilogb(double __x) _NOEXCEPT {
1296 return __builtin_ilogb(__x);
1297}
1298
Nikolas Klauser04005952022-10-21 01:41:22 +02001299inline _LIBCPP_HIDE_FROM_ABI int ilogb(long double __x) _NOEXCEPT {return __builtin_ilogbl(__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, int>::type
Nikolas Klauser04005952022-10-21 01:41:22 +02001304ilogb(_A1 __x) _NOEXCEPT {return __builtin_ilogb((double)__x);}
Richard Smith081bb592015-10-08 20:40:34 +00001305
1306// lgamma
1307
Nikolas Klauser04005952022-10-21 01:41:22 +02001308inline _LIBCPP_HIDE_FROM_ABI float lgamma(float __x) _NOEXCEPT {return __builtin_lgammaf(__x);}
Nikolas Klauser52399652022-11-01 22:29:57 +01001309
1310template <class = int>
1311_LIBCPP_HIDE_FROM_ABI double lgamma(double __x) _NOEXCEPT {
1312 return __builtin_lgamma(__x);
1313}
1314
Nikolas Klauser04005952022-10-21 01:41:22 +02001315inline _LIBCPP_HIDE_FROM_ABI long double lgamma(long double __x) _NOEXCEPT {return __builtin_lgammal(__x);}
Richard Smith081bb592015-10-08 20:40:34 +00001316
1317template <class _A1>
Nikolas Klauser4956e722022-10-12 15:41:22 +02001318inline _LIBCPP_HIDE_FROM_ABI
Richard Smith081bb592015-10-08 20:40:34 +00001319typename std::enable_if<std::is_integral<_A1>::value, double>::type
Nikolas Klauser04005952022-10-21 01:41:22 +02001320lgamma(_A1 __x) _NOEXCEPT {return __builtin_lgamma((double)__x);}
Richard Smith081bb592015-10-08 20:40:34 +00001321
1322// llrint
1323
Nikolas Klauser9806f452022-10-12 15:45:09 +02001324inline _LIBCPP_HIDE_FROM_ABI long long llrint(float __x) _NOEXCEPT
Ilya Tokarc3abffb2021-02-10 13:05:19 -05001325{
Nikolas Klauser9806f452022-10-12 15:45:09 +02001326 return __builtin_llrintf(__x);
Ilya Tokarc3abffb2021-02-10 13:05:19 -05001327}
Nikolas Klauser52399652022-11-01 22:29:57 +01001328
1329template <class = int>
1330_LIBCPP_HIDE_FROM_ABI long long llrint(double __x) _NOEXCEPT {
1331 return __builtin_llrint(__x);
1332}
1333
Nikolas Klauser9806f452022-10-12 15:45:09 +02001334inline _LIBCPP_HIDE_FROM_ABI long long llrint(long double __x) _NOEXCEPT
Ilya Tokarc3abffb2021-02-10 13:05:19 -05001335{
Nikolas Klauser9806f452022-10-12 15:45:09 +02001336 return __builtin_llrintl(__x);
Ilya Tokarc3abffb2021-02-10 13:05:19 -05001337}
Richard Smith081bb592015-10-08 20:40:34 +00001338
1339template <class _A1>
Nikolas Klauser4956e722022-10-12 15:41:22 +02001340inline _LIBCPP_HIDE_FROM_ABI
Richard Smith081bb592015-10-08 20:40:34 +00001341typename std::enable_if<std::is_integral<_A1>::value, long long>::type
Nikolas Klauser9806f452022-10-12 15:45:09 +02001342llrint(_A1 __x) _NOEXCEPT
Ilya Tokarc3abffb2021-02-10 13:05:19 -05001343{
Nikolas Klauser9806f452022-10-12 15:45:09 +02001344 return __builtin_llrint((double)__x);
Ilya Tokarc3abffb2021-02-10 13:05:19 -05001345}
Richard Smith081bb592015-10-08 20:40:34 +00001346
1347// llround
1348
Nikolas Klauser9806f452022-10-12 15:45:09 +02001349inline _LIBCPP_HIDE_FROM_ABI long long llround(float __x) _NOEXCEPT
Ilya Tokarc3abffb2021-02-10 13:05:19 -05001350{
Nikolas Klauser9806f452022-10-12 15:45:09 +02001351 return __builtin_llroundf(__x);
Ilya Tokarc3abffb2021-02-10 13:05:19 -05001352}
Nikolas Klauser52399652022-11-01 22:29:57 +01001353
1354template <class = int>
1355_LIBCPP_HIDE_FROM_ABI long long llround(double __x) _NOEXCEPT {
1356 return __builtin_llround(__x);
1357}
1358
Nikolas Klauser9806f452022-10-12 15:45:09 +02001359inline _LIBCPP_HIDE_FROM_ABI long long llround(long double __x) _NOEXCEPT
Ilya Tokarc3abffb2021-02-10 13:05:19 -05001360{
Nikolas Klauser9806f452022-10-12 15:45:09 +02001361 return __builtin_llroundl(__x);
Ilya Tokarc3abffb2021-02-10 13:05:19 -05001362}
Richard Smith081bb592015-10-08 20:40:34 +00001363
1364template <class _A1>
Nikolas Klauser4956e722022-10-12 15:41:22 +02001365inline _LIBCPP_HIDE_FROM_ABI
Richard Smith081bb592015-10-08 20:40:34 +00001366typename std::enable_if<std::is_integral<_A1>::value, long long>::type
Nikolas Klauser9806f452022-10-12 15:45:09 +02001367llround(_A1 __x) _NOEXCEPT
Ilya Tokarc3abffb2021-02-10 13:05:19 -05001368{
Nikolas Klauser9806f452022-10-12 15:45:09 +02001369 return __builtin_llround((double)__x);
Ilya Tokarc3abffb2021-02-10 13:05:19 -05001370}
Richard Smith081bb592015-10-08 20:40:34 +00001371
1372// log1p
1373
Nikolas Klauser04005952022-10-21 01:41:22 +02001374inline _LIBCPP_HIDE_FROM_ABI float log1p(float __x) _NOEXCEPT {return __builtin_log1pf(__x);}
Nikolas Klauser52399652022-11-01 22:29:57 +01001375
1376template <class = int>
1377_LIBCPP_HIDE_FROM_ABI double log1p(double __x) _NOEXCEPT {
1378 return __builtin_log1p(__x);
1379}
1380
Nikolas Klauser04005952022-10-21 01:41:22 +02001381inline _LIBCPP_HIDE_FROM_ABI long double log1p(long double __x) _NOEXCEPT {return __builtin_log1pl(__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 +02001386log1p(_A1 __x) _NOEXCEPT {return __builtin_log1p((double)__x);}
Richard Smith081bb592015-10-08 20:40:34 +00001387
1388// log2
1389
Nikolas Klauser04005952022-10-21 01:41:22 +02001390inline _LIBCPP_HIDE_FROM_ABI float log2(float __x) _NOEXCEPT {return __builtin_log2f(__x);}
Nikolas Klauser52399652022-11-01 22:29:57 +01001391
1392template <class = int>
1393_LIBCPP_HIDE_FROM_ABI double log2(double __x) _NOEXCEPT {
1394 return __builtin_log2(__x);
1395}
1396
Nikolas Klauser04005952022-10-21 01:41:22 +02001397inline _LIBCPP_HIDE_FROM_ABI long double log2(long double __x) _NOEXCEPT {return __builtin_log2l(__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 +02001402log2(_A1 __x) _NOEXCEPT {return __builtin_log2((double)__x);}
Richard Smith081bb592015-10-08 20:40:34 +00001403
1404// logb
1405
Nikolas Klauser04005952022-10-21 01:41:22 +02001406inline _LIBCPP_HIDE_FROM_ABI float logb(float __x) _NOEXCEPT {return __builtin_logbf(__x);}
Nikolas Klauser52399652022-11-01 22:29:57 +01001407
1408template <class = int>
1409_LIBCPP_HIDE_FROM_ABI double logb(double __x) _NOEXCEPT {
1410 return __builtin_logb(__x);
1411}
1412
Nikolas Klauser04005952022-10-21 01:41:22 +02001413inline _LIBCPP_HIDE_FROM_ABI long double logb(long double __x) _NOEXCEPT {return __builtin_logbl(__x);}
Richard Smith081bb592015-10-08 20:40:34 +00001414
1415template <class _A1>
Nikolas Klauser4956e722022-10-12 15:41:22 +02001416inline _LIBCPP_HIDE_FROM_ABI
Richard Smith081bb592015-10-08 20:40:34 +00001417typename std::enable_if<std::is_integral<_A1>::value, double>::type
Nikolas Klauser04005952022-10-21 01:41:22 +02001418logb(_A1 __x) _NOEXCEPT {return __builtin_logb((double)__x);}
Richard Smith081bb592015-10-08 20:40:34 +00001419
1420// lrint
1421
Nikolas Klauser9806f452022-10-12 15:45:09 +02001422inline _LIBCPP_HIDE_FROM_ABI long lrint(float __x) _NOEXCEPT
Ilya Tokarc3abffb2021-02-10 13:05:19 -05001423{
Nikolas Klauser9806f452022-10-12 15:45:09 +02001424 return __builtin_lrintf(__x);
Ilya Tokarc3abffb2021-02-10 13:05:19 -05001425}
Nikolas Klauser52399652022-11-01 22:29:57 +01001426
1427template <class = int>
1428_LIBCPP_HIDE_FROM_ABI long lrint(double __x) _NOEXCEPT {
1429 return __builtin_lrint(__x);
1430}
1431
Nikolas Klauser9806f452022-10-12 15:45:09 +02001432inline _LIBCPP_HIDE_FROM_ABI long lrint(long double __x) _NOEXCEPT
Ilya Tokarc3abffb2021-02-10 13:05:19 -05001433{
Nikolas Klauser9806f452022-10-12 15:45:09 +02001434 return __builtin_lrintl(__x);
Ilya Tokarc3abffb2021-02-10 13:05:19 -05001435}
Richard Smith081bb592015-10-08 20:40:34 +00001436
1437template <class _A1>
Nikolas Klauser4956e722022-10-12 15:41:22 +02001438inline _LIBCPP_HIDE_FROM_ABI
Richard Smith081bb592015-10-08 20:40:34 +00001439typename std::enable_if<std::is_integral<_A1>::value, long>::type
Nikolas Klauser9806f452022-10-12 15:45:09 +02001440lrint(_A1 __x) _NOEXCEPT
Ilya Tokarc3abffb2021-02-10 13:05:19 -05001441{
Nikolas Klauser9806f452022-10-12 15:45:09 +02001442 return __builtin_lrint((double)__x);
Ilya Tokarc3abffb2021-02-10 13:05:19 -05001443}
Richard Smith081bb592015-10-08 20:40:34 +00001444
1445// lround
1446
Nikolas Klauser9806f452022-10-12 15:45:09 +02001447inline _LIBCPP_HIDE_FROM_ABI long lround(float __x) _NOEXCEPT
Ilya Tokarc3abffb2021-02-10 13:05:19 -05001448{
Nikolas Klauser9806f452022-10-12 15:45:09 +02001449 return __builtin_lroundf(__x);
Ilya Tokarc3abffb2021-02-10 13:05:19 -05001450}
Nikolas Klauser52399652022-11-01 22:29:57 +01001451
1452template <class = int>
1453_LIBCPP_HIDE_FROM_ABI long lround(double __x) _NOEXCEPT {
1454 return __builtin_lround(__x);
1455}
1456
Nikolas Klauser9806f452022-10-12 15:45:09 +02001457inline _LIBCPP_HIDE_FROM_ABI long lround(long double __x) _NOEXCEPT
Ilya Tokarc3abffb2021-02-10 13:05:19 -05001458{
Nikolas Klauser9806f452022-10-12 15:45:09 +02001459 return __builtin_lroundl(__x);
Ilya Tokarc3abffb2021-02-10 13:05:19 -05001460}
Richard Smith081bb592015-10-08 20:40:34 +00001461
1462template <class _A1>
Nikolas Klauser4956e722022-10-12 15:41:22 +02001463inline _LIBCPP_HIDE_FROM_ABI
Richard Smith081bb592015-10-08 20:40:34 +00001464typename std::enable_if<std::is_integral<_A1>::value, long>::type
Nikolas Klauser9806f452022-10-12 15:45:09 +02001465lround(_A1 __x) _NOEXCEPT
Ilya Tokarc3abffb2021-02-10 13:05:19 -05001466{
Nikolas Klauser9806f452022-10-12 15:45:09 +02001467 return __builtin_lround((double)__x);
Ilya Tokarc3abffb2021-02-10 13:05:19 -05001468}
Richard Smith081bb592015-10-08 20:40:34 +00001469
1470// nan
1471
1472// nearbyint
1473
Nikolas Klauser04005952022-10-21 01:41:22 +02001474inline _LIBCPP_HIDE_FROM_ABI float nearbyint(float __x) _NOEXCEPT {return __builtin_nearbyintf(__x);}
Nikolas Klauser52399652022-11-01 22:29:57 +01001475
1476template <class = int>
1477_LIBCPP_HIDE_FROM_ABI double nearbyint(double __x) _NOEXCEPT {
1478 return __builtin_nearbyint(__x);
1479}
1480
Nikolas Klauser04005952022-10-21 01:41:22 +02001481inline _LIBCPP_HIDE_FROM_ABI long double nearbyint(long double __x) _NOEXCEPT {return __builtin_nearbyintl(__x);}
Richard Smith081bb592015-10-08 20:40:34 +00001482
1483template <class _A1>
Nikolas Klauser4956e722022-10-12 15:41:22 +02001484inline _LIBCPP_HIDE_FROM_ABI
Richard Smith081bb592015-10-08 20:40:34 +00001485typename std::enable_if<std::is_integral<_A1>::value, double>::type
Nikolas Klauser04005952022-10-21 01:41:22 +02001486nearbyint(_A1 __x) _NOEXCEPT {return __builtin_nearbyint((double)__x);}
Richard Smith081bb592015-10-08 20:40:34 +00001487
1488// nextafter
1489
Nikolas Klauser04005952022-10-21 01:41:22 +02001490inline _LIBCPP_HIDE_FROM_ABI float nextafter(float __x, float __y) _NOEXCEPT {return __builtin_nextafterf(__x, __y);}
Nikolas Klauser52399652022-11-01 22:29:57 +01001491
1492template <class = int>
1493_LIBCPP_HIDE_FROM_ABI double nextafter(double __x, double __y) _NOEXCEPT {
1494 return __builtin_nextafter(__x, __y);
1495}
1496
Nikolas Klauser04005952022-10-21 01:41:22 +02001497inline _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 +00001498
1499template <class _A1, class _A2>
Nikolas Klauser4956e722022-10-12 15:41:22 +02001500inline _LIBCPP_HIDE_FROM_ABI
Louis Dionne9ce598d2021-09-08 09:14:43 -04001501typename std::__enable_if_t
Richard Smith081bb592015-10-08 20:40:34 +00001502<
1503 std::is_arithmetic<_A1>::value &&
1504 std::is_arithmetic<_A2>::value,
1505 std::__promote<_A1, _A2>
1506>::type
Nikolas Klauser9806f452022-10-12 15:45:09 +02001507nextafter(_A1 __x, _A2 __y) _NOEXCEPT
Richard Smith081bb592015-10-08 20:40:34 +00001508{
1509 typedef typename std::__promote<_A1, _A2>::type __result_type;
Eric Fiselier3906a132019-06-23 20:28:29 +00001510 static_assert((!(std::_IsSame<_A1, __result_type>::value &&
1511 std::_IsSame<_A2, __result_type>::value)), "");
Nikolas Klauser9806f452022-10-12 15:45:09 +02001512 return ::nextafter((__result_type)__x, (__result_type)__y);
Richard Smith081bb592015-10-08 20:40:34 +00001513}
1514
1515// nexttoward
1516
Nikolas Klauser04005952022-10-21 01:41:22 +02001517inline _LIBCPP_HIDE_FROM_ABI float nexttoward(float __x, long double __y) _NOEXCEPT {return __builtin_nexttowardf(__x, __y);}
Nikolas Klauser52399652022-11-01 22:29:57 +01001518
1519template <class = int>
1520_LIBCPP_HIDE_FROM_ABI double nexttoward(double __x, long double __y) _NOEXCEPT {
1521 return __builtin_nexttoward(__x, __y);
1522}
1523
Nikolas Klauser04005952022-10-21 01:41:22 +02001524inline _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 +00001525
1526template <class _A1>
Nikolas Klauser4956e722022-10-12 15:41:22 +02001527inline _LIBCPP_HIDE_FROM_ABI
Richard Smith081bb592015-10-08 20:40:34 +00001528typename std::enable_if<std::is_integral<_A1>::value, double>::type
Nikolas Klauser04005952022-10-21 01:41:22 +02001529nexttoward(_A1 __x, long double __y) _NOEXCEPT {return __builtin_nexttoward((double)__x, __y);}
Richard Smith081bb592015-10-08 20:40:34 +00001530
1531// remainder
1532
Nikolas Klauser04005952022-10-21 01:41:22 +02001533inline _LIBCPP_HIDE_FROM_ABI float remainder(float __x, float __y) _NOEXCEPT {return __builtin_remainderf(__x, __y);}
Nikolas Klauser52399652022-11-01 22:29:57 +01001534
1535template <class = int>
1536_LIBCPP_HIDE_FROM_ABI double remainder(double __x, double __y) _NOEXCEPT {
1537 return __builtin_remainder(__x, __y);
1538}
1539
Nikolas Klauser04005952022-10-21 01:41:22 +02001540inline _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 +00001541
1542template <class _A1, class _A2>
Nikolas Klauser4956e722022-10-12 15:41:22 +02001543inline _LIBCPP_HIDE_FROM_ABI
Louis Dionne9ce598d2021-09-08 09:14:43 -04001544typename std::__enable_if_t
Richard Smith081bb592015-10-08 20:40:34 +00001545<
1546 std::is_arithmetic<_A1>::value &&
1547 std::is_arithmetic<_A2>::value,
1548 std::__promote<_A1, _A2>
1549>::type
Nikolas Klauser9806f452022-10-12 15:45:09 +02001550remainder(_A1 __x, _A2 __y) _NOEXCEPT
Richard Smith081bb592015-10-08 20:40:34 +00001551{
1552 typedef typename std::__promote<_A1, _A2>::type __result_type;
Eric Fiselier3906a132019-06-23 20:28:29 +00001553 static_assert((!(std::_IsSame<_A1, __result_type>::value &&
1554 std::_IsSame<_A2, __result_type>::value)), "");
Nikolas Klauser9806f452022-10-12 15:45:09 +02001555 return ::remainder((__result_type)__x, (__result_type)__y);
Richard Smith081bb592015-10-08 20:40:34 +00001556}
1557
1558// remquo
1559
Nikolas Klauser04005952022-10-21 01:41:22 +02001560inline _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 +01001561
1562template <class = int>
1563_LIBCPP_HIDE_FROM_ABI double remquo(double __x, double __y, int* __z) _NOEXCEPT {
1564 return __builtin_remquo(__x, __y, __z);
1565}
1566
Nikolas Klauser04005952022-10-21 01:41:22 +02001567inline _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 +00001568
1569template <class _A1, class _A2>
Nikolas Klauser4956e722022-10-12 15:41:22 +02001570inline _LIBCPP_HIDE_FROM_ABI
Louis Dionne9ce598d2021-09-08 09:14:43 -04001571typename std::__enable_if_t
Richard Smith081bb592015-10-08 20:40:34 +00001572<
1573 std::is_arithmetic<_A1>::value &&
1574 std::is_arithmetic<_A2>::value,
1575 std::__promote<_A1, _A2>
1576>::type
Nikolas Klauser9806f452022-10-12 15:45:09 +02001577remquo(_A1 __x, _A2 __y, int* __z) _NOEXCEPT
Richard Smith081bb592015-10-08 20:40:34 +00001578{
1579 typedef typename std::__promote<_A1, _A2>::type __result_type;
Eric Fiselier3906a132019-06-23 20:28:29 +00001580 static_assert((!(std::_IsSame<_A1, __result_type>::value &&
1581 std::_IsSame<_A2, __result_type>::value)), "");
Nikolas Klauser9806f452022-10-12 15:45:09 +02001582 return ::remquo((__result_type)__x, (__result_type)__y, __z);
Richard Smith081bb592015-10-08 20:40:34 +00001583}
1584
1585// rint
1586
Nikolas Klauser9806f452022-10-12 15:45:09 +02001587inline _LIBCPP_HIDE_FROM_ABI float rint(float __x) _NOEXCEPT
Ilya Tokarc3abffb2021-02-10 13:05:19 -05001588{
Nikolas Klauser9806f452022-10-12 15:45:09 +02001589 return __builtin_rintf(__x);
Ilya Tokarc3abffb2021-02-10 13:05:19 -05001590}
Nikolas Klauser52399652022-11-01 22:29:57 +01001591
1592template <class = int>
1593_LIBCPP_HIDE_FROM_ABI double rint(double __x) _NOEXCEPT {
1594 return __builtin_rint(__x);
1595}
1596
Nikolas Klauser9806f452022-10-12 15:45:09 +02001597inline _LIBCPP_HIDE_FROM_ABI long double rint(long double __x) _NOEXCEPT
Ilya Tokarc3abffb2021-02-10 13:05:19 -05001598{
Nikolas Klauser9806f452022-10-12 15:45:09 +02001599 return __builtin_rintl(__x);
Ilya Tokarc3abffb2021-02-10 13:05:19 -05001600}
Richard Smith081bb592015-10-08 20:40:34 +00001601
1602template <class _A1>
Nikolas Klauser4956e722022-10-12 15:41:22 +02001603inline _LIBCPP_HIDE_FROM_ABI
Richard Smith081bb592015-10-08 20:40:34 +00001604typename std::enable_if<std::is_integral<_A1>::value, double>::type
Nikolas Klauser9806f452022-10-12 15:45:09 +02001605rint(_A1 __x) _NOEXCEPT
Ilya Tokarc3abffb2021-02-10 13:05:19 -05001606{
Nikolas Klauser9806f452022-10-12 15:45:09 +02001607 return __builtin_rint((double)__x);
Ilya Tokarc3abffb2021-02-10 13:05:19 -05001608}
Richard Smith081bb592015-10-08 20:40:34 +00001609
1610// round
1611
Nikolas Klauser9806f452022-10-12 15:45:09 +02001612inline _LIBCPP_HIDE_FROM_ABI float round(float __x) _NOEXCEPT
Ilya Tokarc3abffb2021-02-10 13:05:19 -05001613{
Nikolas Klauser9806f452022-10-12 15:45:09 +02001614 return __builtin_round(__x);
Ilya Tokarc3abffb2021-02-10 13:05:19 -05001615}
Nikolas Klauser52399652022-11-01 22:29:57 +01001616
1617template <class = int>
1618_LIBCPP_HIDE_FROM_ABI double round(double __x) _NOEXCEPT {
1619 return __builtin_round(__x);
1620}
1621
Nikolas Klauser9806f452022-10-12 15:45:09 +02001622inline _LIBCPP_HIDE_FROM_ABI long double round(long double __x) _NOEXCEPT
Ilya Tokarc3abffb2021-02-10 13:05:19 -05001623{
Nikolas Klauser9806f452022-10-12 15:45:09 +02001624 return __builtin_roundl(__x);
Ilya Tokarc3abffb2021-02-10 13:05:19 -05001625}
Richard Smith081bb592015-10-08 20:40:34 +00001626
1627template <class _A1>
Nikolas Klauser4956e722022-10-12 15:41:22 +02001628inline _LIBCPP_HIDE_FROM_ABI
Richard Smith081bb592015-10-08 20:40:34 +00001629typename std::enable_if<std::is_integral<_A1>::value, double>::type
Nikolas Klauser9806f452022-10-12 15:45:09 +02001630round(_A1 __x) _NOEXCEPT
Ilya Tokarc3abffb2021-02-10 13:05:19 -05001631{
Nikolas Klauser9806f452022-10-12 15:45:09 +02001632 return __builtin_round((double)__x);
Ilya Tokarc3abffb2021-02-10 13:05:19 -05001633}
Richard Smith081bb592015-10-08 20:40:34 +00001634
1635// scalbln
1636
Nikolas Klauser04005952022-10-21 01:41:22 +02001637inline _LIBCPP_HIDE_FROM_ABI float scalbln(float __x, long __y) _NOEXCEPT {return __builtin_scalblnf(__x, __y);}
Nikolas Klauser52399652022-11-01 22:29:57 +01001638
1639template <class = int>
1640_LIBCPP_HIDE_FROM_ABI double scalbln(double __x, long __y) _NOEXCEPT {
1641 return __builtin_scalbln(__x, __y);
1642}
1643
Nikolas Klauser04005952022-10-21 01:41:22 +02001644inline _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 +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 +02001649scalbln(_A1 __x, long __y) _NOEXCEPT {return __builtin_scalbln((double)__x, __y);}
Richard Smith081bb592015-10-08 20:40:34 +00001650
1651// scalbn
1652
Nikolas Klauser04005952022-10-21 01:41:22 +02001653inline _LIBCPP_HIDE_FROM_ABI float scalbn(float __x, int __y) _NOEXCEPT {return __builtin_scalbnf(__x, __y);}
Nikolas Klauser52399652022-11-01 22:29:57 +01001654
1655template <class = int>
1656_LIBCPP_HIDE_FROM_ABI double scalbn(double __x, int __y) _NOEXCEPT {
1657 return __builtin_scalbn(__x, __y);
1658}
1659
Nikolas Klauser04005952022-10-21 01:41:22 +02001660inline _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 +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 +02001665scalbn(_A1 __x, int __y) _NOEXCEPT {return __builtin_scalbn((double)__x, __y);}
Richard Smith081bb592015-10-08 20:40:34 +00001666
1667// tgamma
1668
Nikolas Klauser04005952022-10-21 01:41:22 +02001669inline _LIBCPP_HIDE_FROM_ABI float tgamma(float __x) _NOEXCEPT {return __builtin_tgammaf(__x);}
Nikolas Klauser52399652022-11-01 22:29:57 +01001670
1671template <class = int>
1672_LIBCPP_HIDE_FROM_ABI double tgamma(double __x) _NOEXCEPT {
1673 return __builtin_tgamma(__x);
1674}
1675
Nikolas Klauser04005952022-10-21 01:41:22 +02001676inline _LIBCPP_HIDE_FROM_ABI long double tgamma(long double __x) _NOEXCEPT {return __builtin_tgammal(__x);}
Richard Smith081bb592015-10-08 20:40:34 +00001677
1678template <class _A1>
Nikolas Klauser4956e722022-10-12 15:41:22 +02001679inline _LIBCPP_HIDE_FROM_ABI
Richard Smith081bb592015-10-08 20:40:34 +00001680typename std::enable_if<std::is_integral<_A1>::value, double>::type
Nikolas Klauser04005952022-10-21 01:41:22 +02001681tgamma(_A1 __x) _NOEXCEPT {return __builtin_tgamma((double)__x);}
Richard Smith081bb592015-10-08 20:40:34 +00001682
1683// trunc
1684
Nikolas Klauser9806f452022-10-12 15:45:09 +02001685inline _LIBCPP_HIDE_FROM_ABI float trunc(float __x) _NOEXCEPT
Ilya Tokarc3abffb2021-02-10 13:05:19 -05001686{
Nikolas Klauser9806f452022-10-12 15:45:09 +02001687 return __builtin_trunc(__x);
Ilya Tokarc3abffb2021-02-10 13:05:19 -05001688}
Nikolas Klauser52399652022-11-01 22:29:57 +01001689
1690template <class = int>
1691_LIBCPP_HIDE_FROM_ABI double trunc(double __x) _NOEXCEPT {
1692 return __builtin_trunc(__x);
1693}
1694
Nikolas Klauser9806f452022-10-12 15:45:09 +02001695inline _LIBCPP_HIDE_FROM_ABI long double trunc(long double __x) _NOEXCEPT
Ilya Tokarc3abffb2021-02-10 13:05:19 -05001696{
Nikolas Klauser9806f452022-10-12 15:45:09 +02001697 return __builtin_truncl(__x);
Ilya Tokarc3abffb2021-02-10 13:05:19 -05001698}
Richard Smith081bb592015-10-08 20:40:34 +00001699
1700template <class _A1>
Nikolas Klauser4956e722022-10-12 15:41:22 +02001701inline _LIBCPP_HIDE_FROM_ABI
Richard Smith081bb592015-10-08 20:40:34 +00001702typename std::enable_if<std::is_integral<_A1>::value, double>::type
Nikolas Klauser9806f452022-10-12 15:45:09 +02001703trunc(_A1 __x) _NOEXCEPT
Ilya Tokarc3abffb2021-02-10 13:05:19 -05001704{
Nikolas Klauser9806f452022-10-12 15:45:09 +02001705 return __builtin_trunc((double)__x);
Ilya Tokarc3abffb2021-02-10 13:05:19 -05001706}
Richard Smith081bb592015-10-08 20:40:34 +00001707
Richard Smith081bb592015-10-08 20:40:34 +00001708} // extern "C++"
1709
1710#endif // __cplusplus
1711
Mikhail Maltsev34b4f972018-02-22 09:34:08 +00001712#else // _LIBCPP_MATH_H
1713
1714// This include lives outside the header guard in order to support an MSVC
1715// extension which allows users to do:
1716//
1717// #define _USE_MATH_DEFINES
1718// #include <math.h>
1719//
1720// and receive the definitions of mathematical constants, even if <math.h>
1721// has previously been included.
1722#if defined(_LIBCPP_MSVCRT) && defined(_USE_MATH_DEFINES)
1723#include_next <math.h>
1724#endif
1725
Louis Dionne2b1ceaa2021-04-20 12:03:32 -04001726#endif // _LIBCPP_MATH_H