blob: dd688307b6dd01686f7cabefab97c39c809912ab [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>
403inline _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>
409inline _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>
417inline _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 Klauser4956e722022-10-12 15:41:22 +0200422inline _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 Klauser25fbc472022-11-04 16:56:51 +0100429inline _LIBCPP_HIDE_FROM_ABI bool isinf(float __x) _NOEXCEPT { return __builtin_isinf(__x); }
Richard Smithafccfd32018-05-01 03:05:40 +0000430
Nikolas Klauser25fbc472022-11-04 16:56:51 +0100431inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_PREFERRED_OVERLOAD bool isinf(double __x) _NOEXCEPT { return __builtin_isinf(__x); }
Richard Smithafccfd32018-05-01 03:05:40 +0000432
Nikolas Klauser25fbc472022-11-04 16:56:51 +0100433inline _LIBCPP_HIDE_FROM_ABI bool isinf(long double __x) _NOEXCEPT { return __builtin_isinf(__x); }
Nikolas Klauser9a97dd72022-11-04 16:36:34 +0100434# endif
Richard Smithafccfd32018-05-01 03:05:40 +0000435
Richard Smith081bb592015-10-08 20:40:34 +0000436// isnan
437
Nikolas Klausere96070f2022-11-04 20:08:56 +0100438template <class _A1, std::__enable_if_t<std::is_floating_point<_A1>::value, int> = 0>
439inline _LIBCPP_HIDE_FROM_ABI bool isnan(_A1 __x) _NOEXCEPT {
Nikolas Klauser25fbc472022-11-04 16:56:51 +0100440 return __builtin_isnan(__x);
Richard Smith081bb592015-10-08 20:40:34 +0000441}
442
Nikolas Klausere96070f2022-11-04 20:08:56 +0100443template <class _A1, std::__enable_if_t<std::is_integral<_A1>::value, int> = 0>
444inline _LIBCPP_HIDE_FROM_ABI bool isnan(_A1) _NOEXCEPT {
Nikolas Klauser9a97dd72022-11-04 16:36:34 +0100445 return false;
446}
Duncan P. N. Exon Smith321d6bf2017-04-21 23:14:55 +0000447
Nikolas Klauser9a97dd72022-11-04 16:36:34 +0100448# ifdef _LIBCPP_PREFERRED_OVERLOAD
Nikolas Klauser25fbc472022-11-04 16:56:51 +0100449inline _LIBCPP_HIDE_FROM_ABI bool isnan(float __x) _NOEXCEPT { return __builtin_isnan(__x); }
Richard Smithafccfd32018-05-01 03:05:40 +0000450
Nikolas Klauser25fbc472022-11-04 16:56:51 +0100451inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_PREFERRED_OVERLOAD bool isnan(double __x) _NOEXCEPT { return __builtin_isnan(__x); }
Richard Smithafccfd32018-05-01 03:05:40 +0000452
Nikolas Klauser25fbc472022-11-04 16:56:51 +0100453inline _LIBCPP_HIDE_FROM_ABI bool isnan(long double __x) _NOEXCEPT { return __builtin_isnan(__x); }
Nikolas Klauser9a97dd72022-11-04 16:36:34 +0100454# endif
Richard Smithafccfd32018-05-01 03:05:40 +0000455
Richard Smith081bb592015-10-08 20:40:34 +0000456// isnormal
457
Nikolas Klausere96070f2022-11-04 20:08:56 +0100458template <class _A1, std::__enable_if_t<std::is_floating_point<_A1>::value, int> = 0>
459inline _LIBCPP_HIDE_FROM_ABI bool isnormal(_A1 __x) _NOEXCEPT {
Nikolas Klauser25fbc472022-11-04 16:56:51 +0100460 return __builtin_isnormal(__x);
Richard Smith081bb592015-10-08 20:40:34 +0000461}
462
Nikolas Klausere96070f2022-11-04 20:08:56 +0100463template <class _A1, std::__enable_if_t<std::is_integral<_A1>::value, int> = 0>
464inline _LIBCPP_HIDE_FROM_ABI bool isnormal(_A1 __x) _NOEXCEPT {
Nikolas Klauser9a97dd72022-11-04 16:36:34 +0100465 return __x != 0;
466}
Duncan P. N. Exon Smith321d6bf2017-04-21 23:14:55 +0000467
Richard Smith081bb592015-10-08 20:40:34 +0000468// isgreater
469
Nikolas Klausere96070f2022-11-04 20:08:56 +0100470template <class _A1,
471 class _A2,
472 std::__enable_if_t<std::is_arithmetic<_A1>::value && std::is_arithmetic<_A2>::value, int> = 0>
473inline _LIBCPP_HIDE_FROM_ABI bool isgreater(_A1 __x, _A2 __y) _NOEXCEPT {
Nikolas Klauser9a97dd72022-11-04 16:36:34 +0100474 typedef typename std::__promote<_A1, _A2>::type type;
Nikolas Klauser25fbc472022-11-04 16:56:51 +0100475 return __builtin_isgreater((type)__x, (type)__y);
Richard Smith081bb592015-10-08 20:40:34 +0000476}
477
Richard Smith081bb592015-10-08 20:40:34 +0000478// isgreaterequal
479
Nikolas Klausere96070f2022-11-04 20:08:56 +0100480template <class _A1,
481 class _A2,
482 std::__enable_if_t<std::is_arithmetic<_A1>::value && std::is_arithmetic<_A2>::value, int> = 0>
483inline _LIBCPP_HIDE_FROM_ABI bool isgreaterequal(_A1 __x, _A2 __y) _NOEXCEPT {
Nikolas Klauser9a97dd72022-11-04 16:36:34 +0100484 typedef typename std::__promote<_A1, _A2>::type type;
Nikolas Klauser25fbc472022-11-04 16:56:51 +0100485 return __builtin_isgreaterequal((type)__x, (type)__y);
Richard Smith081bb592015-10-08 20:40:34 +0000486}
487
Richard Smith081bb592015-10-08 20:40:34 +0000488// isless
489
Nikolas Klausere96070f2022-11-04 20:08:56 +0100490template <class _A1,
491 class _A2,
492 std::__enable_if_t<std::is_arithmetic<_A1>::value && std::is_arithmetic<_A2>::value, int> = 0>
493inline _LIBCPP_HIDE_FROM_ABI bool isless(_A1 __x, _A2 __y) _NOEXCEPT {
Nikolas Klauser9a97dd72022-11-04 16:36:34 +0100494 typedef typename std::__promote<_A1, _A2>::type type;
Nikolas Klauser25fbc472022-11-04 16:56:51 +0100495 return __builtin_isless((type)__x, (type)__y);
Richard Smith081bb592015-10-08 20:40:34 +0000496}
497
Richard Smith081bb592015-10-08 20:40:34 +0000498// islessequal
499
Nikolas Klausere96070f2022-11-04 20:08:56 +0100500template <class _A1,
501 class _A2,
502 std::__enable_if_t<std::is_arithmetic<_A1>::value && std::is_arithmetic<_A2>::value, int> = 0>
503inline _LIBCPP_HIDE_FROM_ABI bool islessequal(_A1 __x, _A2 __y) _NOEXCEPT {
Nikolas Klauser9a97dd72022-11-04 16:36:34 +0100504 typedef typename std::__promote<_A1, _A2>::type type;
Nikolas Klauser25fbc472022-11-04 16:56:51 +0100505 return __builtin_islessequal((type)__x, (type)__y);
Richard Smith081bb592015-10-08 20:40:34 +0000506}
507
Richard Smith081bb592015-10-08 20:40:34 +0000508// islessgreater
509
Nikolas Klausere96070f2022-11-04 20:08:56 +0100510template <class _A1,
511 class _A2,
512 std::__enable_if_t<std::is_arithmetic<_A1>::value && std::is_arithmetic<_A2>::value, int> = 0>
513inline _LIBCPP_HIDE_FROM_ABI bool islessgreater(_A1 __x, _A2 __y) _NOEXCEPT {
Nikolas Klauser9a97dd72022-11-04 16:36:34 +0100514 typedef typename std::__promote<_A1, _A2>::type type;
Nikolas Klauser25fbc472022-11-04 16:56:51 +0100515 return __builtin_islessgreater((type)__x, (type)__y);
Richard Smith081bb592015-10-08 20:40:34 +0000516}
517
Richard Smith081bb592015-10-08 20:40:34 +0000518// isunordered
519
Nikolas Klausere96070f2022-11-04 20:08:56 +0100520template <class _A1,
521 class _A2,
522 std::__enable_if_t<std::is_arithmetic<_A1>::value && std::is_arithmetic<_A2>::value, int> = 0>
523inline _LIBCPP_HIDE_FROM_ABI bool isunordered(_A1 __x, _A2 __y) _NOEXCEPT {
Nikolas Klauser9a97dd72022-11-04 16:36:34 +0100524 typedef typename std::__promote<_A1, _A2>::type type;
Nikolas Klauser25fbc472022-11-04 16:56:51 +0100525 return __builtin_isunordered((type)__x, (type)__y);
Richard Smith081bb592015-10-08 20:40:34 +0000526}
527
Nikolas Klauserae1fbc42022-11-04 20:19:20 +0100528#endif // _LIBCPP_MSVCRT
Richard Smith081bb592015-10-08 20:40:34 +0000529
Richard Smith081bb592015-10-08 20:40:34 +0000530// abs
Eric Fiselier6c9e1a72020-02-15 18:55:07 -0500531//
532// handled in stdlib.h
Richard Smith081bb592015-10-08 20:40:34 +0000533
Eric Fiselier2b85c6e2019-04-23 18:01:58 +0000534// div
Eric Fiselier6c9e1a72020-02-15 18:55:07 -0500535//
536// handled in stdlib.h
Eric Fiselier2b85c6e2019-04-23 18:01:58 +0000537
Nikolas Klauser52399652022-11-01 22:29:57 +0100538// We have to provide double overloads for <math.h> to work on platforms that don't provide the full set of math
539// functions. To make the overload set work with multiple functions that take the same arguments, we make our overloads
540// templates. Functions are preferred over function templates during overload resolution, which means that our overload
541// will only be selected when the C library doesn't provide one.
542
Richard Smith081bb592015-10-08 20:40:34 +0000543// acos
544
David Tenty7249ac92022-02-07 18:22:35 -0500545# if !defined(__sun__)
Nikolas Klauser04005952022-10-21 01:41:22 +0200546inline _LIBCPP_HIDE_FROM_ABI float acos(float __x) _NOEXCEPT {return __builtin_acosf(__x);}
Nikolas Klauser52399652022-11-01 22:29:57 +0100547
548template <class = int>
549_LIBCPP_HIDE_FROM_ABI double acos(double __x) _NOEXCEPT {
550 return __builtin_acos(__x);
551}
552
Nikolas Klauser04005952022-10-21 01:41:22 +0200553inline _LIBCPP_HIDE_FROM_ABI long double acos(long double __x) _NOEXCEPT {return __builtin_acosl(__x);}
David Tenty7249ac92022-02-07 18:22:35 -0500554# endif
Richard Smith081bb592015-10-08 20:40:34 +0000555
556template <class _A1>
Nikolas Klauser4956e722022-10-12 15:41:22 +0200557inline _LIBCPP_HIDE_FROM_ABI
Richard Smith081bb592015-10-08 20:40:34 +0000558typename std::enable_if<std::is_integral<_A1>::value, double>::type
Nikolas Klauser04005952022-10-21 01:41:22 +0200559acos(_A1 __x) _NOEXCEPT {return __builtin_acos((double)__x);}
Richard Smith081bb592015-10-08 20:40:34 +0000560
561// asin
562
David Tenty7249ac92022-02-07 18:22:35 -0500563# if !defined(__sun__)
Nikolas Klauser04005952022-10-21 01:41:22 +0200564inline _LIBCPP_HIDE_FROM_ABI float asin(float __x) _NOEXCEPT {return __builtin_asinf(__x);}
Nikolas Klauser52399652022-11-01 22:29:57 +0100565
566template <class = int>
567_LIBCPP_HIDE_FROM_ABI double asin(double __x) _NOEXCEPT {
568 return __builtin_asin(__x);
569}
570
Nikolas Klauser04005952022-10-21 01:41:22 +0200571inline _LIBCPP_HIDE_FROM_ABI long double asin(long double __x) _NOEXCEPT {return __builtin_asinl(__x);}
David Tenty7249ac92022-02-07 18:22:35 -0500572# endif
Richard Smith081bb592015-10-08 20:40:34 +0000573
574template <class _A1>
Nikolas Klauser4956e722022-10-12 15:41:22 +0200575inline _LIBCPP_HIDE_FROM_ABI
Richard Smith081bb592015-10-08 20:40:34 +0000576typename std::enable_if<std::is_integral<_A1>::value, double>::type
Nikolas Klauser04005952022-10-21 01:41:22 +0200577asin(_A1 __x) _NOEXCEPT {return __builtin_asin((double)__x);}
Richard Smith081bb592015-10-08 20:40:34 +0000578
579// atan
580
David Tenty7249ac92022-02-07 18:22:35 -0500581# if !defined(__sun__)
Nikolas Klauser04005952022-10-21 01:41:22 +0200582inline _LIBCPP_HIDE_FROM_ABI float atan(float __x) _NOEXCEPT {return __builtin_atanf(__x);}
Nikolas Klauser52399652022-11-01 22:29:57 +0100583
584template <class = int>
585_LIBCPP_HIDE_FROM_ABI double atan(double __x) _NOEXCEPT {
586 return __builtin_atan(__x);
587}
588
Nikolas Klauser04005952022-10-21 01:41:22 +0200589inline _LIBCPP_HIDE_FROM_ABI long double atan(long double __x) _NOEXCEPT {return __builtin_atanl(__x);}
David Tenty7249ac92022-02-07 18:22:35 -0500590# endif
Richard Smith081bb592015-10-08 20:40:34 +0000591
592template <class _A1>
Nikolas Klauser4956e722022-10-12 15:41:22 +0200593inline _LIBCPP_HIDE_FROM_ABI
Richard Smith081bb592015-10-08 20:40:34 +0000594typename std::enable_if<std::is_integral<_A1>::value, double>::type
Nikolas Klauser04005952022-10-21 01:41:22 +0200595atan(_A1 __x) _NOEXCEPT {return __builtin_atan((double)__x);}
Richard Smith081bb592015-10-08 20:40:34 +0000596
597// atan2
598
David Tenty7249ac92022-02-07 18:22:35 -0500599# if !defined(__sun__)
Nikolas Klauser04005952022-10-21 01:41:22 +0200600inline _LIBCPP_HIDE_FROM_ABI float atan2(float __y, float __x) _NOEXCEPT {return __builtin_atan2f(__y, __x);}
Nikolas Klauser52399652022-11-01 22:29:57 +0100601
602template <class = int>
603_LIBCPP_HIDE_FROM_ABI double atan2(double __x, double __y) _NOEXCEPT {
604 return __builtin_atan2(__x, __y);
605}
606
Nikolas Klauser04005952022-10-21 01:41:22 +0200607inline _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 -0500608# endif
Richard Smith081bb592015-10-08 20:40:34 +0000609
610template <class _A1, class _A2>
Nikolas Klauser4956e722022-10-12 15:41:22 +0200611inline _LIBCPP_HIDE_FROM_ABI
Louis Dionne9ce598d2021-09-08 09:14:43 -0400612typename std::__enable_if_t
Richard Smith081bb592015-10-08 20:40:34 +0000613<
614 std::is_arithmetic<_A1>::value &&
615 std::is_arithmetic<_A2>::value,
616 std::__promote<_A1, _A2>
617>::type
Nikolas Klauser9806f452022-10-12 15:45:09 +0200618atan2(_A1 __y, _A2 __x) _NOEXCEPT
Richard Smith081bb592015-10-08 20:40:34 +0000619{
620 typedef typename std::__promote<_A1, _A2>::type __result_type;
Eric Fiselier3906a132019-06-23 20:28:29 +0000621 static_assert((!(std::_IsSame<_A1, __result_type>::value &&
622 std::_IsSame<_A2, __result_type>::value)), "");
Nikolas Klauser9806f452022-10-12 15:45:09 +0200623 return ::atan2((__result_type)__y, (__result_type)__x);
Richard Smith081bb592015-10-08 20:40:34 +0000624}
625
626// ceil
627
David Tenty7249ac92022-02-07 18:22:35 -0500628# if !defined(__sun__)
Nikolas Klauser04005952022-10-21 01:41:22 +0200629inline _LIBCPP_HIDE_FROM_ABI float ceil(float __x) _NOEXCEPT {return __builtin_ceilf(__x);}
Nikolas Klauser52399652022-11-01 22:29:57 +0100630
631template <class = int>
632_LIBCPP_HIDE_FROM_ABI double ceil(double __x) _NOEXCEPT {
633 return __builtin_ceil(__x);
634}
635
Nikolas Klauser04005952022-10-21 01:41:22 +0200636inline _LIBCPP_HIDE_FROM_ABI long double ceil(long double __x) _NOEXCEPT {return __builtin_ceill(__x);}
David Tenty7249ac92022-02-07 18:22:35 -0500637# endif
Richard Smith081bb592015-10-08 20:40:34 +0000638
639template <class _A1>
Nikolas Klauser4956e722022-10-12 15:41:22 +0200640inline _LIBCPP_HIDE_FROM_ABI
Richard Smith081bb592015-10-08 20:40:34 +0000641typename std::enable_if<std::is_integral<_A1>::value, double>::type
Nikolas Klauser04005952022-10-21 01:41:22 +0200642ceil(_A1 __x) _NOEXCEPT {return __builtin_ceil((double)__x);}
Richard Smith081bb592015-10-08 20:40:34 +0000643
644// cos
645
David Tenty7249ac92022-02-07 18:22:35 -0500646# if !defined(__sun__)
Nikolas Klauser04005952022-10-21 01:41:22 +0200647inline _LIBCPP_HIDE_FROM_ABI float cos(float __x) _NOEXCEPT {return __builtin_cosf(__x);}
Nikolas Klauser52399652022-11-01 22:29:57 +0100648
649template <class = int>
650_LIBCPP_HIDE_FROM_ABI double cos(double __x) _NOEXCEPT {
651 return __builtin_cos(__x);
652}
653
Nikolas Klauser04005952022-10-21 01:41:22 +0200654inline _LIBCPP_HIDE_FROM_ABI long double cos(long double __x) _NOEXCEPT {return __builtin_cosl(__x);}
David Tenty7249ac92022-02-07 18:22:35 -0500655# endif
Richard Smith081bb592015-10-08 20:40:34 +0000656
657template <class _A1>
Nikolas Klauser4956e722022-10-12 15:41:22 +0200658inline _LIBCPP_HIDE_FROM_ABI
Richard Smith081bb592015-10-08 20:40:34 +0000659typename std::enable_if<std::is_integral<_A1>::value, double>::type
Nikolas Klauser04005952022-10-21 01:41:22 +0200660cos(_A1 __x) _NOEXCEPT {return __builtin_cos((double)__x);}
Richard Smith081bb592015-10-08 20:40:34 +0000661
662// cosh
663
David Tenty7249ac92022-02-07 18:22:35 -0500664# if !defined(__sun__)
Nikolas Klauser04005952022-10-21 01:41:22 +0200665inline _LIBCPP_HIDE_FROM_ABI float cosh(float __x) _NOEXCEPT {return __builtin_coshf(__x);}
Nikolas Klauser52399652022-11-01 22:29:57 +0100666
667template <class = int>
668_LIBCPP_HIDE_FROM_ABI double cosh(double __x) _NOEXCEPT {
669 return __builtin_cosh(__x);
670}
671
Nikolas Klauser04005952022-10-21 01:41:22 +0200672inline _LIBCPP_HIDE_FROM_ABI long double cosh(long double __x) _NOEXCEPT {return __builtin_coshl(__x);}
David Tenty7249ac92022-02-07 18:22:35 -0500673# endif
Richard Smith081bb592015-10-08 20:40:34 +0000674
675template <class _A1>
Nikolas Klauser4956e722022-10-12 15:41:22 +0200676inline _LIBCPP_HIDE_FROM_ABI
Richard Smith081bb592015-10-08 20:40:34 +0000677typename std::enable_if<std::is_integral<_A1>::value, double>::type
Nikolas Klauser04005952022-10-21 01:41:22 +0200678cosh(_A1 __x) _NOEXCEPT {return __builtin_cosh((double)__x);}
Richard Smith081bb592015-10-08 20:40:34 +0000679
680// exp
681
David Tenty7249ac92022-02-07 18:22:35 -0500682# if !defined(__sun__)
Nikolas Klauser04005952022-10-21 01:41:22 +0200683inline _LIBCPP_HIDE_FROM_ABI float exp(float __x) _NOEXCEPT {return __builtin_expf(__x);}
Nikolas Klauser52399652022-11-01 22:29:57 +0100684
685template <class = int>
686_LIBCPP_HIDE_FROM_ABI double exp(double __x) _NOEXCEPT {
687 return __builtin_exp(__x);
688}
689
Nikolas Klauser04005952022-10-21 01:41:22 +0200690inline _LIBCPP_HIDE_FROM_ABI long double exp(long double __x) _NOEXCEPT {return __builtin_expl(__x);}
David Tenty7249ac92022-02-07 18:22:35 -0500691# endif
Richard Smith081bb592015-10-08 20:40:34 +0000692
693template <class _A1>
Nikolas Klauser4956e722022-10-12 15:41:22 +0200694inline _LIBCPP_HIDE_FROM_ABI
Richard Smith081bb592015-10-08 20:40:34 +0000695typename std::enable_if<std::is_integral<_A1>::value, double>::type
Nikolas Klauser04005952022-10-21 01:41:22 +0200696exp(_A1 __x) _NOEXCEPT {return __builtin_exp((double)__x);}
Richard Smith081bb592015-10-08 20:40:34 +0000697
698// fabs
699
David Tenty7249ac92022-02-07 18:22:35 -0500700# if !defined(__sun__)
Nikolas Klauser04005952022-10-21 01:41:22 +0200701inline _LIBCPP_HIDE_FROM_ABI float fabs(float __x) _NOEXCEPT {return __builtin_fabsf(__x);}
Nikolas Klauser52399652022-11-01 22:29:57 +0100702
703template <class = int>
704_LIBCPP_HIDE_FROM_ABI double fabs(double __x) _NOEXCEPT {
705 return __builtin_fabs(__x);
706}
707
Nikolas Klauser04005952022-10-21 01:41:22 +0200708inline _LIBCPP_HIDE_FROM_ABI long double fabs(long double __x) _NOEXCEPT {return __builtin_fabsl(__x);}
David Tenty7249ac92022-02-07 18:22:35 -0500709# endif
Richard Smith081bb592015-10-08 20:40:34 +0000710
711template <class _A1>
Nikolas Klauser4956e722022-10-12 15:41:22 +0200712inline _LIBCPP_HIDE_FROM_ABI
Richard Smith081bb592015-10-08 20:40:34 +0000713typename std::enable_if<std::is_integral<_A1>::value, double>::type
Nikolas Klauser04005952022-10-21 01:41:22 +0200714fabs(_A1 __x) _NOEXCEPT {return __builtin_fabs((double)__x);}
Richard Smith081bb592015-10-08 20:40:34 +0000715
716// floor
717
David Tenty7249ac92022-02-07 18:22:35 -0500718# if !defined(__sun__)
Nikolas Klauser04005952022-10-21 01:41:22 +0200719inline _LIBCPP_HIDE_FROM_ABI float floor(float __x) _NOEXCEPT {return __builtin_floorf(__x);}
Nikolas Klauser52399652022-11-01 22:29:57 +0100720
721template <class = int>
722_LIBCPP_HIDE_FROM_ABI double floor(double __x) _NOEXCEPT {
723 return __builtin_floor(__x);
724}
725
Nikolas Klauser04005952022-10-21 01:41:22 +0200726inline _LIBCPP_HIDE_FROM_ABI long double floor(long double __x) _NOEXCEPT {return __builtin_floorl(__x);}
David Tenty7249ac92022-02-07 18:22:35 -0500727# endif
Richard Smith081bb592015-10-08 20:40:34 +0000728
729template <class _A1>
Nikolas Klauser4956e722022-10-12 15:41:22 +0200730inline _LIBCPP_HIDE_FROM_ABI
Richard Smith081bb592015-10-08 20:40:34 +0000731typename std::enable_if<std::is_integral<_A1>::value, double>::type
Nikolas Klauser04005952022-10-21 01:41:22 +0200732floor(_A1 __x) _NOEXCEPT {return __builtin_floor((double)__x);}
Richard Smith081bb592015-10-08 20:40:34 +0000733
734// fmod
735
David Tenty7249ac92022-02-07 18:22:35 -0500736# if !defined(__sun__)
Nikolas Klauser04005952022-10-21 01:41:22 +0200737inline _LIBCPP_HIDE_FROM_ABI float fmod(float __x, float __y) _NOEXCEPT {return __builtin_fmodf(__x, __y);}
Nikolas Klauser52399652022-11-01 22:29:57 +0100738
739template <class = int>
740_LIBCPP_HIDE_FROM_ABI double fmod(double __x, double __y) _NOEXCEPT {
741 return __builtin_fmod(__x, __y);
742}
743
Nikolas Klauser04005952022-10-21 01:41:22 +0200744inline _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 -0500745# endif
Richard Smith081bb592015-10-08 20:40:34 +0000746
747template <class _A1, class _A2>
Nikolas Klauser4956e722022-10-12 15:41:22 +0200748inline _LIBCPP_HIDE_FROM_ABI
Louis Dionne9ce598d2021-09-08 09:14:43 -0400749typename std::__enable_if_t
Richard Smith081bb592015-10-08 20:40:34 +0000750<
751 std::is_arithmetic<_A1>::value &&
752 std::is_arithmetic<_A2>::value,
753 std::__promote<_A1, _A2>
754>::type
Nikolas Klauser9806f452022-10-12 15:45:09 +0200755fmod(_A1 __x, _A2 __y) _NOEXCEPT
Richard Smith081bb592015-10-08 20:40:34 +0000756{
757 typedef typename std::__promote<_A1, _A2>::type __result_type;
Eric Fiselier3906a132019-06-23 20:28:29 +0000758 static_assert((!(std::_IsSame<_A1, __result_type>::value &&
759 std::_IsSame<_A2, __result_type>::value)), "");
Nikolas Klauser9806f452022-10-12 15:45:09 +0200760 return ::fmod((__result_type)__x, (__result_type)__y);
Richard Smith081bb592015-10-08 20:40:34 +0000761}
762
763// frexp
764
David Tenty7249ac92022-02-07 18:22:35 -0500765# if !defined(__sun__)
Nikolas Klauser04005952022-10-21 01:41:22 +0200766inline _LIBCPP_HIDE_FROM_ABI float frexp(float __x, int* __e) _NOEXCEPT {return __builtin_frexpf(__x, __e);}
Nikolas Klauser52399652022-11-01 22:29:57 +0100767
768template <class = int>
769_LIBCPP_HIDE_FROM_ABI double frexp(double __x, int* __e) _NOEXCEPT {
770 return __builtin_frexp(__x, __e);
771}
772
Nikolas Klauser04005952022-10-21 01:41:22 +0200773inline _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 -0500774# endif
Richard Smith081bb592015-10-08 20:40:34 +0000775
776template <class _A1>
Nikolas Klauser4956e722022-10-12 15:41:22 +0200777inline _LIBCPP_HIDE_FROM_ABI
Richard Smith081bb592015-10-08 20:40:34 +0000778typename std::enable_if<std::is_integral<_A1>::value, double>::type
Nikolas Klauser04005952022-10-21 01:41:22 +0200779frexp(_A1 __x, int* __e) _NOEXCEPT {return __builtin_frexp((double)__x, __e);}
Richard Smith081bb592015-10-08 20:40:34 +0000780
781// ldexp
782
David Tenty7249ac92022-02-07 18:22:35 -0500783# if !defined(__sun__)
Nikolas Klauser04005952022-10-21 01:41:22 +0200784inline _LIBCPP_HIDE_FROM_ABI float ldexp(float __x, int __e) _NOEXCEPT {return __builtin_ldexpf(__x, __e);}
Nikolas Klauser52399652022-11-01 22:29:57 +0100785
786template <class = int>
787_LIBCPP_HIDE_FROM_ABI double ldexp(double __x, int __e) _NOEXCEPT {
788 return __builtin_ldexp(__x, __e);
789}
790
Nikolas Klauser04005952022-10-21 01:41:22 +0200791inline _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 -0500792# endif
Richard Smith081bb592015-10-08 20:40:34 +0000793
794template <class _A1>
Nikolas Klauser4956e722022-10-12 15:41:22 +0200795inline _LIBCPP_HIDE_FROM_ABI
Richard Smith081bb592015-10-08 20:40:34 +0000796typename std::enable_if<std::is_integral<_A1>::value, double>::type
Nikolas Klauser04005952022-10-21 01:41:22 +0200797ldexp(_A1 __x, int __e) _NOEXCEPT {return __builtin_ldexp((double)__x, __e);}
Richard Smith081bb592015-10-08 20:40:34 +0000798
799// log
800
David Tenty7249ac92022-02-07 18:22:35 -0500801# if !defined(__sun__)
Nikolas Klauser04005952022-10-21 01:41:22 +0200802inline _LIBCPP_HIDE_FROM_ABI float log(float __x) _NOEXCEPT {return __builtin_logf(__x);}
Nikolas Klauser52399652022-11-01 22:29:57 +0100803
804template <class = int>
805_LIBCPP_HIDE_FROM_ABI double log(double __x) _NOEXCEPT {
806 return __builtin_log(__x);
807}
808
Nikolas Klauser04005952022-10-21 01:41:22 +0200809inline _LIBCPP_HIDE_FROM_ABI long double log(long double __x) _NOEXCEPT {return __builtin_logl(__x);}
David Tenty7249ac92022-02-07 18:22:35 -0500810# endif
Richard Smith081bb592015-10-08 20:40:34 +0000811
812template <class _A1>
Nikolas Klauser4956e722022-10-12 15:41:22 +0200813inline _LIBCPP_HIDE_FROM_ABI
Richard Smith081bb592015-10-08 20:40:34 +0000814typename std::enable_if<std::is_integral<_A1>::value, double>::type
Nikolas Klauser04005952022-10-21 01:41:22 +0200815log(_A1 __x) _NOEXCEPT {return __builtin_log((double)__x);}
Richard Smith081bb592015-10-08 20:40:34 +0000816
817// log10
818
David Tenty7249ac92022-02-07 18:22:35 -0500819# if !defined(__sun__)
Nikolas Klauser04005952022-10-21 01:41:22 +0200820inline _LIBCPP_HIDE_FROM_ABI float log10(float __x) _NOEXCEPT {return __builtin_log10f(__x);}
Nikolas Klauser52399652022-11-01 22:29:57 +0100821
822
823template <class = int>
824_LIBCPP_HIDE_FROM_ABI double log10(double __x) _NOEXCEPT {
825 return __builtin_log10(__x);
826}
827
Nikolas Klauser04005952022-10-21 01:41:22 +0200828inline _LIBCPP_HIDE_FROM_ABI long double log10(long double __x) _NOEXCEPT {return __builtin_log10l(__x);}
David Tenty7249ac92022-02-07 18:22:35 -0500829# endif
Richard Smith081bb592015-10-08 20:40:34 +0000830
831template <class _A1>
Nikolas Klauser4956e722022-10-12 15:41:22 +0200832inline _LIBCPP_HIDE_FROM_ABI
Richard Smith081bb592015-10-08 20:40:34 +0000833typename std::enable_if<std::is_integral<_A1>::value, double>::type
Nikolas Klauser04005952022-10-21 01:41:22 +0200834log10(_A1 __x) _NOEXCEPT {return __builtin_log10((double)__x);}
Richard Smith081bb592015-10-08 20:40:34 +0000835
836// modf
837
David Tenty7249ac92022-02-07 18:22:35 -0500838# if !defined(__sun__)
Nikolas Klauser04005952022-10-21 01:41:22 +0200839inline _LIBCPP_HIDE_FROM_ABI float modf(float __x, float* __y) _NOEXCEPT {return __builtin_modff(__x, __y);}
Nikolas Klauser52399652022-11-01 22:29:57 +0100840
841template <class = int>
842_LIBCPP_HIDE_FROM_ABI double modf(double __x, double* __y) _NOEXCEPT {
843 return __builtin_modf(__x, __y);
844}
845
Nikolas Klauser04005952022-10-21 01:41:22 +0200846inline _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 -0500847# endif
Richard Smith081bb592015-10-08 20:40:34 +0000848
849// pow
850
David Tenty7249ac92022-02-07 18:22:35 -0500851# if !defined(__sun__)
Nikolas Klauser04005952022-10-21 01:41:22 +0200852inline _LIBCPP_HIDE_FROM_ABI float pow(float __x, float __y) _NOEXCEPT {return __builtin_powf(__x, __y);}
Nikolas Klauser52399652022-11-01 22:29:57 +0100853
854template <class = int>
855_LIBCPP_HIDE_FROM_ABI double pow(double __x, double __y) _NOEXCEPT {
856 return __builtin_pow(__x, __y);
857}
858
Nikolas Klauser04005952022-10-21 01:41:22 +0200859inline _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 -0500860# endif
Richard Smith081bb592015-10-08 20:40:34 +0000861
862template <class _A1, class _A2>
Nikolas Klauser4956e722022-10-12 15:41:22 +0200863inline _LIBCPP_HIDE_FROM_ABI
Louis Dionne9ce598d2021-09-08 09:14:43 -0400864typename std::__enable_if_t
Richard Smith081bb592015-10-08 20:40:34 +0000865<
866 std::is_arithmetic<_A1>::value &&
867 std::is_arithmetic<_A2>::value,
868 std::__promote<_A1, _A2>
869>::type
Nikolas Klauser9806f452022-10-12 15:45:09 +0200870pow(_A1 __x, _A2 __y) _NOEXCEPT
Richard Smith081bb592015-10-08 20:40:34 +0000871{
872 typedef typename std::__promote<_A1, _A2>::type __result_type;
Eric Fiselier3906a132019-06-23 20:28:29 +0000873 static_assert((!(std::_IsSame<_A1, __result_type>::value &&
874 std::_IsSame<_A2, __result_type>::value)), "");
Nikolas Klauser9806f452022-10-12 15:45:09 +0200875 return ::pow((__result_type)__x, (__result_type)__y);
Richard Smith081bb592015-10-08 20:40:34 +0000876}
877
878// sin
879
David Tenty7249ac92022-02-07 18:22:35 -0500880# if !defined(__sun__)
Nikolas Klauser04005952022-10-21 01:41:22 +0200881inline _LIBCPP_HIDE_FROM_ABI float sin(float __x) _NOEXCEPT {return __builtin_sinf(__x);}
Nikolas Klauser52399652022-11-01 22:29:57 +0100882
883template <class = int>
884_LIBCPP_HIDE_FROM_ABI double sin(double __x) _NOEXCEPT {
885 return __builtin_sin(__x);
886}
887
Nikolas Klauser04005952022-10-21 01:41:22 +0200888inline _LIBCPP_HIDE_FROM_ABI long double sin(long double __x) _NOEXCEPT {return __builtin_sinl(__x);}
Richard Smith081bb592015-10-08 20:40:34 +0000889#endif
890
891template <class _A1>
Nikolas Klauser4956e722022-10-12 15:41:22 +0200892inline _LIBCPP_HIDE_FROM_ABI
Richard Smith081bb592015-10-08 20:40:34 +0000893typename std::enable_if<std::is_integral<_A1>::value, double>::type
Nikolas Klauser04005952022-10-21 01:41:22 +0200894sin(_A1 __x) _NOEXCEPT {return __builtin_sin((double)__x);}
Richard Smith081bb592015-10-08 20:40:34 +0000895
896// sinh
897
David Tenty7249ac92022-02-07 18:22:35 -0500898# if !defined(__sun__)
Nikolas Klauser04005952022-10-21 01:41:22 +0200899inline _LIBCPP_HIDE_FROM_ABI float sinh(float __x) _NOEXCEPT {return __builtin_sinhf(__x);}
Nikolas Klauser52399652022-11-01 22:29:57 +0100900
901template <class = int>
902_LIBCPP_HIDE_FROM_ABI double sinh(double __x) _NOEXCEPT {
903 return __builtin_sinh(__x);
904}
905
Nikolas Klauser04005952022-10-21 01:41:22 +0200906inline _LIBCPP_HIDE_FROM_ABI long double sinh(long double __x) _NOEXCEPT {return __builtin_sinhl(__x);}
David Tenty7249ac92022-02-07 18:22:35 -0500907# endif
Richard Smith081bb592015-10-08 20:40:34 +0000908
909template <class _A1>
Nikolas Klauser4956e722022-10-12 15:41:22 +0200910inline _LIBCPP_HIDE_FROM_ABI
Richard Smith081bb592015-10-08 20:40:34 +0000911typename std::enable_if<std::is_integral<_A1>::value, double>::type
Nikolas Klauser04005952022-10-21 01:41:22 +0200912sinh(_A1 __x) _NOEXCEPT {return __builtin_sinh((double)__x);}
Richard Smith081bb592015-10-08 20:40:34 +0000913
914// sqrt
915
David Tenty7249ac92022-02-07 18:22:35 -0500916# if !defined(__sun__)
Nikolas Klauser04005952022-10-21 01:41:22 +0200917inline _LIBCPP_HIDE_FROM_ABI float sqrt(float __x) _NOEXCEPT {return __builtin_sqrtf(__x);}
Nikolas Klauser52399652022-11-01 22:29:57 +0100918
919template <class = int>
920_LIBCPP_HIDE_FROM_ABI double sqrt(double __x) _NOEXCEPT {
921 return __builtin_sqrt(__x);
922}
923
Nikolas Klauser04005952022-10-21 01:41:22 +0200924inline _LIBCPP_HIDE_FROM_ABI long double sqrt(long double __x) _NOEXCEPT {return __builtin_sqrtl(__x);}
David Tenty7249ac92022-02-07 18:22:35 -0500925# endif
Richard Smith081bb592015-10-08 20:40:34 +0000926
Richard Smith081bb592015-10-08 20:40:34 +0000927template <class _A1>
Nikolas Klauser4956e722022-10-12 15:41:22 +0200928inline _LIBCPP_HIDE_FROM_ABI
Richard Smith081bb592015-10-08 20:40:34 +0000929typename std::enable_if<std::is_integral<_A1>::value, double>::type
Nikolas Klauser04005952022-10-21 01:41:22 +0200930sqrt(_A1 __x) _NOEXCEPT {return __builtin_sqrt((double)__x);}
Richard Smith081bb592015-10-08 20:40:34 +0000931
932// tan
933
David Tenty7249ac92022-02-07 18:22:35 -0500934# if !defined(__sun__)
Nikolas Klauser04005952022-10-21 01:41:22 +0200935inline _LIBCPP_HIDE_FROM_ABI float tan(float __x) _NOEXCEPT {return __builtin_tanf(__x);}
Nikolas Klauser52399652022-11-01 22:29:57 +0100936
937template <class = int>
938_LIBCPP_HIDE_FROM_ABI double tan(double __x) _NOEXCEPT {
939 return __builtin_tan(__x);
940}
941
Nikolas Klauser04005952022-10-21 01:41:22 +0200942inline _LIBCPP_HIDE_FROM_ABI long double tan(long double __x) _NOEXCEPT {return __builtin_tanl(__x);}
David Tenty7249ac92022-02-07 18:22:35 -0500943# endif
Richard Smith081bb592015-10-08 20:40:34 +0000944
945template <class _A1>
Nikolas Klauser4956e722022-10-12 15:41:22 +0200946inline _LIBCPP_HIDE_FROM_ABI
Richard Smith081bb592015-10-08 20:40:34 +0000947typename std::enable_if<std::is_integral<_A1>::value, double>::type
Nikolas Klauser04005952022-10-21 01:41:22 +0200948tan(_A1 __x) _NOEXCEPT {return __builtin_tan((double)__x);}
Richard Smith081bb592015-10-08 20:40:34 +0000949
950// tanh
951
David Tenty7249ac92022-02-07 18:22:35 -0500952# if !defined(__sun__)
Nikolas Klauser04005952022-10-21 01:41:22 +0200953inline _LIBCPP_HIDE_FROM_ABI float tanh(float __x) _NOEXCEPT {return __builtin_tanhf(__x);}
Nikolas Klauser52399652022-11-01 22:29:57 +0100954
955template <class = int>
956_LIBCPP_HIDE_FROM_ABI double tanh(double __x) _NOEXCEPT {
957 return __builtin_tanh(__x);
958}
959
Nikolas Klauser04005952022-10-21 01:41:22 +0200960inline _LIBCPP_HIDE_FROM_ABI long double tanh(long double __x) _NOEXCEPT {return __builtin_tanhl(__x);}
David Tenty7249ac92022-02-07 18:22:35 -0500961# endif
Richard Smith081bb592015-10-08 20:40:34 +0000962
963template <class _A1>
Nikolas Klauser4956e722022-10-12 15:41:22 +0200964inline _LIBCPP_HIDE_FROM_ABI
Richard Smith081bb592015-10-08 20:40:34 +0000965typename std::enable_if<std::is_integral<_A1>::value, double>::type
Nikolas Klauser04005952022-10-21 01:41:22 +0200966tanh(_A1 __x) _NOEXCEPT {return __builtin_tanh((double)__x);}
Richard Smith081bb592015-10-08 20:40:34 +0000967
968// acosh
969
Nikolas Klauser04005952022-10-21 01:41:22 +0200970inline _LIBCPP_HIDE_FROM_ABI float acosh(float __x) _NOEXCEPT {return __builtin_acoshf(__x);}
Nikolas Klauser52399652022-11-01 22:29:57 +0100971
972template <class = int>
973_LIBCPP_HIDE_FROM_ABI double acosh(double __x) _NOEXCEPT {
974 return __builtin_acosh(__x);
975}
976
Nikolas Klauser04005952022-10-21 01:41:22 +0200977inline _LIBCPP_HIDE_FROM_ABI long double acosh(long double __x) _NOEXCEPT {return __builtin_acoshl(__x);}
Richard Smith081bb592015-10-08 20:40:34 +0000978
979template <class _A1>
Nikolas Klauser4956e722022-10-12 15:41:22 +0200980inline _LIBCPP_HIDE_FROM_ABI
Richard Smith081bb592015-10-08 20:40:34 +0000981typename std::enable_if<std::is_integral<_A1>::value, double>::type
Nikolas Klauser04005952022-10-21 01:41:22 +0200982acosh(_A1 __x) _NOEXCEPT {return __builtin_acosh((double)__x);}
Richard Smith081bb592015-10-08 20:40:34 +0000983
984// asinh
985
Nikolas Klauser04005952022-10-21 01:41:22 +0200986inline _LIBCPP_HIDE_FROM_ABI float asinh(float __x) _NOEXCEPT {return __builtin_asinhf(__x);}
Nikolas Klauser52399652022-11-01 22:29:57 +0100987
988template <class = int>
989_LIBCPP_HIDE_FROM_ABI double asinh(double __x) _NOEXCEPT {
990 return __builtin_asinh(__x);
991}
992
Nikolas Klauser04005952022-10-21 01:41:22 +0200993inline _LIBCPP_HIDE_FROM_ABI long double asinh(long double __x) _NOEXCEPT {return __builtin_asinhl(__x);}
Richard Smith081bb592015-10-08 20:40:34 +0000994
995template <class _A1>
Nikolas Klauser4956e722022-10-12 15:41:22 +0200996inline _LIBCPP_HIDE_FROM_ABI
Richard Smith081bb592015-10-08 20:40:34 +0000997typename std::enable_if<std::is_integral<_A1>::value, double>::type
Nikolas Klauser04005952022-10-21 01:41:22 +0200998asinh(_A1 __x) _NOEXCEPT {return __builtin_asinh((double)__x);}
Richard Smith081bb592015-10-08 20:40:34 +0000999
1000// atanh
1001
Nikolas Klauser04005952022-10-21 01:41:22 +02001002inline _LIBCPP_HIDE_FROM_ABI float atanh(float __x) _NOEXCEPT {return __builtin_atanhf(__x);}
Nikolas Klauser52399652022-11-01 22:29:57 +01001003
1004template <class = int>
1005_LIBCPP_HIDE_FROM_ABI double atanh(double __x) _NOEXCEPT {
1006 return __builtin_atanh(__x);
1007}
1008
Nikolas Klauser04005952022-10-21 01:41:22 +02001009inline _LIBCPP_HIDE_FROM_ABI long double atanh(long double __x) _NOEXCEPT {return __builtin_atanhl(__x);}
Richard Smith081bb592015-10-08 20:40:34 +00001010
1011template <class _A1>
Nikolas Klauser4956e722022-10-12 15:41:22 +02001012inline _LIBCPP_HIDE_FROM_ABI
Richard Smith081bb592015-10-08 20:40:34 +00001013typename std::enable_if<std::is_integral<_A1>::value, double>::type
Nikolas Klauser04005952022-10-21 01:41:22 +02001014atanh(_A1 __x) _NOEXCEPT {return __builtin_atanh((double)__x);}
Richard Smith081bb592015-10-08 20:40:34 +00001015
1016// cbrt
1017
Nikolas Klauser04005952022-10-21 01:41:22 +02001018inline _LIBCPP_HIDE_FROM_ABI float cbrt(float __x) _NOEXCEPT {return __builtin_cbrtf(__x);}
Nikolas Klauser52399652022-11-01 22:29:57 +01001019
1020template <class = int>
1021_LIBCPP_HIDE_FROM_ABI double cbrt(double __x) _NOEXCEPT {
1022 return __builtin_cbrt(__x);
1023}
1024
Nikolas Klauser04005952022-10-21 01:41:22 +02001025inline _LIBCPP_HIDE_FROM_ABI long double cbrt(long double __x) _NOEXCEPT {return __builtin_cbrtl(__x);}
Richard Smith081bb592015-10-08 20:40:34 +00001026
1027template <class _A1>
Nikolas Klauser4956e722022-10-12 15:41:22 +02001028inline _LIBCPP_HIDE_FROM_ABI
Richard Smith081bb592015-10-08 20:40:34 +00001029typename std::enable_if<std::is_integral<_A1>::value, double>::type
Nikolas Klauser04005952022-10-21 01:41:22 +02001030cbrt(_A1 __x) _NOEXCEPT {return __builtin_cbrt((double)__x);}
Richard Smith081bb592015-10-08 20:40:34 +00001031
1032// copysign
1033
Marek Kurdeja933f0d2021-07-21 15:58:17 +02001034_LIBCPP_CONSTEXPR
Nikolas Klauser9806f452022-10-12 15:45:09 +02001035inline _LIBCPP_HIDE_FROM_ABI float __libcpp_copysign(float __x, float __y) _NOEXCEPT {
Nikolas Klauser9806f452022-10-12 15:45:09 +02001036 return __builtin_copysignf(__x, __y);
Richard Smith081bb592015-10-08 20:40:34 +00001037}
Marek Kurdeja933f0d2021-07-21 15:58:17 +02001038
Marek Kurdeja933f0d2021-07-21 15:58:17 +02001039_LIBCPP_CONSTEXPR
Nikolas Klauser9806f452022-10-12 15:45:09 +02001040inline _LIBCPP_HIDE_FROM_ABI double __libcpp_copysign(double __x, double __y) _NOEXCEPT {
Nikolas Klauser9806f452022-10-12 15:45:09 +02001041 return __builtin_copysign(__x, __y);
Marek Kurdeja933f0d2021-07-21 15:58:17 +02001042}
1043
Marek Kurdeja933f0d2021-07-21 15:58:17 +02001044_LIBCPP_CONSTEXPR
Nikolas Klauser9806f452022-10-12 15:45:09 +02001045inline _LIBCPP_HIDE_FROM_ABI long double __libcpp_copysign(long double __x, long double __y) _NOEXCEPT {
Nikolas Klauser9806f452022-10-12 15:45:09 +02001046 return __builtin_copysignl(__x, __y);
Richard Smith081bb592015-10-08 20:40:34 +00001047}
Richard Smith081bb592015-10-08 20:40:34 +00001048
1049template <class _A1, class _A2>
Marek Kurdeja933f0d2021-07-21 15:58:17 +02001050_LIBCPP_CONSTEXPR
Nikolas Klauser4956e722022-10-12 15:41:22 +02001051inline _LIBCPP_HIDE_FROM_ABI
Louis Dionne9ce598d2021-09-08 09:14:43 -04001052typename std::__enable_if_t
Marek Kurdeja933f0d2021-07-21 15:58:17 +02001053<
1054 std::is_arithmetic<_A1>::value &&
1055 std::is_arithmetic<_A2>::value,
1056 std::__promote<_A1, _A2>
1057>::type
Nikolas Klauser9806f452022-10-12 15:45:09 +02001058__libcpp_copysign(_A1 __x, _A2 __y) _NOEXCEPT {
Marek Kurdeja933f0d2021-07-21 15:58:17 +02001059 typedef typename std::__promote<_A1, _A2>::type __result_type;
1060 static_assert((!(std::_IsSame<_A1, __result_type>::value &&
1061 std::_IsSame<_A2, __result_type>::value)), "");
Nikolas Klauser9806f452022-10-12 15:45:09 +02001062 return __builtin_copysign((__result_type)__x, (__result_type)__y);
Marek Kurdeja933f0d2021-07-21 15:58:17 +02001063}
1064
Nikolas Klauser9806f452022-10-12 15:45:09 +02001065inline _LIBCPP_HIDE_FROM_ABI float copysign(float __x, float __y) _NOEXCEPT {
1066 return ::__libcpp_copysign(__x, __y);
Marek Kurdeja933f0d2021-07-21 15:58:17 +02001067}
1068
Nikolas Klauser9806f452022-10-12 15:45:09 +02001069inline _LIBCPP_HIDE_FROM_ABI long double copysign(long double __x, long double __y) _NOEXCEPT {
1070 return ::__libcpp_copysign(__x, __y);
Marek Kurdeja933f0d2021-07-21 15:58:17 +02001071}
1072
1073template <class _A1, class _A2>
Nikolas Klauser4956e722022-10-12 15:41:22 +02001074inline _LIBCPP_HIDE_FROM_ABI
Louis Dionne9ce598d2021-09-08 09:14:43 -04001075typename std::__enable_if_t
Richard Smith081bb592015-10-08 20:40:34 +00001076<
1077 std::is_arithmetic<_A1>::value &&
1078 std::is_arithmetic<_A2>::value,
1079 std::__promote<_A1, _A2>
1080>::type
Nikolas Klauser9806f452022-10-12 15:45:09 +02001081 copysign(_A1 __x, _A2 __y) _NOEXCEPT {
1082 return ::__libcpp_copysign(__x, __y);
Richard Smith081bb592015-10-08 20:40:34 +00001083}
1084
Richard Smith081bb592015-10-08 20:40:34 +00001085// erf
1086
Nikolas Klauser04005952022-10-21 01:41:22 +02001087inline _LIBCPP_HIDE_FROM_ABI float erf(float __x) _NOEXCEPT {return __builtin_erff(__x);}
Nikolas Klauser52399652022-11-01 22:29:57 +01001088
1089template <class = int>
1090_LIBCPP_HIDE_FROM_ABI double erf(double __x) _NOEXCEPT {
1091 return __builtin_erf(__x);
1092}
1093
Nikolas Klauser04005952022-10-21 01:41:22 +02001094inline _LIBCPP_HIDE_FROM_ABI long double erf(long double __x) _NOEXCEPT {return __builtin_erfl(__x);}
Richard Smith081bb592015-10-08 20:40:34 +00001095
1096template <class _A1>
Nikolas Klauser4956e722022-10-12 15:41:22 +02001097inline _LIBCPP_HIDE_FROM_ABI
Richard Smith081bb592015-10-08 20:40:34 +00001098typename std::enable_if<std::is_integral<_A1>::value, double>::type
Nikolas Klauser04005952022-10-21 01:41:22 +02001099erf(_A1 __x) _NOEXCEPT {return __builtin_erf((double)__x);}
Richard Smith081bb592015-10-08 20:40:34 +00001100
1101// erfc
1102
Nikolas Klauser04005952022-10-21 01:41:22 +02001103inline _LIBCPP_HIDE_FROM_ABI float erfc(float __x) _NOEXCEPT {return __builtin_erfcf(__x);}
Nikolas Klauser52399652022-11-01 22:29:57 +01001104
1105template <class = int>
1106_LIBCPP_HIDE_FROM_ABI double erfc(double __x) _NOEXCEPT {
1107 return __builtin_erfc(__x);
1108}
1109
Nikolas Klauser04005952022-10-21 01:41:22 +02001110inline _LIBCPP_HIDE_FROM_ABI long double erfc(long double __x) _NOEXCEPT {return __builtin_erfcl(__x);}
Richard Smith081bb592015-10-08 20:40:34 +00001111
1112template <class _A1>
Nikolas Klauser4956e722022-10-12 15:41:22 +02001113inline _LIBCPP_HIDE_FROM_ABI
Richard Smith081bb592015-10-08 20:40:34 +00001114typename std::enable_if<std::is_integral<_A1>::value, double>::type
Nikolas Klauser04005952022-10-21 01:41:22 +02001115erfc(_A1 __x) _NOEXCEPT {return __builtin_erfc((double)__x);}
Richard Smith081bb592015-10-08 20:40:34 +00001116
1117// exp2
1118
Nikolas Klauser04005952022-10-21 01:41:22 +02001119inline _LIBCPP_HIDE_FROM_ABI float exp2(float __x) _NOEXCEPT {return __builtin_exp2f(__x);}
Nikolas Klauser52399652022-11-01 22:29:57 +01001120
1121template <class = int>
1122_LIBCPP_HIDE_FROM_ABI double exp2(double __x) _NOEXCEPT {
1123 return __builtin_exp2(__x);
1124}
1125
Nikolas Klauser04005952022-10-21 01:41:22 +02001126inline _LIBCPP_HIDE_FROM_ABI long double exp2(long double __x) _NOEXCEPT {return __builtin_exp2l(__x);}
Richard Smith081bb592015-10-08 20:40:34 +00001127
1128template <class _A1>
Nikolas Klauser4956e722022-10-12 15:41:22 +02001129inline _LIBCPP_HIDE_FROM_ABI
Richard Smith081bb592015-10-08 20:40:34 +00001130typename std::enable_if<std::is_integral<_A1>::value, double>::type
Nikolas Klauser04005952022-10-21 01:41:22 +02001131exp2(_A1 __x) _NOEXCEPT {return __builtin_exp2((double)__x);}
Richard Smith081bb592015-10-08 20:40:34 +00001132
1133// expm1
1134
Nikolas Klauser04005952022-10-21 01:41:22 +02001135inline _LIBCPP_HIDE_FROM_ABI float expm1(float __x) _NOEXCEPT {return __builtin_expm1f(__x);}
Nikolas Klauser52399652022-11-01 22:29:57 +01001136
1137template <class = int>
1138_LIBCPP_HIDE_FROM_ABI double expm1(double __x) _NOEXCEPT {
1139 return __builtin_expm1(__x);
1140}
1141
Nikolas Klauser04005952022-10-21 01:41:22 +02001142inline _LIBCPP_HIDE_FROM_ABI long double expm1(long double __x) _NOEXCEPT {return __builtin_expm1l(__x);}
Richard Smith081bb592015-10-08 20:40:34 +00001143
1144template <class _A1>
Nikolas Klauser4956e722022-10-12 15:41:22 +02001145inline _LIBCPP_HIDE_FROM_ABI
Richard Smith081bb592015-10-08 20:40:34 +00001146typename std::enable_if<std::is_integral<_A1>::value, double>::type
Nikolas Klauser04005952022-10-21 01:41:22 +02001147expm1(_A1 __x) _NOEXCEPT {return __builtin_expm1((double)__x);}
Richard Smith081bb592015-10-08 20:40:34 +00001148
1149// fdim
1150
Nikolas Klauser04005952022-10-21 01:41:22 +02001151inline _LIBCPP_HIDE_FROM_ABI float fdim(float __x, float __y) _NOEXCEPT {return __builtin_fdimf(__x, __y);}
Nikolas Klauser52399652022-11-01 22:29:57 +01001152
1153template <class = int>
1154_LIBCPP_HIDE_FROM_ABI double fdim(double __x, double __y) _NOEXCEPT {
1155 return __builtin_fdim(__x, __y);
1156}
1157
Nikolas Klauser04005952022-10-21 01:41:22 +02001158inline _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 +00001159
1160template <class _A1, class _A2>
Nikolas Klauser4956e722022-10-12 15:41:22 +02001161inline _LIBCPP_HIDE_FROM_ABI
Louis Dionne9ce598d2021-09-08 09:14:43 -04001162typename std::__enable_if_t
Richard Smith081bb592015-10-08 20:40:34 +00001163<
1164 std::is_arithmetic<_A1>::value &&
1165 std::is_arithmetic<_A2>::value,
1166 std::__promote<_A1, _A2>
1167>::type
Nikolas Klauser9806f452022-10-12 15:45:09 +02001168fdim(_A1 __x, _A2 __y) _NOEXCEPT
Richard Smith081bb592015-10-08 20:40:34 +00001169{
1170 typedef typename std::__promote<_A1, _A2>::type __result_type;
Eric Fiselier3906a132019-06-23 20:28:29 +00001171 static_assert((!(std::_IsSame<_A1, __result_type>::value &&
1172 std::_IsSame<_A2, __result_type>::value)), "");
Nikolas Klauser9806f452022-10-12 15:45:09 +02001173 return ::fdim((__result_type)__x, (__result_type)__y);
Richard Smith081bb592015-10-08 20:40:34 +00001174}
1175
1176// fma
1177
Nikolas Klauser9806f452022-10-12 15:45:09 +02001178inline _LIBCPP_HIDE_FROM_ABI float fma(float __x, float __y, float __z) _NOEXCEPT
Ilya Tokarc3abffb2021-02-10 13:05:19 -05001179{
Nikolas Klauser9806f452022-10-12 15:45:09 +02001180 return __builtin_fmaf(__x, __y, __z);
Ilya Tokarc3abffb2021-02-10 13:05:19 -05001181}
Nikolas Klauser52399652022-11-01 22:29:57 +01001182
1183
1184template <class = int>
1185_LIBCPP_HIDE_FROM_ABI double fma(double __x, double __y, double __z) _NOEXCEPT {
1186 return __builtin_fma(__x, __y, __z);
1187}
1188
Nikolas Klauser9806f452022-10-12 15:45:09 +02001189inline _LIBCPP_HIDE_FROM_ABI long double fma(long double __x, long double __y, long double __z) _NOEXCEPT
Ilya Tokarc3abffb2021-02-10 13:05:19 -05001190{
Nikolas Klauser9806f452022-10-12 15:45:09 +02001191 return __builtin_fmal(__x, __y, __z);
Ilya Tokarc3abffb2021-02-10 13:05:19 -05001192}
Richard Smith081bb592015-10-08 20:40:34 +00001193
1194template <class _A1, class _A2, class _A3>
Nikolas Klauser4956e722022-10-12 15:41:22 +02001195inline _LIBCPP_HIDE_FROM_ABI
Louis Dionne9ce598d2021-09-08 09:14:43 -04001196typename std::__enable_if_t
Richard Smith081bb592015-10-08 20:40:34 +00001197<
1198 std::is_arithmetic<_A1>::value &&
1199 std::is_arithmetic<_A2>::value &&
1200 std::is_arithmetic<_A3>::value,
1201 std::__promote<_A1, _A2, _A3>
1202>::type
Nikolas Klauser9806f452022-10-12 15:45:09 +02001203fma(_A1 __x, _A2 __y, _A3 __z) _NOEXCEPT
Richard Smith081bb592015-10-08 20:40:34 +00001204{
1205 typedef typename std::__promote<_A1, _A2, _A3>::type __result_type;
Eric Fiselier3906a132019-06-23 20:28:29 +00001206 static_assert((!(std::_IsSame<_A1, __result_type>::value &&
1207 std::_IsSame<_A2, __result_type>::value &&
1208 std::_IsSame<_A3, __result_type>::value)), "");
Nikolas Klauser9806f452022-10-12 15:45:09 +02001209 return __builtin_fma((__result_type)__x, (__result_type)__y, (__result_type)__z);
Richard Smith081bb592015-10-08 20:40:34 +00001210}
1211
1212// fmax
1213
Nikolas Klauser04005952022-10-21 01:41:22 +02001214inline _LIBCPP_HIDE_FROM_ABI float fmax(float __x, float __y) _NOEXCEPT {return __builtin_fmaxf(__x, __y);}
Nikolas Klauser52399652022-11-01 22:29:57 +01001215
1216template <class = int>
1217_LIBCPP_HIDE_FROM_ABI double fmax(double __x, double __y) _NOEXCEPT {
1218 return __builtin_fmax(__x, __y);
1219}
1220
Nikolas Klauser04005952022-10-21 01:41:22 +02001221inline _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 +00001222
1223template <class _A1, class _A2>
Nikolas Klauser4956e722022-10-12 15:41:22 +02001224inline _LIBCPP_HIDE_FROM_ABI
Louis Dionne9ce598d2021-09-08 09:14:43 -04001225typename std::__enable_if_t
Richard Smith081bb592015-10-08 20:40:34 +00001226<
1227 std::is_arithmetic<_A1>::value &&
1228 std::is_arithmetic<_A2>::value,
1229 std::__promote<_A1, _A2>
1230>::type
Nikolas Klauser9806f452022-10-12 15:45:09 +02001231fmax(_A1 __x, _A2 __y) _NOEXCEPT
Richard Smith081bb592015-10-08 20:40:34 +00001232{
1233 typedef typename std::__promote<_A1, _A2>::type __result_type;
Eric Fiselier3906a132019-06-23 20:28:29 +00001234 static_assert((!(std::_IsSame<_A1, __result_type>::value &&
1235 std::_IsSame<_A2, __result_type>::value)), "");
Nikolas Klauser9806f452022-10-12 15:45:09 +02001236 return ::fmax((__result_type)__x, (__result_type)__y);
Richard Smith081bb592015-10-08 20:40:34 +00001237}
1238
1239// fmin
1240
Nikolas Klauser04005952022-10-21 01:41:22 +02001241inline _LIBCPP_HIDE_FROM_ABI float fmin(float __x, float __y) _NOEXCEPT {return __builtin_fminf(__x, __y);}
Nikolas Klauser52399652022-11-01 22:29:57 +01001242
1243template <class = int>
1244_LIBCPP_HIDE_FROM_ABI double fmin(double __x, double __y) _NOEXCEPT {
1245 return __builtin_fmin(__x, __y);
1246}
1247
Nikolas Klauser04005952022-10-21 01:41:22 +02001248inline _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 +00001249
1250template <class _A1, class _A2>
Nikolas Klauser4956e722022-10-12 15:41:22 +02001251inline _LIBCPP_HIDE_FROM_ABI
Louis Dionne9ce598d2021-09-08 09:14:43 -04001252typename std::__enable_if_t
Richard Smith081bb592015-10-08 20:40:34 +00001253<
1254 std::is_arithmetic<_A1>::value &&
1255 std::is_arithmetic<_A2>::value,
1256 std::__promote<_A1, _A2>
1257>::type
Nikolas Klauser9806f452022-10-12 15:45:09 +02001258fmin(_A1 __x, _A2 __y) _NOEXCEPT
Richard Smith081bb592015-10-08 20:40:34 +00001259{
1260 typedef typename std::__promote<_A1, _A2>::type __result_type;
Eric Fiselier3906a132019-06-23 20:28:29 +00001261 static_assert((!(std::_IsSame<_A1, __result_type>::value &&
1262 std::_IsSame<_A2, __result_type>::value)), "");
Nikolas Klauser9806f452022-10-12 15:45:09 +02001263 return ::fmin((__result_type)__x, (__result_type)__y);
Richard Smith081bb592015-10-08 20:40:34 +00001264}
1265
1266// hypot
1267
Nikolas Klauser04005952022-10-21 01:41:22 +02001268inline _LIBCPP_HIDE_FROM_ABI float hypot(float __x, float __y) _NOEXCEPT {return __builtin_hypotf(__x, __y);}
Nikolas Klauser52399652022-11-01 22:29:57 +01001269
1270template <class = int>
1271_LIBCPP_HIDE_FROM_ABI double hypot(double __x, double __y) _NOEXCEPT {
1272 return __builtin_hypot(__x, __y);
1273}
1274
Nikolas Klauser04005952022-10-21 01:41:22 +02001275inline _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 +00001276
1277template <class _A1, class _A2>
Nikolas Klauser4956e722022-10-12 15:41:22 +02001278inline _LIBCPP_HIDE_FROM_ABI
Louis Dionne9ce598d2021-09-08 09:14:43 -04001279typename std::__enable_if_t
Richard Smith081bb592015-10-08 20:40:34 +00001280<
1281 std::is_arithmetic<_A1>::value &&
1282 std::is_arithmetic<_A2>::value,
1283 std::__promote<_A1, _A2>
1284>::type
Nikolas Klauser9806f452022-10-12 15:45:09 +02001285hypot(_A1 __x, _A2 __y) _NOEXCEPT
Richard Smith081bb592015-10-08 20:40:34 +00001286{
1287 typedef typename std::__promote<_A1, _A2>::type __result_type;
Eric Fiselier3906a132019-06-23 20:28:29 +00001288 static_assert((!(std::_IsSame<_A1, __result_type>::value &&
1289 std::_IsSame<_A2, __result_type>::value)), "");
Nikolas Klauser9806f452022-10-12 15:45:09 +02001290 return ::hypot((__result_type)__x, (__result_type)__y);
Richard Smith081bb592015-10-08 20:40:34 +00001291}
1292
1293// ilogb
1294
Nikolas Klauser04005952022-10-21 01:41:22 +02001295inline _LIBCPP_HIDE_FROM_ABI int ilogb(float __x) _NOEXCEPT {return __builtin_ilogbf(__x);}
Nikolas Klauser52399652022-11-01 22:29:57 +01001296
1297template <class = int>
1298_LIBCPP_HIDE_FROM_ABI double ilogb(double __x) _NOEXCEPT {
1299 return __builtin_ilogb(__x);
1300}
1301
Nikolas Klauser04005952022-10-21 01:41:22 +02001302inline _LIBCPP_HIDE_FROM_ABI int ilogb(long double __x) _NOEXCEPT {return __builtin_ilogbl(__x);}
Richard Smith081bb592015-10-08 20:40:34 +00001303
1304template <class _A1>
Nikolas Klauser4956e722022-10-12 15:41:22 +02001305inline _LIBCPP_HIDE_FROM_ABI
Richard Smith081bb592015-10-08 20:40:34 +00001306typename std::enable_if<std::is_integral<_A1>::value, int>::type
Nikolas Klauser04005952022-10-21 01:41:22 +02001307ilogb(_A1 __x) _NOEXCEPT {return __builtin_ilogb((double)__x);}
Richard Smith081bb592015-10-08 20:40:34 +00001308
1309// lgamma
1310
Nikolas Klauser04005952022-10-21 01:41:22 +02001311inline _LIBCPP_HIDE_FROM_ABI float lgamma(float __x) _NOEXCEPT {return __builtin_lgammaf(__x);}
Nikolas Klauser52399652022-11-01 22:29:57 +01001312
1313template <class = int>
1314_LIBCPP_HIDE_FROM_ABI double lgamma(double __x) _NOEXCEPT {
1315 return __builtin_lgamma(__x);
1316}
1317
Nikolas Klauser04005952022-10-21 01:41:22 +02001318inline _LIBCPP_HIDE_FROM_ABI long double lgamma(long double __x) _NOEXCEPT {return __builtin_lgammal(__x);}
Richard Smith081bb592015-10-08 20:40:34 +00001319
1320template <class _A1>
Nikolas Klauser4956e722022-10-12 15:41:22 +02001321inline _LIBCPP_HIDE_FROM_ABI
Richard Smith081bb592015-10-08 20:40:34 +00001322typename std::enable_if<std::is_integral<_A1>::value, double>::type
Nikolas Klauser04005952022-10-21 01:41:22 +02001323lgamma(_A1 __x) _NOEXCEPT {return __builtin_lgamma((double)__x);}
Richard Smith081bb592015-10-08 20:40:34 +00001324
1325// llrint
1326
Nikolas Klauser9806f452022-10-12 15:45:09 +02001327inline _LIBCPP_HIDE_FROM_ABI long long llrint(float __x) _NOEXCEPT
Ilya Tokarc3abffb2021-02-10 13:05:19 -05001328{
Nikolas Klauser9806f452022-10-12 15:45:09 +02001329 return __builtin_llrintf(__x);
Ilya Tokarc3abffb2021-02-10 13:05:19 -05001330}
Nikolas Klauser52399652022-11-01 22:29:57 +01001331
1332template <class = int>
1333_LIBCPP_HIDE_FROM_ABI long long llrint(double __x) _NOEXCEPT {
1334 return __builtin_llrint(__x);
1335}
1336
Nikolas Klauser9806f452022-10-12 15:45:09 +02001337inline _LIBCPP_HIDE_FROM_ABI long long llrint(long double __x) _NOEXCEPT
Ilya Tokarc3abffb2021-02-10 13:05:19 -05001338{
Nikolas Klauser9806f452022-10-12 15:45:09 +02001339 return __builtin_llrintl(__x);
Ilya Tokarc3abffb2021-02-10 13:05:19 -05001340}
Richard Smith081bb592015-10-08 20:40:34 +00001341
1342template <class _A1>
Nikolas Klauser4956e722022-10-12 15:41:22 +02001343inline _LIBCPP_HIDE_FROM_ABI
Richard Smith081bb592015-10-08 20:40:34 +00001344typename std::enable_if<std::is_integral<_A1>::value, long long>::type
Nikolas Klauser9806f452022-10-12 15:45:09 +02001345llrint(_A1 __x) _NOEXCEPT
Ilya Tokarc3abffb2021-02-10 13:05:19 -05001346{
Nikolas Klauser9806f452022-10-12 15:45:09 +02001347 return __builtin_llrint((double)__x);
Ilya Tokarc3abffb2021-02-10 13:05:19 -05001348}
Richard Smith081bb592015-10-08 20:40:34 +00001349
1350// llround
1351
Nikolas Klauser9806f452022-10-12 15:45:09 +02001352inline _LIBCPP_HIDE_FROM_ABI long long llround(float __x) _NOEXCEPT
Ilya Tokarc3abffb2021-02-10 13:05:19 -05001353{
Nikolas Klauser9806f452022-10-12 15:45:09 +02001354 return __builtin_llroundf(__x);
Ilya Tokarc3abffb2021-02-10 13:05:19 -05001355}
Nikolas Klauser52399652022-11-01 22:29:57 +01001356
1357template <class = int>
1358_LIBCPP_HIDE_FROM_ABI long long llround(double __x) _NOEXCEPT {
1359 return __builtin_llround(__x);
1360}
1361
Nikolas Klauser9806f452022-10-12 15:45:09 +02001362inline _LIBCPP_HIDE_FROM_ABI long long llround(long double __x) _NOEXCEPT
Ilya Tokarc3abffb2021-02-10 13:05:19 -05001363{
Nikolas Klauser9806f452022-10-12 15:45:09 +02001364 return __builtin_llroundl(__x);
Ilya Tokarc3abffb2021-02-10 13:05:19 -05001365}
Richard Smith081bb592015-10-08 20:40:34 +00001366
1367template <class _A1>
Nikolas Klauser4956e722022-10-12 15:41:22 +02001368inline _LIBCPP_HIDE_FROM_ABI
Richard Smith081bb592015-10-08 20:40:34 +00001369typename std::enable_if<std::is_integral<_A1>::value, long long>::type
Nikolas Klauser9806f452022-10-12 15:45:09 +02001370llround(_A1 __x) _NOEXCEPT
Ilya Tokarc3abffb2021-02-10 13:05:19 -05001371{
Nikolas Klauser9806f452022-10-12 15:45:09 +02001372 return __builtin_llround((double)__x);
Ilya Tokarc3abffb2021-02-10 13:05:19 -05001373}
Richard Smith081bb592015-10-08 20:40:34 +00001374
1375// log1p
1376
Nikolas Klauser04005952022-10-21 01:41:22 +02001377inline _LIBCPP_HIDE_FROM_ABI float log1p(float __x) _NOEXCEPT {return __builtin_log1pf(__x);}
Nikolas Klauser52399652022-11-01 22:29:57 +01001378
1379template <class = int>
1380_LIBCPP_HIDE_FROM_ABI double log1p(double __x) _NOEXCEPT {
1381 return __builtin_log1p(__x);
1382}
1383
Nikolas Klauser04005952022-10-21 01:41:22 +02001384inline _LIBCPP_HIDE_FROM_ABI long double log1p(long double __x) _NOEXCEPT {return __builtin_log1pl(__x);}
Richard Smith081bb592015-10-08 20:40:34 +00001385
1386template <class _A1>
Nikolas Klauser4956e722022-10-12 15:41:22 +02001387inline _LIBCPP_HIDE_FROM_ABI
Richard Smith081bb592015-10-08 20:40:34 +00001388typename std::enable_if<std::is_integral<_A1>::value, double>::type
Nikolas Klauser04005952022-10-21 01:41:22 +02001389log1p(_A1 __x) _NOEXCEPT {return __builtin_log1p((double)__x);}
Richard Smith081bb592015-10-08 20:40:34 +00001390
1391// log2
1392
Nikolas Klauser04005952022-10-21 01:41:22 +02001393inline _LIBCPP_HIDE_FROM_ABI float log2(float __x) _NOEXCEPT {return __builtin_log2f(__x);}
Nikolas Klauser52399652022-11-01 22:29:57 +01001394
1395template <class = int>
1396_LIBCPP_HIDE_FROM_ABI double log2(double __x) _NOEXCEPT {
1397 return __builtin_log2(__x);
1398}
1399
Nikolas Klauser04005952022-10-21 01:41:22 +02001400inline _LIBCPP_HIDE_FROM_ABI long double log2(long double __x) _NOEXCEPT {return __builtin_log2l(__x);}
Richard Smith081bb592015-10-08 20:40:34 +00001401
1402template <class _A1>
Nikolas Klauser4956e722022-10-12 15:41:22 +02001403inline _LIBCPP_HIDE_FROM_ABI
Richard Smith081bb592015-10-08 20:40:34 +00001404typename std::enable_if<std::is_integral<_A1>::value, double>::type
Nikolas Klauser04005952022-10-21 01:41:22 +02001405log2(_A1 __x) _NOEXCEPT {return __builtin_log2((double)__x);}
Richard Smith081bb592015-10-08 20:40:34 +00001406
1407// logb
1408
Nikolas Klauser04005952022-10-21 01:41:22 +02001409inline _LIBCPP_HIDE_FROM_ABI float logb(float __x) _NOEXCEPT {return __builtin_logbf(__x);}
Nikolas Klauser52399652022-11-01 22:29:57 +01001410
1411template <class = int>
1412_LIBCPP_HIDE_FROM_ABI double logb(double __x) _NOEXCEPT {
1413 return __builtin_logb(__x);
1414}
1415
Nikolas Klauser04005952022-10-21 01:41:22 +02001416inline _LIBCPP_HIDE_FROM_ABI long double logb(long double __x) _NOEXCEPT {return __builtin_logbl(__x);}
Richard Smith081bb592015-10-08 20:40:34 +00001417
1418template <class _A1>
Nikolas Klauser4956e722022-10-12 15:41:22 +02001419inline _LIBCPP_HIDE_FROM_ABI
Richard Smith081bb592015-10-08 20:40:34 +00001420typename std::enable_if<std::is_integral<_A1>::value, double>::type
Nikolas Klauser04005952022-10-21 01:41:22 +02001421logb(_A1 __x) _NOEXCEPT {return __builtin_logb((double)__x);}
Richard Smith081bb592015-10-08 20:40:34 +00001422
1423// lrint
1424
Nikolas Klauser9806f452022-10-12 15:45:09 +02001425inline _LIBCPP_HIDE_FROM_ABI long lrint(float __x) _NOEXCEPT
Ilya Tokarc3abffb2021-02-10 13:05:19 -05001426{
Nikolas Klauser9806f452022-10-12 15:45:09 +02001427 return __builtin_lrintf(__x);
Ilya Tokarc3abffb2021-02-10 13:05:19 -05001428}
Nikolas Klauser52399652022-11-01 22:29:57 +01001429
1430template <class = int>
1431_LIBCPP_HIDE_FROM_ABI long lrint(double __x) _NOEXCEPT {
1432 return __builtin_lrint(__x);
1433}
1434
Nikolas Klauser9806f452022-10-12 15:45:09 +02001435inline _LIBCPP_HIDE_FROM_ABI long lrint(long double __x) _NOEXCEPT
Ilya Tokarc3abffb2021-02-10 13:05:19 -05001436{
Nikolas Klauser9806f452022-10-12 15:45:09 +02001437 return __builtin_lrintl(__x);
Ilya Tokarc3abffb2021-02-10 13:05:19 -05001438}
Richard Smith081bb592015-10-08 20:40:34 +00001439
1440template <class _A1>
Nikolas Klauser4956e722022-10-12 15:41:22 +02001441inline _LIBCPP_HIDE_FROM_ABI
Richard Smith081bb592015-10-08 20:40:34 +00001442typename std::enable_if<std::is_integral<_A1>::value, long>::type
Nikolas Klauser9806f452022-10-12 15:45:09 +02001443lrint(_A1 __x) _NOEXCEPT
Ilya Tokarc3abffb2021-02-10 13:05:19 -05001444{
Nikolas Klauser9806f452022-10-12 15:45:09 +02001445 return __builtin_lrint((double)__x);
Ilya Tokarc3abffb2021-02-10 13:05:19 -05001446}
Richard Smith081bb592015-10-08 20:40:34 +00001447
1448// lround
1449
Nikolas Klauser9806f452022-10-12 15:45:09 +02001450inline _LIBCPP_HIDE_FROM_ABI long lround(float __x) _NOEXCEPT
Ilya Tokarc3abffb2021-02-10 13:05:19 -05001451{
Nikolas Klauser9806f452022-10-12 15:45:09 +02001452 return __builtin_lroundf(__x);
Ilya Tokarc3abffb2021-02-10 13:05:19 -05001453}
Nikolas Klauser52399652022-11-01 22:29:57 +01001454
1455template <class = int>
1456_LIBCPP_HIDE_FROM_ABI long lround(double __x) _NOEXCEPT {
1457 return __builtin_lround(__x);
1458}
1459
Nikolas Klauser9806f452022-10-12 15:45:09 +02001460inline _LIBCPP_HIDE_FROM_ABI long lround(long double __x) _NOEXCEPT
Ilya Tokarc3abffb2021-02-10 13:05:19 -05001461{
Nikolas Klauser9806f452022-10-12 15:45:09 +02001462 return __builtin_lroundl(__x);
Ilya Tokarc3abffb2021-02-10 13:05:19 -05001463}
Richard Smith081bb592015-10-08 20:40:34 +00001464
1465template <class _A1>
Nikolas Klauser4956e722022-10-12 15:41:22 +02001466inline _LIBCPP_HIDE_FROM_ABI
Richard Smith081bb592015-10-08 20:40:34 +00001467typename std::enable_if<std::is_integral<_A1>::value, long>::type
Nikolas Klauser9806f452022-10-12 15:45:09 +02001468lround(_A1 __x) _NOEXCEPT
Ilya Tokarc3abffb2021-02-10 13:05:19 -05001469{
Nikolas Klauser9806f452022-10-12 15:45:09 +02001470 return __builtin_lround((double)__x);
Ilya Tokarc3abffb2021-02-10 13:05:19 -05001471}
Richard Smith081bb592015-10-08 20:40:34 +00001472
1473// nan
1474
1475// nearbyint
1476
Nikolas Klauser04005952022-10-21 01:41:22 +02001477inline _LIBCPP_HIDE_FROM_ABI float nearbyint(float __x) _NOEXCEPT {return __builtin_nearbyintf(__x);}
Nikolas Klauser52399652022-11-01 22:29:57 +01001478
1479template <class = int>
1480_LIBCPP_HIDE_FROM_ABI double nearbyint(double __x) _NOEXCEPT {
1481 return __builtin_nearbyint(__x);
1482}
1483
Nikolas Klauser04005952022-10-21 01:41:22 +02001484inline _LIBCPP_HIDE_FROM_ABI long double nearbyint(long double __x) _NOEXCEPT {return __builtin_nearbyintl(__x);}
Richard Smith081bb592015-10-08 20:40:34 +00001485
1486template <class _A1>
Nikolas Klauser4956e722022-10-12 15:41:22 +02001487inline _LIBCPP_HIDE_FROM_ABI
Richard Smith081bb592015-10-08 20:40:34 +00001488typename std::enable_if<std::is_integral<_A1>::value, double>::type
Nikolas Klauser04005952022-10-21 01:41:22 +02001489nearbyint(_A1 __x) _NOEXCEPT {return __builtin_nearbyint((double)__x);}
Richard Smith081bb592015-10-08 20:40:34 +00001490
1491// nextafter
1492
Nikolas Klauser04005952022-10-21 01:41:22 +02001493inline _LIBCPP_HIDE_FROM_ABI float nextafter(float __x, float __y) _NOEXCEPT {return __builtin_nextafterf(__x, __y);}
Nikolas Klauser52399652022-11-01 22:29:57 +01001494
1495template <class = int>
1496_LIBCPP_HIDE_FROM_ABI double nextafter(double __x, double __y) _NOEXCEPT {
1497 return __builtin_nextafter(__x, __y);
1498}
1499
Nikolas Klauser04005952022-10-21 01:41:22 +02001500inline _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 +00001501
1502template <class _A1, class _A2>
Nikolas Klauser4956e722022-10-12 15:41:22 +02001503inline _LIBCPP_HIDE_FROM_ABI
Louis Dionne9ce598d2021-09-08 09:14:43 -04001504typename std::__enable_if_t
Richard Smith081bb592015-10-08 20:40:34 +00001505<
1506 std::is_arithmetic<_A1>::value &&
1507 std::is_arithmetic<_A2>::value,
1508 std::__promote<_A1, _A2>
1509>::type
Nikolas Klauser9806f452022-10-12 15:45:09 +02001510nextafter(_A1 __x, _A2 __y) _NOEXCEPT
Richard Smith081bb592015-10-08 20:40:34 +00001511{
1512 typedef typename std::__promote<_A1, _A2>::type __result_type;
Eric Fiselier3906a132019-06-23 20:28:29 +00001513 static_assert((!(std::_IsSame<_A1, __result_type>::value &&
1514 std::_IsSame<_A2, __result_type>::value)), "");
Nikolas Klauser9806f452022-10-12 15:45:09 +02001515 return ::nextafter((__result_type)__x, (__result_type)__y);
Richard Smith081bb592015-10-08 20:40:34 +00001516}
1517
1518// nexttoward
1519
Nikolas Klauser04005952022-10-21 01:41:22 +02001520inline _LIBCPP_HIDE_FROM_ABI float nexttoward(float __x, long double __y) _NOEXCEPT {return __builtin_nexttowardf(__x, __y);}
Nikolas Klauser52399652022-11-01 22:29:57 +01001521
1522template <class = int>
1523_LIBCPP_HIDE_FROM_ABI double nexttoward(double __x, long double __y) _NOEXCEPT {
1524 return __builtin_nexttoward(__x, __y);
1525}
1526
Nikolas Klauser04005952022-10-21 01:41:22 +02001527inline _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 +00001528
1529template <class _A1>
Nikolas Klauser4956e722022-10-12 15:41:22 +02001530inline _LIBCPP_HIDE_FROM_ABI
Richard Smith081bb592015-10-08 20:40:34 +00001531typename std::enable_if<std::is_integral<_A1>::value, double>::type
Nikolas Klauser04005952022-10-21 01:41:22 +02001532nexttoward(_A1 __x, long double __y) _NOEXCEPT {return __builtin_nexttoward((double)__x, __y);}
Richard Smith081bb592015-10-08 20:40:34 +00001533
1534// remainder
1535
Nikolas Klauser04005952022-10-21 01:41:22 +02001536inline _LIBCPP_HIDE_FROM_ABI float remainder(float __x, float __y) _NOEXCEPT {return __builtin_remainderf(__x, __y);}
Nikolas Klauser52399652022-11-01 22:29:57 +01001537
1538template <class = int>
1539_LIBCPP_HIDE_FROM_ABI double remainder(double __x, double __y) _NOEXCEPT {
1540 return __builtin_remainder(__x, __y);
1541}
1542
Nikolas Klauser04005952022-10-21 01:41:22 +02001543inline _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 +00001544
1545template <class _A1, class _A2>
Nikolas Klauser4956e722022-10-12 15:41:22 +02001546inline _LIBCPP_HIDE_FROM_ABI
Louis Dionne9ce598d2021-09-08 09:14:43 -04001547typename std::__enable_if_t
Richard Smith081bb592015-10-08 20:40:34 +00001548<
1549 std::is_arithmetic<_A1>::value &&
1550 std::is_arithmetic<_A2>::value,
1551 std::__promote<_A1, _A2>
1552>::type
Nikolas Klauser9806f452022-10-12 15:45:09 +02001553remainder(_A1 __x, _A2 __y) _NOEXCEPT
Richard Smith081bb592015-10-08 20:40:34 +00001554{
1555 typedef typename std::__promote<_A1, _A2>::type __result_type;
Eric Fiselier3906a132019-06-23 20:28:29 +00001556 static_assert((!(std::_IsSame<_A1, __result_type>::value &&
1557 std::_IsSame<_A2, __result_type>::value)), "");
Nikolas Klauser9806f452022-10-12 15:45:09 +02001558 return ::remainder((__result_type)__x, (__result_type)__y);
Richard Smith081bb592015-10-08 20:40:34 +00001559}
1560
1561// remquo
1562
Nikolas Klauser04005952022-10-21 01:41:22 +02001563inline _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 +01001564
1565template <class = int>
1566_LIBCPP_HIDE_FROM_ABI double remquo(double __x, double __y, int* __z) _NOEXCEPT {
1567 return __builtin_remquo(__x, __y, __z);
1568}
1569
Nikolas Klauser04005952022-10-21 01:41:22 +02001570inline _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 +00001571
1572template <class _A1, class _A2>
Nikolas Klauser4956e722022-10-12 15:41:22 +02001573inline _LIBCPP_HIDE_FROM_ABI
Louis Dionne9ce598d2021-09-08 09:14:43 -04001574typename std::__enable_if_t
Richard Smith081bb592015-10-08 20:40:34 +00001575<
1576 std::is_arithmetic<_A1>::value &&
1577 std::is_arithmetic<_A2>::value,
1578 std::__promote<_A1, _A2>
1579>::type
Nikolas Klauser9806f452022-10-12 15:45:09 +02001580remquo(_A1 __x, _A2 __y, int* __z) _NOEXCEPT
Richard Smith081bb592015-10-08 20:40:34 +00001581{
1582 typedef typename std::__promote<_A1, _A2>::type __result_type;
Eric Fiselier3906a132019-06-23 20:28:29 +00001583 static_assert((!(std::_IsSame<_A1, __result_type>::value &&
1584 std::_IsSame<_A2, __result_type>::value)), "");
Nikolas Klauser9806f452022-10-12 15:45:09 +02001585 return ::remquo((__result_type)__x, (__result_type)__y, __z);
Richard Smith081bb592015-10-08 20:40:34 +00001586}
1587
1588// rint
1589
Nikolas Klauser9806f452022-10-12 15:45:09 +02001590inline _LIBCPP_HIDE_FROM_ABI float rint(float __x) _NOEXCEPT
Ilya Tokarc3abffb2021-02-10 13:05:19 -05001591{
Nikolas Klauser9806f452022-10-12 15:45:09 +02001592 return __builtin_rintf(__x);
Ilya Tokarc3abffb2021-02-10 13:05:19 -05001593}
Nikolas Klauser52399652022-11-01 22:29:57 +01001594
1595template <class = int>
1596_LIBCPP_HIDE_FROM_ABI double rint(double __x) _NOEXCEPT {
1597 return __builtin_rint(__x);
1598}
1599
Nikolas Klauser9806f452022-10-12 15:45:09 +02001600inline _LIBCPP_HIDE_FROM_ABI long double rint(long double __x) _NOEXCEPT
Ilya Tokarc3abffb2021-02-10 13:05:19 -05001601{
Nikolas Klauser9806f452022-10-12 15:45:09 +02001602 return __builtin_rintl(__x);
Ilya Tokarc3abffb2021-02-10 13:05:19 -05001603}
Richard Smith081bb592015-10-08 20:40:34 +00001604
1605template <class _A1>
Nikolas Klauser4956e722022-10-12 15:41:22 +02001606inline _LIBCPP_HIDE_FROM_ABI
Richard Smith081bb592015-10-08 20:40:34 +00001607typename std::enable_if<std::is_integral<_A1>::value, double>::type
Nikolas Klauser9806f452022-10-12 15:45:09 +02001608rint(_A1 __x) _NOEXCEPT
Ilya Tokarc3abffb2021-02-10 13:05:19 -05001609{
Nikolas Klauser9806f452022-10-12 15:45:09 +02001610 return __builtin_rint((double)__x);
Ilya Tokarc3abffb2021-02-10 13:05:19 -05001611}
Richard Smith081bb592015-10-08 20:40:34 +00001612
1613// round
1614
Nikolas Klauser9806f452022-10-12 15:45:09 +02001615inline _LIBCPP_HIDE_FROM_ABI float round(float __x) _NOEXCEPT
Ilya Tokarc3abffb2021-02-10 13:05:19 -05001616{
Nikolas Klauser9806f452022-10-12 15:45:09 +02001617 return __builtin_round(__x);
Ilya Tokarc3abffb2021-02-10 13:05:19 -05001618}
Nikolas Klauser52399652022-11-01 22:29:57 +01001619
1620template <class = int>
1621_LIBCPP_HIDE_FROM_ABI double round(double __x) _NOEXCEPT {
1622 return __builtin_round(__x);
1623}
1624
Nikolas Klauser9806f452022-10-12 15:45:09 +02001625inline _LIBCPP_HIDE_FROM_ABI long double round(long double __x) _NOEXCEPT
Ilya Tokarc3abffb2021-02-10 13:05:19 -05001626{
Nikolas Klauser9806f452022-10-12 15:45:09 +02001627 return __builtin_roundl(__x);
Ilya Tokarc3abffb2021-02-10 13:05:19 -05001628}
Richard Smith081bb592015-10-08 20:40:34 +00001629
1630template <class _A1>
Nikolas Klauser4956e722022-10-12 15:41:22 +02001631inline _LIBCPP_HIDE_FROM_ABI
Richard Smith081bb592015-10-08 20:40:34 +00001632typename std::enable_if<std::is_integral<_A1>::value, double>::type
Nikolas Klauser9806f452022-10-12 15:45:09 +02001633round(_A1 __x) _NOEXCEPT
Ilya Tokarc3abffb2021-02-10 13:05:19 -05001634{
Nikolas Klauser9806f452022-10-12 15:45:09 +02001635 return __builtin_round((double)__x);
Ilya Tokarc3abffb2021-02-10 13:05:19 -05001636}
Richard Smith081bb592015-10-08 20:40:34 +00001637
1638// scalbln
1639
Nikolas Klauser04005952022-10-21 01:41:22 +02001640inline _LIBCPP_HIDE_FROM_ABI float scalbln(float __x, long __y) _NOEXCEPT {return __builtin_scalblnf(__x, __y);}
Nikolas Klauser52399652022-11-01 22:29:57 +01001641
1642template <class = int>
1643_LIBCPP_HIDE_FROM_ABI double scalbln(double __x, long __y) _NOEXCEPT {
1644 return __builtin_scalbln(__x, __y);
1645}
1646
Nikolas Klauser04005952022-10-21 01:41:22 +02001647inline _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 +00001648
1649template <class _A1>
Nikolas Klauser4956e722022-10-12 15:41:22 +02001650inline _LIBCPP_HIDE_FROM_ABI
Richard Smith081bb592015-10-08 20:40:34 +00001651typename std::enable_if<std::is_integral<_A1>::value, double>::type
Nikolas Klauser04005952022-10-21 01:41:22 +02001652scalbln(_A1 __x, long __y) _NOEXCEPT {return __builtin_scalbln((double)__x, __y);}
Richard Smith081bb592015-10-08 20:40:34 +00001653
1654// scalbn
1655
Nikolas Klauser04005952022-10-21 01:41:22 +02001656inline _LIBCPP_HIDE_FROM_ABI float scalbn(float __x, int __y) _NOEXCEPT {return __builtin_scalbnf(__x, __y);}
Nikolas Klauser52399652022-11-01 22:29:57 +01001657
1658template <class = int>
1659_LIBCPP_HIDE_FROM_ABI double scalbn(double __x, int __y) _NOEXCEPT {
1660 return __builtin_scalbn(__x, __y);
1661}
1662
Nikolas Klauser04005952022-10-21 01:41:22 +02001663inline _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 +00001664
1665template <class _A1>
Nikolas Klauser4956e722022-10-12 15:41:22 +02001666inline _LIBCPP_HIDE_FROM_ABI
Richard Smith081bb592015-10-08 20:40:34 +00001667typename std::enable_if<std::is_integral<_A1>::value, double>::type
Nikolas Klauser04005952022-10-21 01:41:22 +02001668scalbn(_A1 __x, int __y) _NOEXCEPT {return __builtin_scalbn((double)__x, __y);}
Richard Smith081bb592015-10-08 20:40:34 +00001669
1670// tgamma
1671
Nikolas Klauser04005952022-10-21 01:41:22 +02001672inline _LIBCPP_HIDE_FROM_ABI float tgamma(float __x) _NOEXCEPT {return __builtin_tgammaf(__x);}
Nikolas Klauser52399652022-11-01 22:29:57 +01001673
1674template <class = int>
1675_LIBCPP_HIDE_FROM_ABI double tgamma(double __x) _NOEXCEPT {
1676 return __builtin_tgamma(__x);
1677}
1678
Nikolas Klauser04005952022-10-21 01:41:22 +02001679inline _LIBCPP_HIDE_FROM_ABI long double tgamma(long double __x) _NOEXCEPT {return __builtin_tgammal(__x);}
Richard Smith081bb592015-10-08 20:40:34 +00001680
1681template <class _A1>
Nikolas Klauser4956e722022-10-12 15:41:22 +02001682inline _LIBCPP_HIDE_FROM_ABI
Richard Smith081bb592015-10-08 20:40:34 +00001683typename std::enable_if<std::is_integral<_A1>::value, double>::type
Nikolas Klauser04005952022-10-21 01:41:22 +02001684tgamma(_A1 __x) _NOEXCEPT {return __builtin_tgamma((double)__x);}
Richard Smith081bb592015-10-08 20:40:34 +00001685
1686// trunc
1687
Nikolas Klauser9806f452022-10-12 15:45:09 +02001688inline _LIBCPP_HIDE_FROM_ABI float trunc(float __x) _NOEXCEPT
Ilya Tokarc3abffb2021-02-10 13:05:19 -05001689{
Nikolas Klauser9806f452022-10-12 15:45:09 +02001690 return __builtin_trunc(__x);
Ilya Tokarc3abffb2021-02-10 13:05:19 -05001691}
Nikolas Klauser52399652022-11-01 22:29:57 +01001692
1693template <class = int>
1694_LIBCPP_HIDE_FROM_ABI double trunc(double __x) _NOEXCEPT {
1695 return __builtin_trunc(__x);
1696}
1697
Nikolas Klauser9806f452022-10-12 15:45:09 +02001698inline _LIBCPP_HIDE_FROM_ABI long double trunc(long double __x) _NOEXCEPT
Ilya Tokarc3abffb2021-02-10 13:05:19 -05001699{
Nikolas Klauser9806f452022-10-12 15:45:09 +02001700 return __builtin_truncl(__x);
Ilya Tokarc3abffb2021-02-10 13:05:19 -05001701}
Richard Smith081bb592015-10-08 20:40:34 +00001702
1703template <class _A1>
Nikolas Klauser4956e722022-10-12 15:41:22 +02001704inline _LIBCPP_HIDE_FROM_ABI
Richard Smith081bb592015-10-08 20:40:34 +00001705typename std::enable_if<std::is_integral<_A1>::value, double>::type
Nikolas Klauser9806f452022-10-12 15:45:09 +02001706trunc(_A1 __x) _NOEXCEPT
Ilya Tokarc3abffb2021-02-10 13:05:19 -05001707{
Nikolas Klauser9806f452022-10-12 15:45:09 +02001708 return __builtin_trunc((double)__x);
Ilya Tokarc3abffb2021-02-10 13:05:19 -05001709}
Richard Smith081bb592015-10-08 20:40:34 +00001710
Richard Smith081bb592015-10-08 20:40:34 +00001711} // extern "C++"
1712
1713#endif // __cplusplus
1714
Mikhail Maltsev34b4f972018-02-22 09:34:08 +00001715#else // _LIBCPP_MATH_H
1716
1717// This include lives outside the header guard in order to support an MSVC
1718// extension which allows users to do:
1719//
1720// #define _USE_MATH_DEFINES
1721// #include <math.h>
1722//
1723// and receive the definitions of mathematical constants, even if <math.h>
1724// has previously been included.
1725#if defined(_LIBCPP_MSVCRT) && defined(_USE_MATH_DEFINES)
1726#include_next <math.h>
1727#endif
1728
Louis Dionne2b1ceaa2021-04-20 12:03:32 -04001729#endif // _LIBCPP_MATH_H