blob: 0b07273920f7b895b0b5c82739959987bd99a7b5 [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
Richard Smith081bb592015-10-08 20:40:34 +0000315// signbit
316
Nikolas Klauser9a97dd72022-11-04 16:36:34 +0100317# ifdef signbit
Richard Smith081bb592015-10-08 20:40:34 +0000318
319template <class _A1>
Nikolas Klauser9a97dd72022-11-04 16:36:34 +0100320_LIBCPP_HIDE_FROM_ABI bool __libcpp_signbit(_A1 __x) _NOEXCEPT {
321# if __has_builtin(__builtin_signbit)
322 return __builtin_signbit(__x);
323# else
324 return signbit(__x);
325# endif
Richard Smith081bb592015-10-08 20:40:34 +0000326}
327
Nikolas Klauser9a97dd72022-11-04 16:36:34 +0100328# undef signbit
Richard Smith081bb592015-10-08 20:40:34 +0000329
330template <class _A1>
Nikolas Klauser9a97dd72022-11-04 16:36:34 +0100331inline _LIBCPP_HIDE_FROM_ABI typename std::enable_if<std::is_floating_point<_A1>::value, bool>::type
332signbit(_A1 __x) _NOEXCEPT {
333 return __libcpp_signbit(__x);
Richard Smith081bb592015-10-08 20:40:34 +0000334}
335
Duncan P. N. Exon Smith321d6bf2017-04-21 23:14:55 +0000336template <class _A1>
Nikolas Klauser4956e722022-10-12 15:41:22 +0200337inline _LIBCPP_HIDE_FROM_ABI
Nikolas Klauser9a97dd72022-11-04 16:36:34 +0100338 typename std::enable_if< std::is_integral<_A1>::value && std::is_signed<_A1>::value, bool>::type
339 signbit(_A1 __x) _NOEXCEPT {
340 return __x < 0;
341}
Duncan P. N. Exon Smith321d6bf2017-04-21 23:14:55 +0000342
343template <class _A1>
Nikolas Klauser4956e722022-10-12 15:41:22 +0200344inline _LIBCPP_HIDE_FROM_ABI
Nikolas Klauser9a97dd72022-11-04 16:36:34 +0100345 typename std::enable_if< std::is_integral<_A1>::value && !std::is_signed<_A1>::value, bool>::type
346 signbit(_A1) _NOEXCEPT {
347 return false;
348}
Duncan P. N. Exon Smith321d6bf2017-04-21 23:14:55 +0000349
Nikolas Klauser9a97dd72022-11-04 16:36:34 +0100350# elif defined(_LIBCPP_MSVCRT)
Saleem Abdulrasool257256b2017-02-18 19:28:38 +0000351
352template <typename _A1>
Nikolas Klauser9a97dd72022-11-04 16:36:34 +0100353inline _LIBCPP_HIDE_FROM_ABI typename std::enable_if<std::is_floating_point<_A1>::value, bool>::type
354signbit(_A1 __x) _NOEXCEPT {
Nikolas Klauser37a5b4f2022-10-27 20:01:13 +0200355 return ::signbit(__x);
Saleem Abdulrasool257256b2017-02-18 19:28:38 +0000356}
357
Duncan P. N. Exon Smith321d6bf2017-04-21 23:14:55 +0000358template <class _A1>
Nikolas Klauser4956e722022-10-12 15:41:22 +0200359inline _LIBCPP_HIDE_FROM_ABI
Nikolas Klauser9a97dd72022-11-04 16:36:34 +0100360 typename std::enable_if< std::is_integral<_A1>::value && std::is_signed<_A1>::value, bool>::type
361 signbit(_A1 __x) _NOEXCEPT {
362 return __x < 0;
363}
Duncan P. N. Exon Smith321d6bf2017-04-21 23:14:55 +0000364
365template <class _A1>
Nikolas Klauser4956e722022-10-12 15:41:22 +0200366inline _LIBCPP_HIDE_FROM_ABI
Nikolas Klauser9a97dd72022-11-04 16:36:34 +0100367 typename std::enable_if< std::is_integral<_A1>::value && !std::is_signed<_A1>::value, bool>::type
368 signbit(_A1) _NOEXCEPT {
369 return false;
370}
Duncan P. N. Exon Smith321d6bf2017-04-21 23:14:55 +0000371
Nikolas Klauser9a97dd72022-11-04 16:36:34 +0100372# endif // signbit
Richard Smith081bb592015-10-08 20:40:34 +0000373
374// fpclassify
375
Nikolas Klauser9a97dd72022-11-04 16:36:34 +0100376# ifdef fpclassify
Richard Smith081bb592015-10-08 20:40:34 +0000377
378template <class _A1>
Nikolas Klauser9a97dd72022-11-04 16:36:34 +0100379_LIBCPP_HIDE_FROM_ABI int __libcpp_fpclassify(_A1 __x) _NOEXCEPT {
380# if __has_builtin(__builtin_fpclassify)
381 return __builtin_fpclassify(FP_NAN, FP_INFINITE, FP_NORMAL, FP_SUBNORMAL, FP_ZERO, __x);
382# else
383 return fpclassify(__x);
384# endif
Richard Smith081bb592015-10-08 20:40:34 +0000385}
386
Nikolas Klauser9a97dd72022-11-04 16:36:34 +0100387# undef fpclassify
Richard Smith081bb592015-10-08 20:40:34 +0000388
389template <class _A1>
Nikolas Klauser9a97dd72022-11-04 16:36:34 +0100390inline _LIBCPP_HIDE_FROM_ABI typename std::enable_if<std::is_floating_point<_A1>::value, int>::type
391fpclassify(_A1 __x) _NOEXCEPT {
392 return __libcpp_fpclassify(__x);
Richard Smith081bb592015-10-08 20:40:34 +0000393}
394
Duncan P. N. Exon Smith321d6bf2017-04-21 23:14:55 +0000395template <class _A1>
Nikolas Klauser9a97dd72022-11-04 16:36:34 +0100396inline _LIBCPP_HIDE_FROM_ABI typename std::enable_if<std::is_integral<_A1>::value, int>::type
397fpclassify(_A1 __x) _NOEXCEPT {
398 return __x == 0 ? FP_ZERO : FP_NORMAL;
399}
Duncan P. N. Exon Smith321d6bf2017-04-21 23:14:55 +0000400
Nikolas Klauser9a97dd72022-11-04 16:36:34 +0100401# elif defined(_LIBCPP_MSVCRT)
Saleem Abdulrasool257256b2017-02-18 19:28:38 +0000402
403template <typename _A1>
Nikolas Klauser9a97dd72022-11-04 16:36:34 +0100404inline _LIBCPP_HIDE_FROM_ABI typename std::enable_if<std::is_floating_point<_A1>::value, bool>::type
405fpclassify(_A1 __x) _NOEXCEPT {
Nikolas Klauser37a5b4f2022-10-27 20:01:13 +0200406 return ::fpclassify(__x);
Saleem Abdulrasool257256b2017-02-18 19:28:38 +0000407}
408
Duncan P. N. Exon Smith321d6bf2017-04-21 23:14:55 +0000409template <class _A1>
Nikolas Klauser9a97dd72022-11-04 16:36:34 +0100410inline _LIBCPP_HIDE_FROM_ABI typename std::enable_if<std::is_integral<_A1>::value, int>::type
411fpclassify(_A1 __x) _NOEXCEPT {
412 return __x == 0 ? FP_ZERO : FP_NORMAL;
413}
Duncan P. N. Exon Smith321d6bf2017-04-21 23:14:55 +0000414
Nikolas Klauser9a97dd72022-11-04 16:36:34 +0100415# endif // fpclassify
Richard Smith081bb592015-10-08 20:40:34 +0000416
417// isfinite
418
Nikolas Klauser9a97dd72022-11-04 16:36:34 +0100419# ifdef isfinite
Richard Smith081bb592015-10-08 20:40:34 +0000420
421template <class _A1>
Nikolas Klauser9a97dd72022-11-04 16:36:34 +0100422_LIBCPP_HIDE_FROM_ABI bool __libcpp_isfinite(_A1 __x) _NOEXCEPT {
423# if __has_builtin(__builtin_isfinite)
424 return __builtin_isfinite(__x);
425# else
426 return isfinite(__x);
427# endif
Richard Smith081bb592015-10-08 20:40:34 +0000428}
429
Nikolas Klauser9a97dd72022-11-04 16:36:34 +0100430# undef isfinite
Richard Smith081bb592015-10-08 20:40:34 +0000431
432template <class _A1>
Nikolas Klauser4956e722022-10-12 15:41:22 +0200433inline _LIBCPP_HIDE_FROM_ABI
Nikolas Klauser9a97dd72022-11-04 16:36:34 +0100434 typename std::enable_if< std::is_arithmetic<_A1>::value && std::numeric_limits<_A1>::has_infinity, bool>::type
435 isfinite(_A1 __x) _NOEXCEPT {
436 return __libcpp_isfinite((typename std::__promote<_A1>::type)__x);
Richard Smith081bb592015-10-08 20:40:34 +0000437}
438
Duncan P. N. Exon Smith321d6bf2017-04-21 23:14:55 +0000439template <class _A1>
Nikolas Klauser4956e722022-10-12 15:41:22 +0200440inline _LIBCPP_HIDE_FROM_ABI
Nikolas Klauser9a97dd72022-11-04 16:36:34 +0100441 typename std::enable_if< std::is_arithmetic<_A1>::value && !std::numeric_limits<_A1>::has_infinity, bool>::type
442 isfinite(_A1) _NOEXCEPT {
443 return true;
444}
Duncan P. N. Exon Smith321d6bf2017-04-21 23:14:55 +0000445
Nikolas Klauser9a97dd72022-11-04 16:36:34 +0100446# endif // isfinite
Richard Smith081bb592015-10-08 20:40:34 +0000447
448// isinf
449
Nikolas Klauser9a97dd72022-11-04 16:36:34 +0100450# ifdef isinf
Richard Smith081bb592015-10-08 20:40:34 +0000451
452template <class _A1>
Nikolas Klauser9a97dd72022-11-04 16:36:34 +0100453_LIBCPP_HIDE_FROM_ABI bool __libcpp_isinf(_A1 __x) _NOEXCEPT {
454# if __has_builtin(__builtin_isinf)
455 return __builtin_isinf(__x);
456# else
457 return isinf(__x);
458# endif
Richard Smith081bb592015-10-08 20:40:34 +0000459}
460
Nikolas Klauser9a97dd72022-11-04 16:36:34 +0100461# undef isinf
Richard Smith081bb592015-10-08 20:40:34 +0000462
463template <class _A1>
Nikolas Klauser4956e722022-10-12 15:41:22 +0200464inline _LIBCPP_HIDE_FROM_ABI
Nikolas Klauser9a97dd72022-11-04 16:36:34 +0100465 typename std::enable_if< std::is_arithmetic<_A1>::value && std::numeric_limits<_A1>::has_infinity, bool>::type
466 isinf(_A1 __x) _NOEXCEPT {
467 return __libcpp_isinf((typename std::__promote<_A1>::type)__x);
Richard Smith081bb592015-10-08 20:40:34 +0000468}
469
Duncan P. N. Exon Smith321d6bf2017-04-21 23:14:55 +0000470template <class _A1>
Nikolas Klauser4956e722022-10-12 15:41:22 +0200471inline _LIBCPP_HIDE_FROM_ABI
Nikolas Klauser9a97dd72022-11-04 16:36:34 +0100472 typename std::enable_if< std::is_arithmetic<_A1>::value && !std::numeric_limits<_A1>::has_infinity, bool>::type
473 isinf(_A1) _NOEXCEPT {
474 return false;
475}
Duncan P. N. Exon Smith321d6bf2017-04-21 23:14:55 +0000476
Nikolas Klauser9a97dd72022-11-04 16:36:34 +0100477# ifdef _LIBCPP_PREFERRED_OVERLOAD
478inline _LIBCPP_HIDE_FROM_ABI bool isinf(float __x) _NOEXCEPT { return __libcpp_isinf(__x); }
Richard Smithafccfd32018-05-01 03:05:40 +0000479
Nikolas Klauser9a97dd72022-11-04 16:36:34 +0100480inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_PREFERRED_OVERLOAD bool isinf(double __x) _NOEXCEPT { return __libcpp_isinf(__x); }
Richard Smithafccfd32018-05-01 03:05:40 +0000481
Nikolas Klauser9a97dd72022-11-04 16:36:34 +0100482inline _LIBCPP_HIDE_FROM_ABI bool isinf(long double __x) _NOEXCEPT { return __libcpp_isinf(__x); }
483# endif
Richard Smithafccfd32018-05-01 03:05:40 +0000484
Nikolas Klauser9a97dd72022-11-04 16:36:34 +0100485# endif // isinf
Richard Smith081bb592015-10-08 20:40:34 +0000486
487// isnan
488
Nikolas Klauser9a97dd72022-11-04 16:36:34 +0100489# ifdef isnan
Richard Smith081bb592015-10-08 20:40:34 +0000490
491template <class _A1>
Nikolas Klauser9a97dd72022-11-04 16:36:34 +0100492_LIBCPP_HIDE_FROM_ABI bool __libcpp_isnan(_A1 __x) _NOEXCEPT {
493# if __has_builtin(__builtin_isnan)
494 return __builtin_isnan(__x);
495# else
496 return isnan(__x);
497# endif
Richard Smith081bb592015-10-08 20:40:34 +0000498}
499
Nikolas Klauser9a97dd72022-11-04 16:36:34 +0100500# undef isnan
Richard Smith081bb592015-10-08 20:40:34 +0000501
502template <class _A1>
Nikolas Klauser9a97dd72022-11-04 16:36:34 +0100503inline _LIBCPP_HIDE_FROM_ABI typename std::enable_if<std::is_floating_point<_A1>::value, bool>::type
504isnan(_A1 __x) _NOEXCEPT {
505 return __libcpp_isnan(__x);
Richard Smith081bb592015-10-08 20:40:34 +0000506}
507
Duncan P. N. Exon Smith321d6bf2017-04-21 23:14:55 +0000508template <class _A1>
Nikolas Klauser9a97dd72022-11-04 16:36:34 +0100509inline _LIBCPP_HIDE_FROM_ABI typename std::enable_if<std::is_integral<_A1>::value, bool>::type isnan(_A1) _NOEXCEPT {
510 return false;
511}
Duncan P. N. Exon Smith321d6bf2017-04-21 23:14:55 +0000512
Nikolas Klauser9a97dd72022-11-04 16:36:34 +0100513# ifdef _LIBCPP_PREFERRED_OVERLOAD
514inline _LIBCPP_HIDE_FROM_ABI bool isnan(float __x) _NOEXCEPT { return __libcpp_isnan(__x); }
Richard Smithafccfd32018-05-01 03:05:40 +0000515
Nikolas Klauser9a97dd72022-11-04 16:36:34 +0100516inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_PREFERRED_OVERLOAD bool isnan(double __x) _NOEXCEPT { return __libcpp_isnan(__x); }
Richard Smithafccfd32018-05-01 03:05:40 +0000517
Nikolas Klauser9a97dd72022-11-04 16:36:34 +0100518inline _LIBCPP_HIDE_FROM_ABI bool isnan(long double __x) _NOEXCEPT { return __libcpp_isnan(__x); }
519# endif
Richard Smithafccfd32018-05-01 03:05:40 +0000520
Nikolas Klauser9a97dd72022-11-04 16:36:34 +0100521# endif // isnan
Richard Smith081bb592015-10-08 20:40:34 +0000522
523// isnormal
524
Nikolas Klauser9a97dd72022-11-04 16:36:34 +0100525# ifdef isnormal
Richard Smith081bb592015-10-08 20:40:34 +0000526
527template <class _A1>
Nikolas Klauser9a97dd72022-11-04 16:36:34 +0100528_LIBCPP_HIDE_FROM_ABI bool __libcpp_isnormal(_A1 __x) _NOEXCEPT {
529# if __has_builtin(__builtin_isnormal)
530 return __builtin_isnormal(__x);
531# else
532 return isnormal(__x);
533# endif
Richard Smith081bb592015-10-08 20:40:34 +0000534}
535
Nikolas Klauser9a97dd72022-11-04 16:36:34 +0100536# undef isnormal
Richard Smith081bb592015-10-08 20:40:34 +0000537
538template <class _A1>
Nikolas Klauser9a97dd72022-11-04 16:36:34 +0100539inline _LIBCPP_HIDE_FROM_ABI typename std::enable_if<std::is_floating_point<_A1>::value, bool>::type
540isnormal(_A1 __x) _NOEXCEPT {
541 return __libcpp_isnormal(__x);
Richard Smith081bb592015-10-08 20:40:34 +0000542}
543
Duncan P. N. Exon Smith321d6bf2017-04-21 23:14:55 +0000544template <class _A1>
Nikolas Klauser9a97dd72022-11-04 16:36:34 +0100545inline _LIBCPP_HIDE_FROM_ABI typename std::enable_if<std::is_integral<_A1>::value, bool>::type
546isnormal(_A1 __x) _NOEXCEPT {
547 return __x != 0;
548}
Duncan P. N. Exon Smith321d6bf2017-04-21 23:14:55 +0000549
Nikolas Klauser9a97dd72022-11-04 16:36:34 +0100550# endif // isnormal
Richard Smith081bb592015-10-08 20:40:34 +0000551
552// isgreater
553
Nikolas Klauser9a97dd72022-11-04 16:36:34 +0100554# ifdef isgreater
Richard Smith081bb592015-10-08 20:40:34 +0000555
556template <class _A1, class _A2>
Nikolas Klauser9a97dd72022-11-04 16:36:34 +0100557_LIBCPP_HIDE_FROM_ABI bool __libcpp_isgreater(_A1 __x, _A2 __y) _NOEXCEPT {
558 return isgreater(__x, __y);
Richard Smith081bb592015-10-08 20:40:34 +0000559}
560
Nikolas Klauser9a97dd72022-11-04 16:36:34 +0100561# undef isgreater
Richard Smith081bb592015-10-08 20:40:34 +0000562
563template <class _A1, class _A2>
Nikolas Klauser4956e722022-10-12 15:41:22 +0200564inline _LIBCPP_HIDE_FROM_ABI
Nikolas Klauser9a97dd72022-11-04 16:36:34 +0100565 typename std::enable_if< std::is_arithmetic<_A1>::value && std::is_arithmetic<_A2>::value, bool >::type
566 isgreater(_A1 __x, _A2 __y) _NOEXCEPT {
567 typedef typename std::__promote<_A1, _A2>::type type;
568 return __libcpp_isgreater((type)__x, (type)__y);
Richard Smith081bb592015-10-08 20:40:34 +0000569}
570
Nikolas Klauser9a97dd72022-11-04 16:36:34 +0100571# endif // isgreater
Richard Smith081bb592015-10-08 20:40:34 +0000572
573// isgreaterequal
574
Nikolas Klauser9a97dd72022-11-04 16:36:34 +0100575# ifdef isgreaterequal
Richard Smith081bb592015-10-08 20:40:34 +0000576
577template <class _A1, class _A2>
Nikolas Klauser9a97dd72022-11-04 16:36:34 +0100578_LIBCPP_HIDE_FROM_ABI bool __libcpp_isgreaterequal(_A1 __x, _A2 __y) _NOEXCEPT {
579 return isgreaterequal(__x, __y);
Richard Smith081bb592015-10-08 20:40:34 +0000580}
581
Nikolas Klauser9a97dd72022-11-04 16:36:34 +0100582# undef isgreaterequal
Richard Smith081bb592015-10-08 20:40:34 +0000583
584template <class _A1, class _A2>
Nikolas Klauser4956e722022-10-12 15:41:22 +0200585inline _LIBCPP_HIDE_FROM_ABI
Nikolas Klauser9a97dd72022-11-04 16:36:34 +0100586 typename std::enable_if< std::is_arithmetic<_A1>::value && std::is_arithmetic<_A2>::value, bool >::type
587 isgreaterequal(_A1 __x, _A2 __y) _NOEXCEPT {
588 typedef typename std::__promote<_A1, _A2>::type type;
589 return __libcpp_isgreaterequal((type)__x, (type)__y);
Richard Smith081bb592015-10-08 20:40:34 +0000590}
591
Nikolas Klauser9a97dd72022-11-04 16:36:34 +0100592# endif // isgreaterequal
Richard Smith081bb592015-10-08 20:40:34 +0000593
594// isless
595
Nikolas Klauser9a97dd72022-11-04 16:36:34 +0100596# ifdef isless
Richard Smith081bb592015-10-08 20:40:34 +0000597
598template <class _A1, class _A2>
Nikolas Klauser9a97dd72022-11-04 16:36:34 +0100599_LIBCPP_HIDE_FROM_ABI bool __libcpp_isless(_A1 __x, _A2 __y) _NOEXCEPT {
600 return isless(__x, __y);
Richard Smith081bb592015-10-08 20:40:34 +0000601}
602
Nikolas Klauser9a97dd72022-11-04 16:36:34 +0100603# undef isless
Richard Smith081bb592015-10-08 20:40:34 +0000604
605template <class _A1, class _A2>
Nikolas Klauser4956e722022-10-12 15:41:22 +0200606inline _LIBCPP_HIDE_FROM_ABI
Nikolas Klauser9a97dd72022-11-04 16:36:34 +0100607 typename std::enable_if< std::is_arithmetic<_A1>::value && std::is_arithmetic<_A2>::value, bool >::type
608 isless(_A1 __x, _A2 __y) _NOEXCEPT {
609 typedef typename std::__promote<_A1, _A2>::type type;
610 return __libcpp_isless((type)__x, (type)__y);
Richard Smith081bb592015-10-08 20:40:34 +0000611}
612
Nikolas Klauser9a97dd72022-11-04 16:36:34 +0100613# endif // isless
Richard Smith081bb592015-10-08 20:40:34 +0000614
615// islessequal
616
Nikolas Klauser9a97dd72022-11-04 16:36:34 +0100617# ifdef islessequal
Richard Smith081bb592015-10-08 20:40:34 +0000618
619template <class _A1, class _A2>
Nikolas Klauser9a97dd72022-11-04 16:36:34 +0100620_LIBCPP_HIDE_FROM_ABI bool __libcpp_islessequal(_A1 __x, _A2 __y) _NOEXCEPT {
621 return islessequal(__x, __y);
Richard Smith081bb592015-10-08 20:40:34 +0000622}
623
Nikolas Klauser9a97dd72022-11-04 16:36:34 +0100624# undef islessequal
Richard Smith081bb592015-10-08 20:40:34 +0000625
626template <class _A1, class _A2>
Nikolas Klauser4956e722022-10-12 15:41:22 +0200627inline _LIBCPP_HIDE_FROM_ABI
Nikolas Klauser9a97dd72022-11-04 16:36:34 +0100628 typename std::enable_if< std::is_arithmetic<_A1>::value && std::is_arithmetic<_A2>::value, bool >::type
629 islessequal(_A1 __x, _A2 __y) _NOEXCEPT {
630 typedef typename std::__promote<_A1, _A2>::type type;
631 return __libcpp_islessequal((type)__x, (type)__y);
Richard Smith081bb592015-10-08 20:40:34 +0000632}
633
Nikolas Klauser9a97dd72022-11-04 16:36:34 +0100634# endif // islessequal
Richard Smith081bb592015-10-08 20:40:34 +0000635
636// islessgreater
637
Nikolas Klauser9a97dd72022-11-04 16:36:34 +0100638# ifdef islessgreater
Richard Smith081bb592015-10-08 20:40:34 +0000639
640template <class _A1, class _A2>
Nikolas Klauser9a97dd72022-11-04 16:36:34 +0100641_LIBCPP_HIDE_FROM_ABI bool __libcpp_islessgreater(_A1 __x, _A2 __y) _NOEXCEPT {
642 return islessgreater(__x, __y);
Richard Smith081bb592015-10-08 20:40:34 +0000643}
644
Nikolas Klauser9a97dd72022-11-04 16:36:34 +0100645# undef islessgreater
Richard Smith081bb592015-10-08 20:40:34 +0000646
647template <class _A1, class _A2>
Nikolas Klauser4956e722022-10-12 15:41:22 +0200648inline _LIBCPP_HIDE_FROM_ABI
Nikolas Klauser9a97dd72022-11-04 16:36:34 +0100649 typename std::enable_if< std::is_arithmetic<_A1>::value && std::is_arithmetic<_A2>::value, bool >::type
650 islessgreater(_A1 __x, _A2 __y) _NOEXCEPT {
651 typedef typename std::__promote<_A1, _A2>::type type;
652 return __libcpp_islessgreater((type)__x, (type)__y);
Richard Smith081bb592015-10-08 20:40:34 +0000653}
654
Nikolas Klauser9a97dd72022-11-04 16:36:34 +0100655# endif // islessgreater
Richard Smith081bb592015-10-08 20:40:34 +0000656
657// isunordered
658
Nikolas Klauser9a97dd72022-11-04 16:36:34 +0100659# ifdef isunordered
Richard Smith081bb592015-10-08 20:40:34 +0000660
661template <class _A1, class _A2>
Nikolas Klauser9a97dd72022-11-04 16:36:34 +0100662_LIBCPP_HIDE_FROM_ABI bool __libcpp_isunordered(_A1 __x, _A2 __y) _NOEXCEPT {
663 return isunordered(__x, __y);
Richard Smith081bb592015-10-08 20:40:34 +0000664}
665
Nikolas Klauser9a97dd72022-11-04 16:36:34 +0100666# undef isunordered
Richard Smith081bb592015-10-08 20:40:34 +0000667
668template <class _A1, class _A2>
Nikolas Klauser4956e722022-10-12 15:41:22 +0200669inline _LIBCPP_HIDE_FROM_ABI
Nikolas Klauser9a97dd72022-11-04 16:36:34 +0100670 typename std::enable_if< std::is_arithmetic<_A1>::value && std::is_arithmetic<_A2>::value, bool >::type
671 isunordered(_A1 __x, _A2 __y) _NOEXCEPT {
672 typedef typename std::__promote<_A1, _A2>::type type;
673 return __libcpp_isunordered((type)__x, (type)__y);
Richard Smith081bb592015-10-08 20:40:34 +0000674}
675
Nikolas Klauser9a97dd72022-11-04 16:36:34 +0100676# endif // isunordered
Richard Smith081bb592015-10-08 20:40:34 +0000677
Richard Smith081bb592015-10-08 20:40:34 +0000678// abs
Eric Fiselier6c9e1a72020-02-15 18:55:07 -0500679//
680// handled in stdlib.h
Richard Smith081bb592015-10-08 20:40:34 +0000681
Eric Fiselier2b85c6e2019-04-23 18:01:58 +0000682// div
Eric Fiselier6c9e1a72020-02-15 18:55:07 -0500683//
684// handled in stdlib.h
Eric Fiselier2b85c6e2019-04-23 18:01:58 +0000685
Richard Smith081bb592015-10-08 20:40:34 +0000686// acos
687
David Tenty7249ac92022-02-07 18:22:35 -0500688# if !defined(__sun__)
Nikolas Klauser9806f452022-10-12 15:45:09 +0200689inline _LIBCPP_HIDE_FROM_ABI float acos(float __x) _NOEXCEPT {return ::acosf(__x);}
690inline _LIBCPP_HIDE_FROM_ABI long double acos(long double __x) _NOEXCEPT {return ::acosl(__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 Klauser9806f452022-10-12 15:45:09 +0200696acos(_A1 __x) _NOEXCEPT {return ::acos((double)__x);}
Richard Smith081bb592015-10-08 20:40:34 +0000697
698// asin
699
David Tenty7249ac92022-02-07 18:22:35 -0500700# if !defined(__sun__)
Nikolas Klauser9806f452022-10-12 15:45:09 +0200701inline _LIBCPP_HIDE_FROM_ABI float asin(float __x) _NOEXCEPT {return ::asinf(__x);}
702inline _LIBCPP_HIDE_FROM_ABI long double asin(long double __x) _NOEXCEPT {return ::asinl(__x);}
David Tenty7249ac92022-02-07 18:22:35 -0500703# endif
Richard Smith081bb592015-10-08 20:40:34 +0000704
705template <class _A1>
Nikolas Klauser4956e722022-10-12 15:41:22 +0200706inline _LIBCPP_HIDE_FROM_ABI
Richard Smith081bb592015-10-08 20:40:34 +0000707typename std::enable_if<std::is_integral<_A1>::value, double>::type
Nikolas Klauser9806f452022-10-12 15:45:09 +0200708asin(_A1 __x) _NOEXCEPT {return ::asin((double)__x);}
Richard Smith081bb592015-10-08 20:40:34 +0000709
710// atan
711
David Tenty7249ac92022-02-07 18:22:35 -0500712# if !defined(__sun__)
Nikolas Klauser9806f452022-10-12 15:45:09 +0200713inline _LIBCPP_HIDE_FROM_ABI float atan(float __x) _NOEXCEPT {return ::atanf(__x);}
714inline _LIBCPP_HIDE_FROM_ABI long double atan(long double __x) _NOEXCEPT {return ::atanl(__x);}
David Tenty7249ac92022-02-07 18:22:35 -0500715# endif
Richard Smith081bb592015-10-08 20:40:34 +0000716
717template <class _A1>
Nikolas Klauser4956e722022-10-12 15:41:22 +0200718inline _LIBCPP_HIDE_FROM_ABI
Richard Smith081bb592015-10-08 20:40:34 +0000719typename std::enable_if<std::is_integral<_A1>::value, double>::type
Nikolas Klauser9806f452022-10-12 15:45:09 +0200720atan(_A1 __x) _NOEXCEPT {return ::atan((double)__x);}
Richard Smith081bb592015-10-08 20:40:34 +0000721
722// atan2
723
David Tenty7249ac92022-02-07 18:22:35 -0500724# if !defined(__sun__)
Nikolas Klauser9806f452022-10-12 15:45:09 +0200725inline _LIBCPP_HIDE_FROM_ABI float atan2(float __y, float __x) _NOEXCEPT {return ::atan2f(__y, __x);}
726inline _LIBCPP_HIDE_FROM_ABI long double atan2(long double __y, long double __x) _NOEXCEPT {return ::atan2l(__y, __x);}
David Tenty7249ac92022-02-07 18:22:35 -0500727# endif
Richard Smith081bb592015-10-08 20:40:34 +0000728
729template <class _A1, class _A2>
Nikolas Klauser4956e722022-10-12 15:41:22 +0200730inline _LIBCPP_HIDE_FROM_ABI
Louis Dionne9ce598d2021-09-08 09:14:43 -0400731typename std::__enable_if_t
Richard Smith081bb592015-10-08 20:40:34 +0000732<
733 std::is_arithmetic<_A1>::value &&
734 std::is_arithmetic<_A2>::value,
735 std::__promote<_A1, _A2>
736>::type
Nikolas Klauser9806f452022-10-12 15:45:09 +0200737atan2(_A1 __y, _A2 __x) _NOEXCEPT
Richard Smith081bb592015-10-08 20:40:34 +0000738{
739 typedef typename std::__promote<_A1, _A2>::type __result_type;
Eric Fiselier3906a132019-06-23 20:28:29 +0000740 static_assert((!(std::_IsSame<_A1, __result_type>::value &&
741 std::_IsSame<_A2, __result_type>::value)), "");
Nikolas Klauser9806f452022-10-12 15:45:09 +0200742 return ::atan2((__result_type)__y, (__result_type)__x);
Richard Smith081bb592015-10-08 20:40:34 +0000743}
744
745// ceil
746
David Tenty7249ac92022-02-07 18:22:35 -0500747# if !defined(__sun__)
Nikolas Klauser9806f452022-10-12 15:45:09 +0200748inline _LIBCPP_HIDE_FROM_ABI float ceil(float __x) _NOEXCEPT {return ::ceilf(__x);}
749inline _LIBCPP_HIDE_FROM_ABI long double ceil(long double __x) _NOEXCEPT {return ::ceill(__x);}
David Tenty7249ac92022-02-07 18:22:35 -0500750# endif
Richard Smith081bb592015-10-08 20:40:34 +0000751
752template <class _A1>
Nikolas Klauser4956e722022-10-12 15:41:22 +0200753inline _LIBCPP_HIDE_FROM_ABI
Richard Smith081bb592015-10-08 20:40:34 +0000754typename std::enable_if<std::is_integral<_A1>::value, double>::type
Nikolas Klauser9806f452022-10-12 15:45:09 +0200755ceil(_A1 __x) _NOEXCEPT {return ::ceil((double)__x);}
Richard Smith081bb592015-10-08 20:40:34 +0000756
757// cos
758
David Tenty7249ac92022-02-07 18:22:35 -0500759# if !defined(__sun__)
Nikolas Klauser9806f452022-10-12 15:45:09 +0200760inline _LIBCPP_HIDE_FROM_ABI float cos(float __x) _NOEXCEPT {return ::cosf(__x);}
761inline _LIBCPP_HIDE_FROM_ABI long double cos(long double __x) _NOEXCEPT {return ::cosl(__x);}
David Tenty7249ac92022-02-07 18:22:35 -0500762# endif
Richard Smith081bb592015-10-08 20:40:34 +0000763
764template <class _A1>
Nikolas Klauser4956e722022-10-12 15:41:22 +0200765inline _LIBCPP_HIDE_FROM_ABI
Richard Smith081bb592015-10-08 20:40:34 +0000766typename std::enable_if<std::is_integral<_A1>::value, double>::type
Nikolas Klauser9806f452022-10-12 15:45:09 +0200767cos(_A1 __x) _NOEXCEPT {return ::cos((double)__x);}
Richard Smith081bb592015-10-08 20:40:34 +0000768
769// cosh
770
David Tenty7249ac92022-02-07 18:22:35 -0500771# if !defined(__sun__)
Nikolas Klauser9806f452022-10-12 15:45:09 +0200772inline _LIBCPP_HIDE_FROM_ABI float cosh(float __x) _NOEXCEPT {return ::coshf(__x);}
773inline _LIBCPP_HIDE_FROM_ABI long double cosh(long double __x) _NOEXCEPT {return ::coshl(__x);}
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 Klauser9806f452022-10-12 15:45:09 +0200779cosh(_A1 __x) _NOEXCEPT {return ::cosh((double)__x);}
Richard Smith081bb592015-10-08 20:40:34 +0000780
781// exp
782
David Tenty7249ac92022-02-07 18:22:35 -0500783# if !defined(__sun__)
Nikolas Klauser9806f452022-10-12 15:45:09 +0200784inline _LIBCPP_HIDE_FROM_ABI float exp(float __x) _NOEXCEPT {return ::expf(__x);}
785inline _LIBCPP_HIDE_FROM_ABI long double exp(long double __x) _NOEXCEPT {return ::expl(__x);}
David Tenty7249ac92022-02-07 18:22:35 -0500786# endif
Richard Smith081bb592015-10-08 20:40:34 +0000787
788template <class _A1>
Nikolas Klauser4956e722022-10-12 15:41:22 +0200789inline _LIBCPP_HIDE_FROM_ABI
Richard Smith081bb592015-10-08 20:40:34 +0000790typename std::enable_if<std::is_integral<_A1>::value, double>::type
Nikolas Klauser9806f452022-10-12 15:45:09 +0200791exp(_A1 __x) _NOEXCEPT {return ::exp((double)__x);}
Richard Smith081bb592015-10-08 20:40:34 +0000792
793// fabs
794
David Tenty7249ac92022-02-07 18:22:35 -0500795# if !defined(__sun__)
Nikolas Klauser9806f452022-10-12 15:45:09 +0200796inline _LIBCPP_HIDE_FROM_ABI float fabs(float __x) _NOEXCEPT {return ::fabsf(__x);}
797inline _LIBCPP_HIDE_FROM_ABI long double fabs(long double __x) _NOEXCEPT {return ::fabsl(__x);}
David Tenty7249ac92022-02-07 18:22:35 -0500798# endif
Richard Smith081bb592015-10-08 20:40:34 +0000799
800template <class _A1>
Nikolas Klauser4956e722022-10-12 15:41:22 +0200801inline _LIBCPP_HIDE_FROM_ABI
Richard Smith081bb592015-10-08 20:40:34 +0000802typename std::enable_if<std::is_integral<_A1>::value, double>::type
Nikolas Klauser9806f452022-10-12 15:45:09 +0200803fabs(_A1 __x) _NOEXCEPT {return ::fabs((double)__x);}
Richard Smith081bb592015-10-08 20:40:34 +0000804
805// floor
806
David Tenty7249ac92022-02-07 18:22:35 -0500807# if !defined(__sun__)
Nikolas Klauser9806f452022-10-12 15:45:09 +0200808inline _LIBCPP_HIDE_FROM_ABI float floor(float __x) _NOEXCEPT {return ::floorf(__x);}
809inline _LIBCPP_HIDE_FROM_ABI long double floor(long double __x) _NOEXCEPT {return ::floorl(__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 Klauser9806f452022-10-12 15:45:09 +0200815floor(_A1 __x) _NOEXCEPT {return ::floor((double)__x);}
Richard Smith081bb592015-10-08 20:40:34 +0000816
817// fmod
818
David Tenty7249ac92022-02-07 18:22:35 -0500819# if !defined(__sun__)
Nikolas Klauser9806f452022-10-12 15:45:09 +0200820inline _LIBCPP_HIDE_FROM_ABI float fmod(float __x, float __y) _NOEXCEPT {return ::fmodf(__x, __y);}
821inline _LIBCPP_HIDE_FROM_ABI long double fmod(long double __x, long double __y) _NOEXCEPT {return ::fmodl(__x, __y);}
David Tenty7249ac92022-02-07 18:22:35 -0500822# endif
Richard Smith081bb592015-10-08 20:40:34 +0000823
824template <class _A1, class _A2>
Nikolas Klauser4956e722022-10-12 15:41:22 +0200825inline _LIBCPP_HIDE_FROM_ABI
Louis Dionne9ce598d2021-09-08 09:14:43 -0400826typename std::__enable_if_t
Richard Smith081bb592015-10-08 20:40:34 +0000827<
828 std::is_arithmetic<_A1>::value &&
829 std::is_arithmetic<_A2>::value,
830 std::__promote<_A1, _A2>
831>::type
Nikolas Klauser9806f452022-10-12 15:45:09 +0200832fmod(_A1 __x, _A2 __y) _NOEXCEPT
Richard Smith081bb592015-10-08 20:40:34 +0000833{
834 typedef typename std::__promote<_A1, _A2>::type __result_type;
Eric Fiselier3906a132019-06-23 20:28:29 +0000835 static_assert((!(std::_IsSame<_A1, __result_type>::value &&
836 std::_IsSame<_A2, __result_type>::value)), "");
Nikolas Klauser9806f452022-10-12 15:45:09 +0200837 return ::fmod((__result_type)__x, (__result_type)__y);
Richard Smith081bb592015-10-08 20:40:34 +0000838}
839
840// frexp
841
David Tenty7249ac92022-02-07 18:22:35 -0500842# if !defined(__sun__)
Nikolas Klauser9806f452022-10-12 15:45:09 +0200843inline _LIBCPP_HIDE_FROM_ABI float frexp(float __x, int* __e) _NOEXCEPT {return ::frexpf(__x, __e);}
844inline _LIBCPP_HIDE_FROM_ABI long double frexp(long double __x, int* __e) _NOEXCEPT {return ::frexpl(__x, __e);}
David Tenty7249ac92022-02-07 18:22:35 -0500845# endif
Richard Smith081bb592015-10-08 20:40:34 +0000846
847template <class _A1>
Nikolas Klauser4956e722022-10-12 15:41:22 +0200848inline _LIBCPP_HIDE_FROM_ABI
Richard Smith081bb592015-10-08 20:40:34 +0000849typename std::enable_if<std::is_integral<_A1>::value, double>::type
Nikolas Klauser9806f452022-10-12 15:45:09 +0200850frexp(_A1 __x, int* __e) _NOEXCEPT {return ::frexp((double)__x, __e);}
Richard Smith081bb592015-10-08 20:40:34 +0000851
852// ldexp
853
David Tenty7249ac92022-02-07 18:22:35 -0500854# if !defined(__sun__)
Nikolas Klauser9806f452022-10-12 15:45:09 +0200855inline _LIBCPP_HIDE_FROM_ABI float ldexp(float __x, int __e) _NOEXCEPT {return ::ldexpf(__x, __e);}
856inline _LIBCPP_HIDE_FROM_ABI long double ldexp(long double __x, int __e) _NOEXCEPT {return ::ldexpl(__x, __e);}
David Tenty7249ac92022-02-07 18:22:35 -0500857# endif
Richard Smith081bb592015-10-08 20:40:34 +0000858
859template <class _A1>
Nikolas Klauser4956e722022-10-12 15:41:22 +0200860inline _LIBCPP_HIDE_FROM_ABI
Richard Smith081bb592015-10-08 20:40:34 +0000861typename std::enable_if<std::is_integral<_A1>::value, double>::type
Nikolas Klauser9806f452022-10-12 15:45:09 +0200862ldexp(_A1 __x, int __e) _NOEXCEPT {return ::ldexp((double)__x, __e);}
Richard Smith081bb592015-10-08 20:40:34 +0000863
864// log
865
David Tenty7249ac92022-02-07 18:22:35 -0500866# if !defined(__sun__)
Nikolas Klauser9806f452022-10-12 15:45:09 +0200867inline _LIBCPP_HIDE_FROM_ABI float log(float __x) _NOEXCEPT {return ::logf(__x);}
868inline _LIBCPP_HIDE_FROM_ABI long double log(long double __x) _NOEXCEPT {return ::logl(__x);}
David Tenty7249ac92022-02-07 18:22:35 -0500869# endif
Richard Smith081bb592015-10-08 20:40:34 +0000870
871template <class _A1>
Nikolas Klauser4956e722022-10-12 15:41:22 +0200872inline _LIBCPP_HIDE_FROM_ABI
Richard Smith081bb592015-10-08 20:40:34 +0000873typename std::enable_if<std::is_integral<_A1>::value, double>::type
Nikolas Klauser9806f452022-10-12 15:45:09 +0200874log(_A1 __x) _NOEXCEPT {return ::log((double)__x);}
Richard Smith081bb592015-10-08 20:40:34 +0000875
876// log10
877
David Tenty7249ac92022-02-07 18:22:35 -0500878# if !defined(__sun__)
Nikolas Klauser9806f452022-10-12 15:45:09 +0200879inline _LIBCPP_HIDE_FROM_ABI float log10(float __x) _NOEXCEPT {return ::log10f(__x);}
880inline _LIBCPP_HIDE_FROM_ABI long double log10(long double __x) _NOEXCEPT {return ::log10l(__x);}
David Tenty7249ac92022-02-07 18:22:35 -0500881# endif
Richard Smith081bb592015-10-08 20:40:34 +0000882
883template <class _A1>
Nikolas Klauser4956e722022-10-12 15:41:22 +0200884inline _LIBCPP_HIDE_FROM_ABI
Richard Smith081bb592015-10-08 20:40:34 +0000885typename std::enable_if<std::is_integral<_A1>::value, double>::type
Nikolas Klauser9806f452022-10-12 15:45:09 +0200886log10(_A1 __x) _NOEXCEPT {return ::log10((double)__x);}
Richard Smith081bb592015-10-08 20:40:34 +0000887
888// modf
889
David Tenty7249ac92022-02-07 18:22:35 -0500890# if !defined(__sun__)
Nikolas Klauser9806f452022-10-12 15:45:09 +0200891inline _LIBCPP_HIDE_FROM_ABI float modf(float __x, float* __y) _NOEXCEPT {return ::modff(__x, __y);}
892inline _LIBCPP_HIDE_FROM_ABI long double modf(long double __x, long double* __y) _NOEXCEPT {return ::modfl(__x, __y);}
David Tenty7249ac92022-02-07 18:22:35 -0500893# endif
Richard Smith081bb592015-10-08 20:40:34 +0000894
895// pow
896
David Tenty7249ac92022-02-07 18:22:35 -0500897# if !defined(__sun__)
Nikolas Klauser9806f452022-10-12 15:45:09 +0200898inline _LIBCPP_HIDE_FROM_ABI float pow(float __x, float __y) _NOEXCEPT {return ::powf(__x, __y);}
899inline _LIBCPP_HIDE_FROM_ABI long double pow(long double __x, long double __y) _NOEXCEPT {return ::powl(__x, __y);}
David Tenty7249ac92022-02-07 18:22:35 -0500900# endif
Richard Smith081bb592015-10-08 20:40:34 +0000901
902template <class _A1, class _A2>
Nikolas Klauser4956e722022-10-12 15:41:22 +0200903inline _LIBCPP_HIDE_FROM_ABI
Louis Dionne9ce598d2021-09-08 09:14:43 -0400904typename std::__enable_if_t
Richard Smith081bb592015-10-08 20:40:34 +0000905<
906 std::is_arithmetic<_A1>::value &&
907 std::is_arithmetic<_A2>::value,
908 std::__promote<_A1, _A2>
909>::type
Nikolas Klauser9806f452022-10-12 15:45:09 +0200910pow(_A1 __x, _A2 __y) _NOEXCEPT
Richard Smith081bb592015-10-08 20:40:34 +0000911{
912 typedef typename std::__promote<_A1, _A2>::type __result_type;
Eric Fiselier3906a132019-06-23 20:28:29 +0000913 static_assert((!(std::_IsSame<_A1, __result_type>::value &&
914 std::_IsSame<_A2, __result_type>::value)), "");
Nikolas Klauser9806f452022-10-12 15:45:09 +0200915 return ::pow((__result_type)__x, (__result_type)__y);
Richard Smith081bb592015-10-08 20:40:34 +0000916}
917
918// sin
919
David Tenty7249ac92022-02-07 18:22:35 -0500920# if !defined(__sun__)
Nikolas Klauser9806f452022-10-12 15:45:09 +0200921inline _LIBCPP_HIDE_FROM_ABI float sin(float __x) _NOEXCEPT {return ::sinf(__x);}
922inline _LIBCPP_HIDE_FROM_ABI long double sin(long double __x) _NOEXCEPT {return ::sinl(__x);}
Richard Smith081bb592015-10-08 20:40:34 +0000923#endif
924
925template <class _A1>
Nikolas Klauser4956e722022-10-12 15:41:22 +0200926inline _LIBCPP_HIDE_FROM_ABI
Richard Smith081bb592015-10-08 20:40:34 +0000927typename std::enable_if<std::is_integral<_A1>::value, double>::type
Nikolas Klauser9806f452022-10-12 15:45:09 +0200928sin(_A1 __x) _NOEXCEPT {return ::sin((double)__x);}
Richard Smith081bb592015-10-08 20:40:34 +0000929
930// sinh
931
David Tenty7249ac92022-02-07 18:22:35 -0500932# if !defined(__sun__)
Nikolas Klauser9806f452022-10-12 15:45:09 +0200933inline _LIBCPP_HIDE_FROM_ABI float sinh(float __x) _NOEXCEPT {return ::sinhf(__x);}
934inline _LIBCPP_HIDE_FROM_ABI long double sinh(long double __x) _NOEXCEPT {return ::sinhl(__x);}
David Tenty7249ac92022-02-07 18:22:35 -0500935# endif
Richard Smith081bb592015-10-08 20:40:34 +0000936
937template <class _A1>
Nikolas Klauser4956e722022-10-12 15:41:22 +0200938inline _LIBCPP_HIDE_FROM_ABI
Richard Smith081bb592015-10-08 20:40:34 +0000939typename std::enable_if<std::is_integral<_A1>::value, double>::type
Nikolas Klauser9806f452022-10-12 15:45:09 +0200940sinh(_A1 __x) _NOEXCEPT {return ::sinh((double)__x);}
Richard Smith081bb592015-10-08 20:40:34 +0000941
942// sqrt
943
David Tenty7249ac92022-02-07 18:22:35 -0500944# if !defined(__sun__)
Nikolas Klauser9806f452022-10-12 15:45:09 +0200945inline _LIBCPP_HIDE_FROM_ABI float sqrt(float __x) _NOEXCEPT {return ::sqrtf(__x);}
946inline _LIBCPP_HIDE_FROM_ABI long double sqrt(long double __x) _NOEXCEPT {return ::sqrtl(__x);}
David Tenty7249ac92022-02-07 18:22:35 -0500947# endif
Richard Smith081bb592015-10-08 20:40:34 +0000948
Richard Smith081bb592015-10-08 20:40:34 +0000949template <class _A1>
Nikolas Klauser4956e722022-10-12 15:41:22 +0200950inline _LIBCPP_HIDE_FROM_ABI
Richard Smith081bb592015-10-08 20:40:34 +0000951typename std::enable_if<std::is_integral<_A1>::value, double>::type
Nikolas Klauser9806f452022-10-12 15:45:09 +0200952sqrt(_A1 __x) _NOEXCEPT {return ::sqrt((double)__x);}
Richard Smith081bb592015-10-08 20:40:34 +0000953
954// tan
955
David Tenty7249ac92022-02-07 18:22:35 -0500956# if !defined(__sun__)
Nikolas Klauser9806f452022-10-12 15:45:09 +0200957inline _LIBCPP_HIDE_FROM_ABI float tan(float __x) _NOEXCEPT {return ::tanf(__x);}
958inline _LIBCPP_HIDE_FROM_ABI long double tan(long double __x) _NOEXCEPT {return ::tanl(__x);}
David Tenty7249ac92022-02-07 18:22:35 -0500959# endif
Richard Smith081bb592015-10-08 20:40:34 +0000960
961template <class _A1>
Nikolas Klauser4956e722022-10-12 15:41:22 +0200962inline _LIBCPP_HIDE_FROM_ABI
Richard Smith081bb592015-10-08 20:40:34 +0000963typename std::enable_if<std::is_integral<_A1>::value, double>::type
Nikolas Klauser9806f452022-10-12 15:45:09 +0200964tan(_A1 __x) _NOEXCEPT {return ::tan((double)__x);}
Richard Smith081bb592015-10-08 20:40:34 +0000965
966// tanh
967
David Tenty7249ac92022-02-07 18:22:35 -0500968# if !defined(__sun__)
Nikolas Klauser9806f452022-10-12 15:45:09 +0200969inline _LIBCPP_HIDE_FROM_ABI float tanh(float __x) _NOEXCEPT {return ::tanhf(__x);}
970inline _LIBCPP_HIDE_FROM_ABI long double tanh(long double __x) _NOEXCEPT {return ::tanhl(__x);}
David Tenty7249ac92022-02-07 18:22:35 -0500971# endif
Richard Smith081bb592015-10-08 20:40:34 +0000972
973template <class _A1>
Nikolas Klauser4956e722022-10-12 15:41:22 +0200974inline _LIBCPP_HIDE_FROM_ABI
Richard Smith081bb592015-10-08 20:40:34 +0000975typename std::enable_if<std::is_integral<_A1>::value, double>::type
Nikolas Klauser9806f452022-10-12 15:45:09 +0200976tanh(_A1 __x) _NOEXCEPT {return ::tanh((double)__x);}
Richard Smith081bb592015-10-08 20:40:34 +0000977
978// acosh
979
Nikolas Klauser9806f452022-10-12 15:45:09 +0200980inline _LIBCPP_HIDE_FROM_ABI float acosh(float __x) _NOEXCEPT {return ::acoshf(__x);}
981inline _LIBCPP_HIDE_FROM_ABI long double acosh(long double __x) _NOEXCEPT {return ::acoshl(__x);}
Richard Smith081bb592015-10-08 20:40:34 +0000982
983template <class _A1>
Nikolas Klauser4956e722022-10-12 15:41:22 +0200984inline _LIBCPP_HIDE_FROM_ABI
Richard Smith081bb592015-10-08 20:40:34 +0000985typename std::enable_if<std::is_integral<_A1>::value, double>::type
Nikolas Klauser9806f452022-10-12 15:45:09 +0200986acosh(_A1 __x) _NOEXCEPT {return ::acosh((double)__x);}
Richard Smith081bb592015-10-08 20:40:34 +0000987
988// asinh
989
Nikolas Klauser9806f452022-10-12 15:45:09 +0200990inline _LIBCPP_HIDE_FROM_ABI float asinh(float __x) _NOEXCEPT {return ::asinhf(__x);}
991inline _LIBCPP_HIDE_FROM_ABI long double asinh(long double __x) _NOEXCEPT {return ::asinhl(__x);}
Richard Smith081bb592015-10-08 20:40:34 +0000992
993template <class _A1>
Nikolas Klauser4956e722022-10-12 15:41:22 +0200994inline _LIBCPP_HIDE_FROM_ABI
Richard Smith081bb592015-10-08 20:40:34 +0000995typename std::enable_if<std::is_integral<_A1>::value, double>::type
Nikolas Klauser9806f452022-10-12 15:45:09 +0200996asinh(_A1 __x) _NOEXCEPT {return ::asinh((double)__x);}
Richard Smith081bb592015-10-08 20:40:34 +0000997
998// atanh
999
Nikolas Klauser9806f452022-10-12 15:45:09 +02001000inline _LIBCPP_HIDE_FROM_ABI float atanh(float __x) _NOEXCEPT {return ::atanhf(__x);}
1001inline _LIBCPP_HIDE_FROM_ABI long double atanh(long double __x) _NOEXCEPT {return ::atanhl(__x);}
Richard Smith081bb592015-10-08 20:40:34 +00001002
1003template <class _A1>
Nikolas Klauser4956e722022-10-12 15:41:22 +02001004inline _LIBCPP_HIDE_FROM_ABI
Richard Smith081bb592015-10-08 20:40:34 +00001005typename std::enable_if<std::is_integral<_A1>::value, double>::type
Nikolas Klauser9806f452022-10-12 15:45:09 +02001006atanh(_A1 __x) _NOEXCEPT {return ::atanh((double)__x);}
Richard Smith081bb592015-10-08 20:40:34 +00001007
1008// cbrt
1009
Nikolas Klauser9806f452022-10-12 15:45:09 +02001010inline _LIBCPP_HIDE_FROM_ABI float cbrt(float __x) _NOEXCEPT {return ::cbrtf(__x);}
1011inline _LIBCPP_HIDE_FROM_ABI long double cbrt(long double __x) _NOEXCEPT {return ::cbrtl(__x);}
Richard Smith081bb592015-10-08 20:40:34 +00001012
1013template <class _A1>
Nikolas Klauser4956e722022-10-12 15:41:22 +02001014inline _LIBCPP_HIDE_FROM_ABI
Richard Smith081bb592015-10-08 20:40:34 +00001015typename std::enable_if<std::is_integral<_A1>::value, double>::type
Nikolas Klauser9806f452022-10-12 15:45:09 +02001016cbrt(_A1 __x) _NOEXCEPT {return ::cbrt((double)__x);}
Richard Smith081bb592015-10-08 20:40:34 +00001017
1018// copysign
1019
Marek Kurdeja933f0d2021-07-21 15:58:17 +02001020#if __has_builtin(__builtin_copysignf)
1021_LIBCPP_CONSTEXPR
1022#endif
Nikolas Klauser9806f452022-10-12 15:45:09 +02001023inline _LIBCPP_HIDE_FROM_ABI float __libcpp_copysign(float __x, float __y) _NOEXCEPT {
Ilya Tokarc3abffb2021-02-10 13:05:19 -05001024#if __has_builtin(__builtin_copysignf)
Nikolas Klauser9806f452022-10-12 15:45:09 +02001025 return __builtin_copysignf(__x, __y);
Ilya Tokarc3abffb2021-02-10 13:05:19 -05001026#else
Nikolas Klauser9806f452022-10-12 15:45:09 +02001027 return ::copysignf(__x, __y);
Ilya Tokarc3abffb2021-02-10 13:05:19 -05001028#endif
Richard Smith081bb592015-10-08 20:40:34 +00001029}
Marek Kurdeja933f0d2021-07-21 15:58:17 +02001030
1031#if __has_builtin(__builtin_copysign)
1032_LIBCPP_CONSTEXPR
1033#endif
Nikolas Klauser9806f452022-10-12 15:45:09 +02001034inline _LIBCPP_HIDE_FROM_ABI double __libcpp_copysign(double __x, double __y) _NOEXCEPT {
Marek Kurdeja933f0d2021-07-21 15:58:17 +02001035#if __has_builtin(__builtin_copysign)
Nikolas Klauser9806f452022-10-12 15:45:09 +02001036 return __builtin_copysign(__x, __y);
Marek Kurdeja933f0d2021-07-21 15:58:17 +02001037#else
Nikolas Klauser9806f452022-10-12 15:45:09 +02001038 return ::copysign(__x, __y);
Marek Kurdeja933f0d2021-07-21 15:58:17 +02001039#endif
1040}
1041
1042#if __has_builtin(__builtin_copysignl)
1043_LIBCPP_CONSTEXPR
1044#endif
Nikolas Klauser9806f452022-10-12 15:45:09 +02001045inline _LIBCPP_HIDE_FROM_ABI long double __libcpp_copysign(long double __x, long double __y) _NOEXCEPT {
Ilya Tokarc3abffb2021-02-10 13:05:19 -05001046#if __has_builtin(__builtin_copysignl)
Nikolas Klauser9806f452022-10-12 15:45:09 +02001047 return __builtin_copysignl(__x, __y);
Ilya Tokarc3abffb2021-02-10 13:05:19 -05001048#else
Nikolas Klauser9806f452022-10-12 15:45:09 +02001049 return ::copysignl(__x, __y);
Ilya Tokarc3abffb2021-02-10 13:05:19 -05001050#endif
Richard Smith081bb592015-10-08 20:40:34 +00001051}
Richard Smith081bb592015-10-08 20:40:34 +00001052
1053template <class _A1, class _A2>
Marek Kurdeja933f0d2021-07-21 15:58:17 +02001054#if __has_builtin(__builtin_copysign)
1055_LIBCPP_CONSTEXPR
1056#endif
Nikolas Klauser4956e722022-10-12 15:41:22 +02001057inline _LIBCPP_HIDE_FROM_ABI
Louis Dionne9ce598d2021-09-08 09:14:43 -04001058typename std::__enable_if_t
Marek Kurdeja933f0d2021-07-21 15:58:17 +02001059<
1060 std::is_arithmetic<_A1>::value &&
1061 std::is_arithmetic<_A2>::value,
1062 std::__promote<_A1, _A2>
1063>::type
Nikolas Klauser9806f452022-10-12 15:45:09 +02001064__libcpp_copysign(_A1 __x, _A2 __y) _NOEXCEPT {
Marek Kurdeja933f0d2021-07-21 15:58:17 +02001065 typedef typename std::__promote<_A1, _A2>::type __result_type;
1066 static_assert((!(std::_IsSame<_A1, __result_type>::value &&
1067 std::_IsSame<_A2, __result_type>::value)), "");
1068#if __has_builtin(__builtin_copysign)
Nikolas Klauser9806f452022-10-12 15:45:09 +02001069 return __builtin_copysign((__result_type)__x, (__result_type)__y);
Marek Kurdeja933f0d2021-07-21 15:58:17 +02001070#else
Nikolas Klauser9806f452022-10-12 15:45:09 +02001071 return ::copysign((__result_type)__x, (__result_type)__y);
Marek Kurdeja933f0d2021-07-21 15:58:17 +02001072#endif
1073}
1074
Nikolas Klauser9806f452022-10-12 15:45:09 +02001075inline _LIBCPP_HIDE_FROM_ABI float copysign(float __x, float __y) _NOEXCEPT {
1076 return ::__libcpp_copysign(__x, __y);
Marek Kurdeja933f0d2021-07-21 15:58:17 +02001077}
1078
Nikolas Klauser9806f452022-10-12 15:45:09 +02001079inline _LIBCPP_HIDE_FROM_ABI long double copysign(long double __x, long double __y) _NOEXCEPT {
1080 return ::__libcpp_copysign(__x, __y);
Marek Kurdeja933f0d2021-07-21 15:58:17 +02001081}
1082
1083template <class _A1, class _A2>
Nikolas Klauser4956e722022-10-12 15:41:22 +02001084inline _LIBCPP_HIDE_FROM_ABI
Louis Dionne9ce598d2021-09-08 09:14:43 -04001085typename std::__enable_if_t
Richard Smith081bb592015-10-08 20:40:34 +00001086<
1087 std::is_arithmetic<_A1>::value &&
1088 std::is_arithmetic<_A2>::value,
1089 std::__promote<_A1, _A2>
1090>::type
Nikolas Klauser9806f452022-10-12 15:45:09 +02001091 copysign(_A1 __x, _A2 __y) _NOEXCEPT {
1092 return ::__libcpp_copysign(__x, __y);
Richard Smith081bb592015-10-08 20:40:34 +00001093}
1094
Richard Smith081bb592015-10-08 20:40:34 +00001095// erf
1096
Nikolas Klauser9806f452022-10-12 15:45:09 +02001097inline _LIBCPP_HIDE_FROM_ABI float erf(float __x) _NOEXCEPT {return ::erff(__x);}
1098inline _LIBCPP_HIDE_FROM_ABI long double erf(long double __x) _NOEXCEPT {return ::erfl(__x);}
Richard Smith081bb592015-10-08 20:40:34 +00001099
1100template <class _A1>
Nikolas Klauser4956e722022-10-12 15:41:22 +02001101inline _LIBCPP_HIDE_FROM_ABI
Richard Smith081bb592015-10-08 20:40:34 +00001102typename std::enable_if<std::is_integral<_A1>::value, double>::type
Nikolas Klauser9806f452022-10-12 15:45:09 +02001103erf(_A1 __x) _NOEXCEPT {return ::erf((double)__x);}
Richard Smith081bb592015-10-08 20:40:34 +00001104
1105// erfc
1106
Nikolas Klauser9806f452022-10-12 15:45:09 +02001107inline _LIBCPP_HIDE_FROM_ABI float erfc(float __x) _NOEXCEPT {return ::erfcf(__x);}
1108inline _LIBCPP_HIDE_FROM_ABI long double erfc(long double __x) _NOEXCEPT {return ::erfcl(__x);}
Richard Smith081bb592015-10-08 20:40:34 +00001109
1110template <class _A1>
Nikolas Klauser4956e722022-10-12 15:41:22 +02001111inline _LIBCPP_HIDE_FROM_ABI
Richard Smith081bb592015-10-08 20:40:34 +00001112typename std::enable_if<std::is_integral<_A1>::value, double>::type
Nikolas Klauser9806f452022-10-12 15:45:09 +02001113erfc(_A1 __x) _NOEXCEPT {return ::erfc((double)__x);}
Richard Smith081bb592015-10-08 20:40:34 +00001114
1115// exp2
1116
Nikolas Klauser9806f452022-10-12 15:45:09 +02001117inline _LIBCPP_HIDE_FROM_ABI float exp2(float __x) _NOEXCEPT {return ::exp2f(__x);}
1118inline _LIBCPP_HIDE_FROM_ABI long double exp2(long double __x) _NOEXCEPT {return ::exp2l(__x);}
Richard Smith081bb592015-10-08 20:40:34 +00001119
1120template <class _A1>
Nikolas Klauser4956e722022-10-12 15:41:22 +02001121inline _LIBCPP_HIDE_FROM_ABI
Richard Smith081bb592015-10-08 20:40:34 +00001122typename std::enable_if<std::is_integral<_A1>::value, double>::type
Nikolas Klauser9806f452022-10-12 15:45:09 +02001123exp2(_A1 __x) _NOEXCEPT {return ::exp2((double)__x);}
Richard Smith081bb592015-10-08 20:40:34 +00001124
1125// expm1
1126
Nikolas Klauser9806f452022-10-12 15:45:09 +02001127inline _LIBCPP_HIDE_FROM_ABI float expm1(float __x) _NOEXCEPT {return ::expm1f(__x);}
1128inline _LIBCPP_HIDE_FROM_ABI long double expm1(long double __x) _NOEXCEPT {return ::expm1l(__x);}
Richard Smith081bb592015-10-08 20:40:34 +00001129
1130template <class _A1>
Nikolas Klauser4956e722022-10-12 15:41:22 +02001131inline _LIBCPP_HIDE_FROM_ABI
Richard Smith081bb592015-10-08 20:40:34 +00001132typename std::enable_if<std::is_integral<_A1>::value, double>::type
Nikolas Klauser9806f452022-10-12 15:45:09 +02001133expm1(_A1 __x) _NOEXCEPT {return ::expm1((double)__x);}
Richard Smith081bb592015-10-08 20:40:34 +00001134
1135// fdim
1136
Nikolas Klauser9806f452022-10-12 15:45:09 +02001137inline _LIBCPP_HIDE_FROM_ABI float fdim(float __x, float __y) _NOEXCEPT {return ::fdimf(__x, __y);}
1138inline _LIBCPP_HIDE_FROM_ABI long double fdim(long double __x, long double __y) _NOEXCEPT {return ::fdiml(__x, __y);}
Richard Smith081bb592015-10-08 20:40:34 +00001139
1140template <class _A1, class _A2>
Nikolas Klauser4956e722022-10-12 15:41:22 +02001141inline _LIBCPP_HIDE_FROM_ABI
Louis Dionne9ce598d2021-09-08 09:14:43 -04001142typename std::__enable_if_t
Richard Smith081bb592015-10-08 20:40:34 +00001143<
1144 std::is_arithmetic<_A1>::value &&
1145 std::is_arithmetic<_A2>::value,
1146 std::__promote<_A1, _A2>
1147>::type
Nikolas Klauser9806f452022-10-12 15:45:09 +02001148fdim(_A1 __x, _A2 __y) _NOEXCEPT
Richard Smith081bb592015-10-08 20:40:34 +00001149{
1150 typedef typename std::__promote<_A1, _A2>::type __result_type;
Eric Fiselier3906a132019-06-23 20:28:29 +00001151 static_assert((!(std::_IsSame<_A1, __result_type>::value &&
1152 std::_IsSame<_A2, __result_type>::value)), "");
Nikolas Klauser9806f452022-10-12 15:45:09 +02001153 return ::fdim((__result_type)__x, (__result_type)__y);
Richard Smith081bb592015-10-08 20:40:34 +00001154}
1155
1156// fma
1157
Nikolas Klauser9806f452022-10-12 15:45:09 +02001158inline _LIBCPP_HIDE_FROM_ABI float fma(float __x, float __y, float __z) _NOEXCEPT
Ilya Tokarc3abffb2021-02-10 13:05:19 -05001159{
1160#if __has_builtin(__builtin_fmaf)
Nikolas Klauser9806f452022-10-12 15:45:09 +02001161 return __builtin_fmaf(__x, __y, __z);
Ilya Tokarc3abffb2021-02-10 13:05:19 -05001162#else
Nikolas Klauser9806f452022-10-12 15:45:09 +02001163 return ::fmaf(__x, __y, __z);
Ilya Tokarc3abffb2021-02-10 13:05:19 -05001164#endif
1165}
Nikolas Klauser9806f452022-10-12 15:45:09 +02001166inline _LIBCPP_HIDE_FROM_ABI long double fma(long double __x, long double __y, long double __z) _NOEXCEPT
Ilya Tokarc3abffb2021-02-10 13:05:19 -05001167{
1168#if __has_builtin(__builtin_fmal)
Nikolas Klauser9806f452022-10-12 15:45:09 +02001169 return __builtin_fmal(__x, __y, __z);
Ilya Tokarc3abffb2021-02-10 13:05:19 -05001170#else
Nikolas Klauser9806f452022-10-12 15:45:09 +02001171 return ::fmal(__x, __y, __z);
Ilya Tokarc3abffb2021-02-10 13:05:19 -05001172#endif
1173}
Richard Smith081bb592015-10-08 20:40:34 +00001174
1175template <class _A1, class _A2, class _A3>
Nikolas Klauser4956e722022-10-12 15:41:22 +02001176inline _LIBCPP_HIDE_FROM_ABI
Louis Dionne9ce598d2021-09-08 09:14:43 -04001177typename std::__enable_if_t
Richard Smith081bb592015-10-08 20:40:34 +00001178<
1179 std::is_arithmetic<_A1>::value &&
1180 std::is_arithmetic<_A2>::value &&
1181 std::is_arithmetic<_A3>::value,
1182 std::__promote<_A1, _A2, _A3>
1183>::type
Nikolas Klauser9806f452022-10-12 15:45:09 +02001184fma(_A1 __x, _A2 __y, _A3 __z) _NOEXCEPT
Richard Smith081bb592015-10-08 20:40:34 +00001185{
1186 typedef typename std::__promote<_A1, _A2, _A3>::type __result_type;
Eric Fiselier3906a132019-06-23 20:28:29 +00001187 static_assert((!(std::_IsSame<_A1, __result_type>::value &&
1188 std::_IsSame<_A2, __result_type>::value &&
1189 std::_IsSame<_A3, __result_type>::value)), "");
Ilya Tokarc3abffb2021-02-10 13:05:19 -05001190#if __has_builtin(__builtin_fma)
Nikolas Klauser9806f452022-10-12 15:45:09 +02001191 return __builtin_fma((__result_type)__x, (__result_type)__y, (__result_type)__z);
Ilya Tokarc3abffb2021-02-10 13:05:19 -05001192#else
Nikolas Klauser9806f452022-10-12 15:45:09 +02001193 return ::fma((__result_type)__x, (__result_type)__y, (__result_type)__z);
Ilya Tokarc3abffb2021-02-10 13:05:19 -05001194#endif
Richard Smith081bb592015-10-08 20:40:34 +00001195}
1196
1197// fmax
1198
Nikolas Klauser9806f452022-10-12 15:45:09 +02001199inline _LIBCPP_HIDE_FROM_ABI float fmax(float __x, float __y) _NOEXCEPT {return ::fmaxf(__x, __y);}
1200inline _LIBCPP_HIDE_FROM_ABI long double fmax(long double __x, long double __y) _NOEXCEPT {return ::fmaxl(__x, __y);}
Richard Smith081bb592015-10-08 20:40:34 +00001201
1202template <class _A1, class _A2>
Nikolas Klauser4956e722022-10-12 15:41:22 +02001203inline _LIBCPP_HIDE_FROM_ABI
Louis Dionne9ce598d2021-09-08 09:14:43 -04001204typename std::__enable_if_t
Richard Smith081bb592015-10-08 20:40:34 +00001205<
1206 std::is_arithmetic<_A1>::value &&
1207 std::is_arithmetic<_A2>::value,
1208 std::__promote<_A1, _A2>
1209>::type
Nikolas Klauser9806f452022-10-12 15:45:09 +02001210fmax(_A1 __x, _A2 __y) _NOEXCEPT
Richard Smith081bb592015-10-08 20:40:34 +00001211{
1212 typedef typename std::__promote<_A1, _A2>::type __result_type;
Eric Fiselier3906a132019-06-23 20:28:29 +00001213 static_assert((!(std::_IsSame<_A1, __result_type>::value &&
1214 std::_IsSame<_A2, __result_type>::value)), "");
Nikolas Klauser9806f452022-10-12 15:45:09 +02001215 return ::fmax((__result_type)__x, (__result_type)__y);
Richard Smith081bb592015-10-08 20:40:34 +00001216}
1217
1218// fmin
1219
Nikolas Klauser9806f452022-10-12 15:45:09 +02001220inline _LIBCPP_HIDE_FROM_ABI float fmin(float __x, float __y) _NOEXCEPT {return ::fminf(__x, __y);}
1221inline _LIBCPP_HIDE_FROM_ABI long double fmin(long double __x, long double __y) _NOEXCEPT {return ::fminl(__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 +02001231fmin(_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 ::fmin((__result_type)__x, (__result_type)__y);
Richard Smith081bb592015-10-08 20:40:34 +00001237}
1238
1239// hypot
1240
Nikolas Klauser9806f452022-10-12 15:45:09 +02001241inline _LIBCPP_HIDE_FROM_ABI float hypot(float __x, float __y) _NOEXCEPT {return ::hypotf(__x, __y);}
1242inline _LIBCPP_HIDE_FROM_ABI long double hypot(long double __x, long double __y) _NOEXCEPT {return ::hypotl(__x, __y);}
Richard Smith081bb592015-10-08 20:40:34 +00001243
1244template <class _A1, class _A2>
Nikolas Klauser4956e722022-10-12 15:41:22 +02001245inline _LIBCPP_HIDE_FROM_ABI
Louis Dionne9ce598d2021-09-08 09:14:43 -04001246typename std::__enable_if_t
Richard Smith081bb592015-10-08 20:40:34 +00001247<
1248 std::is_arithmetic<_A1>::value &&
1249 std::is_arithmetic<_A2>::value,
1250 std::__promote<_A1, _A2>
1251>::type
Nikolas Klauser9806f452022-10-12 15:45:09 +02001252hypot(_A1 __x, _A2 __y) _NOEXCEPT
Richard Smith081bb592015-10-08 20:40:34 +00001253{
1254 typedef typename std::__promote<_A1, _A2>::type __result_type;
Eric Fiselier3906a132019-06-23 20:28:29 +00001255 static_assert((!(std::_IsSame<_A1, __result_type>::value &&
1256 std::_IsSame<_A2, __result_type>::value)), "");
Nikolas Klauser9806f452022-10-12 15:45:09 +02001257 return ::hypot((__result_type)__x, (__result_type)__y);
Richard Smith081bb592015-10-08 20:40:34 +00001258}
1259
1260// ilogb
1261
Nikolas Klauser9806f452022-10-12 15:45:09 +02001262inline _LIBCPP_HIDE_FROM_ABI int ilogb(float __x) _NOEXCEPT {return ::ilogbf(__x);}
1263inline _LIBCPP_HIDE_FROM_ABI int ilogb(long double __x) _NOEXCEPT {return ::ilogbl(__x);}
Richard Smith081bb592015-10-08 20:40:34 +00001264
1265template <class _A1>
Nikolas Klauser4956e722022-10-12 15:41:22 +02001266inline _LIBCPP_HIDE_FROM_ABI
Richard Smith081bb592015-10-08 20:40:34 +00001267typename std::enable_if<std::is_integral<_A1>::value, int>::type
Nikolas Klauser9806f452022-10-12 15:45:09 +02001268ilogb(_A1 __x) _NOEXCEPT {return ::ilogb((double)__x);}
Richard Smith081bb592015-10-08 20:40:34 +00001269
1270// lgamma
1271
Nikolas Klauser9806f452022-10-12 15:45:09 +02001272inline _LIBCPP_HIDE_FROM_ABI float lgamma(float __x) _NOEXCEPT {return ::lgammaf(__x);}
1273inline _LIBCPP_HIDE_FROM_ABI long double lgamma(long double __x) _NOEXCEPT {return ::lgammal(__x);}
Richard Smith081bb592015-10-08 20:40:34 +00001274
1275template <class _A1>
Nikolas Klauser4956e722022-10-12 15:41:22 +02001276inline _LIBCPP_HIDE_FROM_ABI
Richard Smith081bb592015-10-08 20:40:34 +00001277typename std::enable_if<std::is_integral<_A1>::value, double>::type
Nikolas Klauser9806f452022-10-12 15:45:09 +02001278lgamma(_A1 __x) _NOEXCEPT {return ::lgamma((double)__x);}
Richard Smith081bb592015-10-08 20:40:34 +00001279
1280// llrint
1281
Nikolas Klauser9806f452022-10-12 15:45:09 +02001282inline _LIBCPP_HIDE_FROM_ABI long long llrint(float __x) _NOEXCEPT
Ilya Tokarc3abffb2021-02-10 13:05:19 -05001283{
1284#if __has_builtin(__builtin_llrintf)
Nikolas Klauser9806f452022-10-12 15:45:09 +02001285 return __builtin_llrintf(__x);
Ilya Tokarc3abffb2021-02-10 13:05:19 -05001286#else
Nikolas Klauser9806f452022-10-12 15:45:09 +02001287 return ::llrintf(__x);
Ilya Tokarc3abffb2021-02-10 13:05:19 -05001288#endif
1289}
Nikolas Klauser9806f452022-10-12 15:45:09 +02001290inline _LIBCPP_HIDE_FROM_ABI long long llrint(long double __x) _NOEXCEPT
Ilya Tokarc3abffb2021-02-10 13:05:19 -05001291{
1292#if __has_builtin(__builtin_llrintl)
Nikolas Klauser9806f452022-10-12 15:45:09 +02001293 return __builtin_llrintl(__x);
Ilya Tokarc3abffb2021-02-10 13:05:19 -05001294#else
Nikolas Klauser9806f452022-10-12 15:45:09 +02001295 return ::llrintl(__x);
Ilya Tokarc3abffb2021-02-10 13:05:19 -05001296#endif
1297}
Richard Smith081bb592015-10-08 20:40:34 +00001298
1299template <class _A1>
Nikolas Klauser4956e722022-10-12 15:41:22 +02001300inline _LIBCPP_HIDE_FROM_ABI
Richard Smith081bb592015-10-08 20:40:34 +00001301typename std::enable_if<std::is_integral<_A1>::value, long long>::type
Nikolas Klauser9806f452022-10-12 15:45:09 +02001302llrint(_A1 __x) _NOEXCEPT
Ilya Tokarc3abffb2021-02-10 13:05:19 -05001303{
1304#if __has_builtin(__builtin_llrint)
Nikolas Klauser9806f452022-10-12 15:45:09 +02001305 return __builtin_llrint((double)__x);
Ilya Tokarc3abffb2021-02-10 13:05:19 -05001306#else
Nikolas Klauser9806f452022-10-12 15:45:09 +02001307 return ::llrint((double)__x);
Ilya Tokarc3abffb2021-02-10 13:05:19 -05001308#endif
1309}
Richard Smith081bb592015-10-08 20:40:34 +00001310
1311// llround
1312
Nikolas Klauser9806f452022-10-12 15:45:09 +02001313inline _LIBCPP_HIDE_FROM_ABI long long llround(float __x) _NOEXCEPT
Ilya Tokarc3abffb2021-02-10 13:05:19 -05001314{
1315#if __has_builtin(__builtin_llroundf)
Nikolas Klauser9806f452022-10-12 15:45:09 +02001316 return __builtin_llroundf(__x);
Ilya Tokarc3abffb2021-02-10 13:05:19 -05001317#else
Nikolas Klauser9806f452022-10-12 15:45:09 +02001318 return ::llroundf(__x);
Ilya Tokarc3abffb2021-02-10 13:05:19 -05001319#endif
1320}
Nikolas Klauser9806f452022-10-12 15:45:09 +02001321inline _LIBCPP_HIDE_FROM_ABI long long llround(long double __x) _NOEXCEPT
Ilya Tokarc3abffb2021-02-10 13:05:19 -05001322{
1323#if __has_builtin(__builtin_llroundl)
Nikolas Klauser9806f452022-10-12 15:45:09 +02001324 return __builtin_llroundl(__x);
Ilya Tokarc3abffb2021-02-10 13:05:19 -05001325#else
Nikolas Klauser9806f452022-10-12 15:45:09 +02001326 return ::llroundl(__x);
Ilya Tokarc3abffb2021-02-10 13:05:19 -05001327#endif
1328}
Richard Smith081bb592015-10-08 20:40:34 +00001329
1330template <class _A1>
Nikolas Klauser4956e722022-10-12 15:41:22 +02001331inline _LIBCPP_HIDE_FROM_ABI
Richard Smith081bb592015-10-08 20:40:34 +00001332typename std::enable_if<std::is_integral<_A1>::value, long long>::type
Nikolas Klauser9806f452022-10-12 15:45:09 +02001333llround(_A1 __x) _NOEXCEPT
Ilya Tokarc3abffb2021-02-10 13:05:19 -05001334{
1335#if __has_builtin(__builtin_llround)
Nikolas Klauser9806f452022-10-12 15:45:09 +02001336 return __builtin_llround((double)__x);
Ilya Tokarc3abffb2021-02-10 13:05:19 -05001337#else
Nikolas Klauser9806f452022-10-12 15:45:09 +02001338 return ::llround((double)__x);
Ilya Tokarc3abffb2021-02-10 13:05:19 -05001339#endif
1340}
Richard Smith081bb592015-10-08 20:40:34 +00001341
1342// log1p
1343
Nikolas Klauser9806f452022-10-12 15:45:09 +02001344inline _LIBCPP_HIDE_FROM_ABI float log1p(float __x) _NOEXCEPT {return ::log1pf(__x);}
1345inline _LIBCPP_HIDE_FROM_ABI long double log1p(long double __x) _NOEXCEPT {return ::log1pl(__x);}
Richard Smith081bb592015-10-08 20:40:34 +00001346
1347template <class _A1>
Nikolas Klauser4956e722022-10-12 15:41:22 +02001348inline _LIBCPP_HIDE_FROM_ABI
Richard Smith081bb592015-10-08 20:40:34 +00001349typename std::enable_if<std::is_integral<_A1>::value, double>::type
Nikolas Klauser9806f452022-10-12 15:45:09 +02001350log1p(_A1 __x) _NOEXCEPT {return ::log1p((double)__x);}
Richard Smith081bb592015-10-08 20:40:34 +00001351
1352// log2
1353
Nikolas Klauser9806f452022-10-12 15:45:09 +02001354inline _LIBCPP_HIDE_FROM_ABI float log2(float __x) _NOEXCEPT {return ::log2f(__x);}
1355inline _LIBCPP_HIDE_FROM_ABI long double log2(long double __x) _NOEXCEPT {return ::log2l(__x);}
Richard Smith081bb592015-10-08 20:40:34 +00001356
1357template <class _A1>
Nikolas Klauser4956e722022-10-12 15:41:22 +02001358inline _LIBCPP_HIDE_FROM_ABI
Richard Smith081bb592015-10-08 20:40:34 +00001359typename std::enable_if<std::is_integral<_A1>::value, double>::type
Nikolas Klauser9806f452022-10-12 15:45:09 +02001360log2(_A1 __x) _NOEXCEPT {return ::log2((double)__x);}
Richard Smith081bb592015-10-08 20:40:34 +00001361
1362// logb
1363
Nikolas Klauser9806f452022-10-12 15:45:09 +02001364inline _LIBCPP_HIDE_FROM_ABI float logb(float __x) _NOEXCEPT {return ::logbf(__x);}
1365inline _LIBCPP_HIDE_FROM_ABI long double logb(long double __x) _NOEXCEPT {return ::logbl(__x);}
Richard Smith081bb592015-10-08 20:40:34 +00001366
1367template <class _A1>
Nikolas Klauser4956e722022-10-12 15:41:22 +02001368inline _LIBCPP_HIDE_FROM_ABI
Richard Smith081bb592015-10-08 20:40:34 +00001369typename std::enable_if<std::is_integral<_A1>::value, double>::type
Nikolas Klauser9806f452022-10-12 15:45:09 +02001370logb(_A1 __x) _NOEXCEPT {return ::logb((double)__x);}
Richard Smith081bb592015-10-08 20:40:34 +00001371
1372// lrint
1373
Nikolas Klauser9806f452022-10-12 15:45:09 +02001374inline _LIBCPP_HIDE_FROM_ABI long lrint(float __x) _NOEXCEPT
Ilya Tokarc3abffb2021-02-10 13:05:19 -05001375{
1376#if __has_builtin(__builtin_lrintf)
Nikolas Klauser9806f452022-10-12 15:45:09 +02001377 return __builtin_lrintf(__x);
Ilya Tokarc3abffb2021-02-10 13:05:19 -05001378#else
Nikolas Klauser9806f452022-10-12 15:45:09 +02001379 return ::lrintf(__x);
Ilya Tokarc3abffb2021-02-10 13:05:19 -05001380#endif
1381}
Nikolas Klauser9806f452022-10-12 15:45:09 +02001382inline _LIBCPP_HIDE_FROM_ABI long lrint(long double __x) _NOEXCEPT
Ilya Tokarc3abffb2021-02-10 13:05:19 -05001383{
1384#if __has_builtin(__builtin_lrintl)
Nikolas Klauser9806f452022-10-12 15:45:09 +02001385 return __builtin_lrintl(__x);
Ilya Tokarc3abffb2021-02-10 13:05:19 -05001386#else
Nikolas Klauser9806f452022-10-12 15:45:09 +02001387 return ::lrintl(__x);
Ilya Tokarc3abffb2021-02-10 13:05:19 -05001388#endif
1389}
Richard Smith081bb592015-10-08 20:40:34 +00001390
1391template <class _A1>
Nikolas Klauser4956e722022-10-12 15:41:22 +02001392inline _LIBCPP_HIDE_FROM_ABI
Richard Smith081bb592015-10-08 20:40:34 +00001393typename std::enable_if<std::is_integral<_A1>::value, long>::type
Nikolas Klauser9806f452022-10-12 15:45:09 +02001394lrint(_A1 __x) _NOEXCEPT
Ilya Tokarc3abffb2021-02-10 13:05:19 -05001395{
1396#if __has_builtin(__builtin_lrint)
Nikolas Klauser9806f452022-10-12 15:45:09 +02001397 return __builtin_lrint((double)__x);
Ilya Tokarc3abffb2021-02-10 13:05:19 -05001398#else
Nikolas Klauser9806f452022-10-12 15:45:09 +02001399 return ::lrint((double)__x);
Ilya Tokarc3abffb2021-02-10 13:05:19 -05001400#endif
1401}
Richard Smith081bb592015-10-08 20:40:34 +00001402
1403// lround
1404
Nikolas Klauser9806f452022-10-12 15:45:09 +02001405inline _LIBCPP_HIDE_FROM_ABI long lround(float __x) _NOEXCEPT
Ilya Tokarc3abffb2021-02-10 13:05:19 -05001406{
1407#if __has_builtin(__builtin_lroundf)
Nikolas Klauser9806f452022-10-12 15:45:09 +02001408 return __builtin_lroundf(__x);
Ilya Tokarc3abffb2021-02-10 13:05:19 -05001409#else
Nikolas Klauser9806f452022-10-12 15:45:09 +02001410 return ::lroundf(__x);
Ilya Tokarc3abffb2021-02-10 13:05:19 -05001411#endif
1412}
Nikolas Klauser9806f452022-10-12 15:45:09 +02001413inline _LIBCPP_HIDE_FROM_ABI long lround(long double __x) _NOEXCEPT
Ilya Tokarc3abffb2021-02-10 13:05:19 -05001414{
1415#if __has_builtin(__builtin_lroundl)
Nikolas Klauser9806f452022-10-12 15:45:09 +02001416 return __builtin_lroundl(__x);
Ilya Tokarc3abffb2021-02-10 13:05:19 -05001417#else
Nikolas Klauser9806f452022-10-12 15:45:09 +02001418 return ::lroundl(__x);
Ilya Tokarc3abffb2021-02-10 13:05:19 -05001419#endif
1420}
Richard Smith081bb592015-10-08 20:40:34 +00001421
1422template <class _A1>
Nikolas Klauser4956e722022-10-12 15:41:22 +02001423inline _LIBCPP_HIDE_FROM_ABI
Richard Smith081bb592015-10-08 20:40:34 +00001424typename std::enable_if<std::is_integral<_A1>::value, long>::type
Nikolas Klauser9806f452022-10-12 15:45:09 +02001425lround(_A1 __x) _NOEXCEPT
Ilya Tokarc3abffb2021-02-10 13:05:19 -05001426{
1427#if __has_builtin(__builtin_lround)
Nikolas Klauser9806f452022-10-12 15:45:09 +02001428 return __builtin_lround((double)__x);
Ilya Tokarc3abffb2021-02-10 13:05:19 -05001429#else
Nikolas Klauser9806f452022-10-12 15:45:09 +02001430 return ::lround((double)__x);
Ilya Tokarc3abffb2021-02-10 13:05:19 -05001431#endif
1432}
Richard Smith081bb592015-10-08 20:40:34 +00001433
1434// nan
1435
1436// nearbyint
1437
Nikolas Klauser9806f452022-10-12 15:45:09 +02001438inline _LIBCPP_HIDE_FROM_ABI float nearbyint(float __x) _NOEXCEPT {return ::nearbyintf(__x);}
1439inline _LIBCPP_HIDE_FROM_ABI long double nearbyint(long double __x) _NOEXCEPT {return ::nearbyintl(__x);}
Richard Smith081bb592015-10-08 20:40:34 +00001440
1441template <class _A1>
Nikolas Klauser4956e722022-10-12 15:41:22 +02001442inline _LIBCPP_HIDE_FROM_ABI
Richard Smith081bb592015-10-08 20:40:34 +00001443typename std::enable_if<std::is_integral<_A1>::value, double>::type
Nikolas Klauser9806f452022-10-12 15:45:09 +02001444nearbyint(_A1 __x) _NOEXCEPT {return ::nearbyint((double)__x);}
Richard Smith081bb592015-10-08 20:40:34 +00001445
1446// nextafter
1447
Nikolas Klauser9806f452022-10-12 15:45:09 +02001448inline _LIBCPP_HIDE_FROM_ABI float nextafter(float __x, float __y) _NOEXCEPT {return ::nextafterf(__x, __y);}
1449inline _LIBCPP_HIDE_FROM_ABI long double nextafter(long double __x, long double __y) _NOEXCEPT {return ::nextafterl(__x, __y);}
Richard Smith081bb592015-10-08 20:40:34 +00001450
1451template <class _A1, class _A2>
Nikolas Klauser4956e722022-10-12 15:41:22 +02001452inline _LIBCPP_HIDE_FROM_ABI
Louis Dionne9ce598d2021-09-08 09:14:43 -04001453typename std::__enable_if_t
Richard Smith081bb592015-10-08 20:40:34 +00001454<
1455 std::is_arithmetic<_A1>::value &&
1456 std::is_arithmetic<_A2>::value,
1457 std::__promote<_A1, _A2>
1458>::type
Nikolas Klauser9806f452022-10-12 15:45:09 +02001459nextafter(_A1 __x, _A2 __y) _NOEXCEPT
Richard Smith081bb592015-10-08 20:40:34 +00001460{
1461 typedef typename std::__promote<_A1, _A2>::type __result_type;
Eric Fiselier3906a132019-06-23 20:28:29 +00001462 static_assert((!(std::_IsSame<_A1, __result_type>::value &&
1463 std::_IsSame<_A2, __result_type>::value)), "");
Nikolas Klauser9806f452022-10-12 15:45:09 +02001464 return ::nextafter((__result_type)__x, (__result_type)__y);
Richard Smith081bb592015-10-08 20:40:34 +00001465}
1466
1467// nexttoward
1468
Nikolas Klauser9806f452022-10-12 15:45:09 +02001469inline _LIBCPP_HIDE_FROM_ABI float nexttoward(float __x, long double __y) _NOEXCEPT {return ::nexttowardf(__x, __y);}
1470inline _LIBCPP_HIDE_FROM_ABI long double nexttoward(long double __x, long double __y) _NOEXCEPT {return ::nexttowardl(__x, __y);}
Richard Smith081bb592015-10-08 20:40:34 +00001471
1472template <class _A1>
Nikolas Klauser4956e722022-10-12 15:41:22 +02001473inline _LIBCPP_HIDE_FROM_ABI
Richard Smith081bb592015-10-08 20:40:34 +00001474typename std::enable_if<std::is_integral<_A1>::value, double>::type
Nikolas Klauser9806f452022-10-12 15:45:09 +02001475nexttoward(_A1 __x, long double __y) _NOEXCEPT {return ::nexttoward((double)__x, __y);}
Richard Smith081bb592015-10-08 20:40:34 +00001476
1477// remainder
1478
Nikolas Klauser9806f452022-10-12 15:45:09 +02001479inline _LIBCPP_HIDE_FROM_ABI float remainder(float __x, float __y) _NOEXCEPT {return ::remainderf(__x, __y);}
1480inline _LIBCPP_HIDE_FROM_ABI long double remainder(long double __x, long double __y) _NOEXCEPT {return ::remainderl(__x, __y);}
Richard Smith081bb592015-10-08 20:40:34 +00001481
1482template <class _A1, class _A2>
Nikolas Klauser4956e722022-10-12 15:41:22 +02001483inline _LIBCPP_HIDE_FROM_ABI
Louis Dionne9ce598d2021-09-08 09:14:43 -04001484typename std::__enable_if_t
Richard Smith081bb592015-10-08 20:40:34 +00001485<
1486 std::is_arithmetic<_A1>::value &&
1487 std::is_arithmetic<_A2>::value,
1488 std::__promote<_A1, _A2>
1489>::type
Nikolas Klauser9806f452022-10-12 15:45:09 +02001490remainder(_A1 __x, _A2 __y) _NOEXCEPT
Richard Smith081bb592015-10-08 20:40:34 +00001491{
1492 typedef typename std::__promote<_A1, _A2>::type __result_type;
Eric Fiselier3906a132019-06-23 20:28:29 +00001493 static_assert((!(std::_IsSame<_A1, __result_type>::value &&
1494 std::_IsSame<_A2, __result_type>::value)), "");
Nikolas Klauser9806f452022-10-12 15:45:09 +02001495 return ::remainder((__result_type)__x, (__result_type)__y);
Richard Smith081bb592015-10-08 20:40:34 +00001496}
1497
1498// remquo
1499
Nikolas Klauser9806f452022-10-12 15:45:09 +02001500inline _LIBCPP_HIDE_FROM_ABI float remquo(float __x, float __y, int* __z) _NOEXCEPT {return ::remquof(__x, __y, __z);}
1501inline _LIBCPP_HIDE_FROM_ABI long double remquo(long double __x, long double __y, int* __z) _NOEXCEPT {return ::remquol(__x, __y, __z);}
Richard Smith081bb592015-10-08 20:40:34 +00001502
1503template <class _A1, class _A2>
Nikolas Klauser4956e722022-10-12 15:41:22 +02001504inline _LIBCPP_HIDE_FROM_ABI
Louis Dionne9ce598d2021-09-08 09:14:43 -04001505typename std::__enable_if_t
Richard Smith081bb592015-10-08 20:40:34 +00001506<
1507 std::is_arithmetic<_A1>::value &&
1508 std::is_arithmetic<_A2>::value,
1509 std::__promote<_A1, _A2>
1510>::type
Nikolas Klauser9806f452022-10-12 15:45:09 +02001511remquo(_A1 __x, _A2 __y, int* __z) _NOEXCEPT
Richard Smith081bb592015-10-08 20:40:34 +00001512{
1513 typedef typename std::__promote<_A1, _A2>::type __result_type;
Eric Fiselier3906a132019-06-23 20:28:29 +00001514 static_assert((!(std::_IsSame<_A1, __result_type>::value &&
1515 std::_IsSame<_A2, __result_type>::value)), "");
Nikolas Klauser9806f452022-10-12 15:45:09 +02001516 return ::remquo((__result_type)__x, (__result_type)__y, __z);
Richard Smith081bb592015-10-08 20:40:34 +00001517}
1518
1519// rint
1520
Nikolas Klauser9806f452022-10-12 15:45:09 +02001521inline _LIBCPP_HIDE_FROM_ABI float rint(float __x) _NOEXCEPT
Ilya Tokarc3abffb2021-02-10 13:05:19 -05001522{
1523#if __has_builtin(__builtin_rintf)
Nikolas Klauser9806f452022-10-12 15:45:09 +02001524 return __builtin_rintf(__x);
Ilya Tokarc3abffb2021-02-10 13:05:19 -05001525#else
Nikolas Klauser9806f452022-10-12 15:45:09 +02001526 return ::rintf(__x);
Ilya Tokarc3abffb2021-02-10 13:05:19 -05001527#endif
1528}
Nikolas Klauser9806f452022-10-12 15:45:09 +02001529inline _LIBCPP_HIDE_FROM_ABI long double rint(long double __x) _NOEXCEPT
Ilya Tokarc3abffb2021-02-10 13:05:19 -05001530{
1531#if __has_builtin(__builtin_rintl)
Nikolas Klauser9806f452022-10-12 15:45:09 +02001532 return __builtin_rintl(__x);
Ilya Tokarc3abffb2021-02-10 13:05:19 -05001533#else
Nikolas Klauser9806f452022-10-12 15:45:09 +02001534 return ::rintl(__x);
Ilya Tokarc3abffb2021-02-10 13:05:19 -05001535#endif
1536}
Richard Smith081bb592015-10-08 20:40:34 +00001537
1538template <class _A1>
Nikolas Klauser4956e722022-10-12 15:41:22 +02001539inline _LIBCPP_HIDE_FROM_ABI
Richard Smith081bb592015-10-08 20:40:34 +00001540typename std::enable_if<std::is_integral<_A1>::value, double>::type
Nikolas Klauser9806f452022-10-12 15:45:09 +02001541rint(_A1 __x) _NOEXCEPT
Ilya Tokarc3abffb2021-02-10 13:05:19 -05001542{
1543#if __has_builtin(__builtin_rint)
Nikolas Klauser9806f452022-10-12 15:45:09 +02001544 return __builtin_rint((double)__x);
Ilya Tokarc3abffb2021-02-10 13:05:19 -05001545#else
Nikolas Klauser9806f452022-10-12 15:45:09 +02001546 return ::rint((double)__x);
Ilya Tokarc3abffb2021-02-10 13:05:19 -05001547#endif
1548}
Richard Smith081bb592015-10-08 20:40:34 +00001549
1550// round
1551
Nikolas Klauser9806f452022-10-12 15:45:09 +02001552inline _LIBCPP_HIDE_FROM_ABI float round(float __x) _NOEXCEPT
Ilya Tokarc3abffb2021-02-10 13:05:19 -05001553{
1554#if __has_builtin(__builtin_round)
Nikolas Klauser9806f452022-10-12 15:45:09 +02001555 return __builtin_round(__x);
Ilya Tokarc3abffb2021-02-10 13:05:19 -05001556#else
Nikolas Klauser9806f452022-10-12 15:45:09 +02001557 return ::round(__x);
Ilya Tokarc3abffb2021-02-10 13:05:19 -05001558#endif
1559}
Nikolas Klauser9806f452022-10-12 15:45:09 +02001560inline _LIBCPP_HIDE_FROM_ABI long double round(long double __x) _NOEXCEPT
Ilya Tokarc3abffb2021-02-10 13:05:19 -05001561{
1562#if __has_builtin(__builtin_roundl)
Nikolas Klauser9806f452022-10-12 15:45:09 +02001563 return __builtin_roundl(__x);
Ilya Tokarc3abffb2021-02-10 13:05:19 -05001564#else
Nikolas Klauser9806f452022-10-12 15:45:09 +02001565 return ::roundl(__x);
Ilya Tokarc3abffb2021-02-10 13:05:19 -05001566#endif
1567}
Richard Smith081bb592015-10-08 20:40:34 +00001568
1569template <class _A1>
Nikolas Klauser4956e722022-10-12 15:41:22 +02001570inline _LIBCPP_HIDE_FROM_ABI
Richard Smith081bb592015-10-08 20:40:34 +00001571typename std::enable_if<std::is_integral<_A1>::value, double>::type
Nikolas Klauser9806f452022-10-12 15:45:09 +02001572round(_A1 __x) _NOEXCEPT
Ilya Tokarc3abffb2021-02-10 13:05:19 -05001573{
1574#if __has_builtin(__builtin_round)
Nikolas Klauser9806f452022-10-12 15:45:09 +02001575 return __builtin_round((double)__x);
Ilya Tokarc3abffb2021-02-10 13:05:19 -05001576#else
Nikolas Klauser9806f452022-10-12 15:45:09 +02001577 return ::round((double)__x);
Ilya Tokarc3abffb2021-02-10 13:05:19 -05001578#endif
1579}
Richard Smith081bb592015-10-08 20:40:34 +00001580
1581// scalbln
1582
Nikolas Klauser9806f452022-10-12 15:45:09 +02001583inline _LIBCPP_HIDE_FROM_ABI float scalbln(float __x, long __y) _NOEXCEPT {return ::scalblnf(__x, __y);}
1584inline _LIBCPP_HIDE_FROM_ABI long double scalbln(long double __x, long __y) _NOEXCEPT {return ::scalblnl(__x, __y);}
Richard Smith081bb592015-10-08 20:40:34 +00001585
1586template <class _A1>
Nikolas Klauser4956e722022-10-12 15:41:22 +02001587inline _LIBCPP_HIDE_FROM_ABI
Richard Smith081bb592015-10-08 20:40:34 +00001588typename std::enable_if<std::is_integral<_A1>::value, double>::type
Nikolas Klauser9806f452022-10-12 15:45:09 +02001589scalbln(_A1 __x, long __y) _NOEXCEPT {return ::scalbln((double)__x, __y);}
Richard Smith081bb592015-10-08 20:40:34 +00001590
1591// scalbn
1592
Nikolas Klauser9806f452022-10-12 15:45:09 +02001593inline _LIBCPP_HIDE_FROM_ABI float scalbn(float __x, int __y) _NOEXCEPT {return ::scalbnf(__x, __y);}
1594inline _LIBCPP_HIDE_FROM_ABI long double scalbn(long double __x, int __y) _NOEXCEPT {return ::scalbnl(__x, __y);}
Richard Smith081bb592015-10-08 20:40:34 +00001595
1596template <class _A1>
Nikolas Klauser4956e722022-10-12 15:41:22 +02001597inline _LIBCPP_HIDE_FROM_ABI
Richard Smith081bb592015-10-08 20:40:34 +00001598typename std::enable_if<std::is_integral<_A1>::value, double>::type
Nikolas Klauser9806f452022-10-12 15:45:09 +02001599scalbn(_A1 __x, int __y) _NOEXCEPT {return ::scalbn((double)__x, __y);}
Richard Smith081bb592015-10-08 20:40:34 +00001600
1601// tgamma
1602
Nikolas Klauser9806f452022-10-12 15:45:09 +02001603inline _LIBCPP_HIDE_FROM_ABI float tgamma(float __x) _NOEXCEPT {return ::tgammaf(__x);}
1604inline _LIBCPP_HIDE_FROM_ABI long double tgamma(long double __x) _NOEXCEPT {return ::tgammal(__x);}
Richard Smith081bb592015-10-08 20:40:34 +00001605
1606template <class _A1>
Nikolas Klauser4956e722022-10-12 15:41:22 +02001607inline _LIBCPP_HIDE_FROM_ABI
Richard Smith081bb592015-10-08 20:40:34 +00001608typename std::enable_if<std::is_integral<_A1>::value, double>::type
Nikolas Klauser9806f452022-10-12 15:45:09 +02001609tgamma(_A1 __x) _NOEXCEPT {return ::tgamma((double)__x);}
Richard Smith081bb592015-10-08 20:40:34 +00001610
1611// trunc
1612
Nikolas Klauser9806f452022-10-12 15:45:09 +02001613inline _LIBCPP_HIDE_FROM_ABI float trunc(float __x) _NOEXCEPT
Ilya Tokarc3abffb2021-02-10 13:05:19 -05001614{
1615#if __has_builtin(__builtin_trunc)
Nikolas Klauser9806f452022-10-12 15:45:09 +02001616 return __builtin_trunc(__x);
Ilya Tokarc3abffb2021-02-10 13:05:19 -05001617#else
Nikolas Klauser9806f452022-10-12 15:45:09 +02001618 return ::trunc(__x);
Ilya Tokarc3abffb2021-02-10 13:05:19 -05001619#endif
1620}
Nikolas Klauser9806f452022-10-12 15:45:09 +02001621inline _LIBCPP_HIDE_FROM_ABI long double trunc(long double __x) _NOEXCEPT
Ilya Tokarc3abffb2021-02-10 13:05:19 -05001622{
1623#if __has_builtin(__builtin_truncl)
Nikolas Klauser9806f452022-10-12 15:45:09 +02001624 return __builtin_truncl(__x);
Ilya Tokarc3abffb2021-02-10 13:05:19 -05001625#else
Nikolas Klauser9806f452022-10-12 15:45:09 +02001626 return ::truncl(__x);
Ilya Tokarc3abffb2021-02-10 13:05:19 -05001627#endif
1628}
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 +02001633trunc(_A1 __x) _NOEXCEPT
Ilya Tokarc3abffb2021-02-10 13:05:19 -05001634{
1635#if __has_builtin(__builtin_trunc)
Nikolas Klauser9806f452022-10-12 15:45:09 +02001636 return __builtin_trunc((double)__x);
Ilya Tokarc3abffb2021-02-10 13:05:19 -05001637#else
Nikolas Klauser9806f452022-10-12 15:45:09 +02001638 return ::trunc((double)__x);
Ilya Tokarc3abffb2021-02-10 13:05:19 -05001639#endif
1640}
Richard Smith081bb592015-10-08 20:40:34 +00001641
Richard Smith081bb592015-10-08 20:40:34 +00001642} // extern "C++"
1643
1644#endif // __cplusplus
1645
Mikhail Maltsev34b4f972018-02-22 09:34:08 +00001646#else // _LIBCPP_MATH_H
1647
1648// This include lives outside the header guard in order to support an MSVC
1649// extension which allows users to do:
1650//
1651// #define _USE_MATH_DEFINES
1652// #include <math.h>
1653//
1654// and receive the definitions of mathematical constants, even if <math.h>
1655// has previously been included.
1656#if defined(_LIBCPP_MSVCRT) && defined(_USE_MATH_DEFINES)
1657#include_next <math.h>
1658#endif
1659
Louis Dionne2b1ceaa2021-04-20 12:03:32 -04001660#endif // _LIBCPP_MATH_H