2 //===----------------------------------------------------------------------===//
4 // 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
8 //===----------------------------------------------------------------------===//
35 math_errhandling // C99
47 floating_point abs(floating_point x);
49 floating_point acos (arithmetic x);
51 long double acosl(long double x);
53 floating_point asin (arithmetic x);
55 long double asinl(long double x);
57 floating_point atan (arithmetic x);
59 long double atanl(long double x);
61 floating_point atan2 (arithmetic y, arithmetic x);
62 float atan2f(float y, float x);
63 long double atan2l(long double y, long double x);
65 floating_point ceil (arithmetic x);
67 long double ceill(long double x);
69 floating_point cos (arithmetic x);
71 long double cosl(long double x);
73 floating_point cosh (arithmetic x);
75 long double coshl(long double x);
77 floating_point exp (arithmetic x);
79 long double expl(long double x);
81 floating_point fabs (arithmetic x);
83 long double fabsl(long double x);
85 floating_point floor (arithmetic x);
86 float floorf(float x);
87 long double floorl(long double x);
89 floating_point fmod (arithmetic x, arithmetic y);
90 float fmodf(float x, float y);
91 long double fmodl(long double x, long double y);
93 floating_point frexp (arithmetic value, int* exp);
94 float frexpf(float value, int* exp);
95 long double frexpl(long double value, int* exp);
97 floating_point ldexp (arithmetic value, int exp);
98 float ldexpf(float value, int exp);
99 long double ldexpl(long double value, int exp);
101 floating_point log (arithmetic x);
103 long double logl(long double x);
105 floating_point log10 (arithmetic x);
106 float log10f(float x);
107 long double log10l(long double x);
109 floating_point modf (floating_point value, floating_point* iptr);
110 float modff(float value, float* iptr);
111 long double modfl(long double value, long double* iptr);
113 floating_point pow (arithmetic x, arithmetic y);
114 float powf(float x, float y);
115 long double powl(long double x, long double y);
117 floating_point sin (arithmetic x);
119 long double sinl(long double x);
121 floating_point sinh (arithmetic x);
122 float sinhf(float x);
123 long double sinhl(long double x);
125 floating_point sqrt (arithmetic x);
126 float sqrtf(float x);
127 long double sqrtl(long double x);
129 floating_point tan (arithmetic x);
131 long double tanl(long double x);
133 floating_point tanh (arithmetic x);
134 float tanhf(float x);
135 long double tanhl(long double x);
139 bool signbit(arithmetic x);
141 int fpclassify(arithmetic x);
143 bool isfinite(arithmetic x);
144 bool isinf(arithmetic x);
145 bool isnan(arithmetic x);
146 bool isnormal(arithmetic x);
148 bool isgreater(arithmetic x, arithmetic y);
149 bool isgreaterequal(arithmetic x, arithmetic y);
150 bool isless(arithmetic x, arithmetic y);
151 bool islessequal(arithmetic x, arithmetic y);
152 bool islessgreater(arithmetic x, arithmetic y);
153 bool isunordered(arithmetic x, arithmetic y);
155 floating_point acosh (arithmetic x);
156 float acoshf(float x);
157 long double acoshl(long double x);
159 floating_point asinh (arithmetic x);
160 float asinhf(float x);
161 long double asinhl(long double x);
163 floating_point atanh (arithmetic x);
164 float atanhf(float x);
165 long double atanhl(long double x);
167 floating_point cbrt (arithmetic x);
168 float cbrtf(float x);
169 long double cbrtl(long double x);
171 floating_point copysign (arithmetic x, arithmetic y);
172 float copysignf(float x, float y);
173 long double copysignl(long double x, long double y);
175 floating_point erf (arithmetic x);
177 long double erfl(long double x);
179 floating_point erfc (arithmetic x);
180 float erfcf(float x);
181 long double erfcl(long double x);
183 floating_point exp2 (arithmetic x);
184 float exp2f(float x);
185 long double exp2l(long double x);
187 floating_point expm1 (arithmetic x);
188 float expm1f(float x);
189 long double expm1l(long double x);
191 floating_point fdim (arithmetic x, arithmetic y);
192 float fdimf(float x, float y);
193 long double fdiml(long double x, long double y);
195 floating_point fma (arithmetic x, arithmetic y, arithmetic z);
196 float fmaf(float x, float y, float z);
197 long double fmal(long double x, long double y, long double z);
199 floating_point fmax (arithmetic x, arithmetic y);
200 float fmaxf(float x, float y);
201 long double fmaxl(long double x, long double y);
203 floating_point fmin (arithmetic x, arithmetic y);
204 float fminf(float x, float y);
205 long double fminl(long double x, long double y);
207 floating_point hypot (arithmetic x, arithmetic y);
208 float hypotf(float x, float y);
209 long double hypotl(long double x, long double y);
211 double hypot(double x, double y, double z); // C++17
212 float hypot(float x, float y, float z); // C++17
213 long double hypot(long double x, long double y, long double z); // C++17
215 int ilogb (arithmetic x);
217 int ilogbl(long double x);
219 floating_point lgamma (arithmetic x);
220 float lgammaf(float x);
221 long double lgammal(long double x);
223 long long llrint (arithmetic x);
224 long long llrintf(float x);
225 long long llrintl(long double x);
227 long long llround (arithmetic x);
228 long long llroundf(float x);
229 long long llroundl(long double x);
231 floating_point log1p (arithmetic x);
232 float log1pf(float x);
233 long double log1pl(long double x);
235 floating_point log2 (arithmetic x);
236 float log2f(float x);
237 long double log2l(long double x);
239 floating_point logb (arithmetic x);
240 float logbf(float x);
241 long double logbl(long double x);
243 long lrint (arithmetic x);
244 long lrintf(float x);
245 long lrintl(long double x);
247 long lround (arithmetic x);
248 long lroundf(float x);
249 long lroundl(long double x);
251 double nan (const char* str);
252 float nanf(const char* str);
253 long double nanl(const char* str);
255 floating_point nearbyint (arithmetic x);
256 float nearbyintf(float x);
257 long double nearbyintl(long double x);
259 floating_point nextafter (arithmetic x, arithmetic y);
260 float nextafterf(float x, float y);
261 long double nextafterl(long double x, long double y);
263 floating_point nexttoward (arithmetic x, long double y);
264 float nexttowardf(float x, long double y);
265 long double nexttowardl(long double x, long double y);
267 floating_point remainder (arithmetic x, arithmetic y);
268 float remainderf(float x, float y);
269 long double remainderl(long double x, long double y);
271 floating_point remquo (arithmetic x, arithmetic y, int* pquo);
272 float remquof(float x, float y, int* pquo);
273 long double remquol(long double x, long double y, int* pquo);
275 floating_point rint (arithmetic x);
276 float rintf(float x);
277 long double rintl(long double x);
279 floating_point round (arithmetic x);
280 float roundf(float x);
281 long double roundl(long double x);
283 floating_point scalbln (arithmetic x, long ex);
284 float scalblnf(float x, long ex);
285 long double scalblnl(long double x, long ex);
287 floating_point scalbn (arithmetic x, int ex);
288 float scalbnf(float x, int ex);
289 long double scalbnl(long double x, int ex);
291 floating_point tgamma (arithmetic x);
292 float tgammaf(float x);
293 long double tgammal(long double x);
295 floating_point trunc (arithmetic x);
296 float truncf(float x);
297 long double truncl(long double x);
299 constexpr float lerp(float a, float b, float t) noexcept; // C++20
300 constexpr double lerp(double a, double b, double t) noexcept; // C++20
301 constexpr long double lerp(long double a, long double b, long double t) noexcept; // C++20
307 #include <__assert> // all public C++ headers provide the assertion handler
309 #include <__type_traits/enable_if.h>
310 #include <__type_traits/is_arithmetic.h>
311 #include <__type_traits/is_constant_evaluated.h>
312 #include <__type_traits/is_floating_point.h>
313 #include <__type_traits/is_same.h>
314 #include <__type_traits/promote.h>
315 #include <__type_traits/remove_cv.h>
321 #ifndef _LIBCPP_MATH_H
322 # error <cmath> tried including <math.h> but didn't find libc++'s <math.h> header. \
323 This usually means that your header search paths are not configured properly. \
324 The header search paths should contain the C++ Standard Library headers before \
325 any C Standard Library, and you are probably using compiler flags that make that \
329 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
330 # pragma GCC system_header
334 #include <__undef_macros>
336 _LIBCPP_BEGIN_NAMESPACE_STD
338 using ::signbit _LIBCPP_USING_IF_EXISTS;
339 using ::fpclassify _LIBCPP_USING_IF_EXISTS;
340 using ::isfinite _LIBCPP_USING_IF_EXISTS;
341 using ::isinf _LIBCPP_USING_IF_EXISTS;
342 using ::isnan _LIBCPP_USING_IF_EXISTS;
343 using ::isnormal _LIBCPP_USING_IF_EXISTS;
344 using ::isgreater _LIBCPP_USING_IF_EXISTS;
345 using ::isgreaterequal _LIBCPP_USING_IF_EXISTS;
346 using ::isless _LIBCPP_USING_IF_EXISTS;
347 using ::islessequal _LIBCPP_USING_IF_EXISTS;
348 using ::islessgreater _LIBCPP_USING_IF_EXISTS;
349 using ::isunordered _LIBCPP_USING_IF_EXISTS;
350 using ::isunordered _LIBCPP_USING_IF_EXISTS;
352 using ::float_t _LIBCPP_USING_IF_EXISTS;
353 using ::double_t _LIBCPP_USING_IF_EXISTS;
355 using ::abs _LIBCPP_USING_IF_EXISTS;
357 using ::acos _LIBCPP_USING_IF_EXISTS;
358 using ::acosf _LIBCPP_USING_IF_EXISTS;
359 using ::asin _LIBCPP_USING_IF_EXISTS;
360 using ::asinf _LIBCPP_USING_IF_EXISTS;
361 using ::atan _LIBCPP_USING_IF_EXISTS;
362 using ::atanf _LIBCPP_USING_IF_EXISTS;
363 using ::atan2 _LIBCPP_USING_IF_EXISTS;
364 using ::atan2f _LIBCPP_USING_IF_EXISTS;
365 using ::ceil _LIBCPP_USING_IF_EXISTS;
366 using ::ceilf _LIBCPP_USING_IF_EXISTS;
367 using ::cos _LIBCPP_USING_IF_EXISTS;
368 using ::cosf _LIBCPP_USING_IF_EXISTS;
369 using ::cosh _LIBCPP_USING_IF_EXISTS;
370 using ::coshf _LIBCPP_USING_IF_EXISTS;
372 using ::exp _LIBCPP_USING_IF_EXISTS;
373 using ::expf _LIBCPP_USING_IF_EXISTS;
375 using ::fabs _LIBCPP_USING_IF_EXISTS;
376 using ::fabsf _LIBCPP_USING_IF_EXISTS;
377 using ::floor _LIBCPP_USING_IF_EXISTS;
378 using ::floorf _LIBCPP_USING_IF_EXISTS;
380 using ::fmod _LIBCPP_USING_IF_EXISTS;
381 using ::fmodf _LIBCPP_USING_IF_EXISTS;
383 using ::frexp _LIBCPP_USING_IF_EXISTS;
384 using ::frexpf _LIBCPP_USING_IF_EXISTS;
385 using ::ldexp _LIBCPP_USING_IF_EXISTS;
386 using ::ldexpf _LIBCPP_USING_IF_EXISTS;
388 using ::log _LIBCPP_USING_IF_EXISTS;
389 using ::logf _LIBCPP_USING_IF_EXISTS;
391 using ::log10 _LIBCPP_USING_IF_EXISTS;
392 using ::log10f _LIBCPP_USING_IF_EXISTS;
393 using ::modf _LIBCPP_USING_IF_EXISTS;
394 using ::modff _LIBCPP_USING_IF_EXISTS;
396 using ::pow _LIBCPP_USING_IF_EXISTS;
397 using ::powf _LIBCPP_USING_IF_EXISTS;
399 using ::sin _LIBCPP_USING_IF_EXISTS;
400 using ::sinf _LIBCPP_USING_IF_EXISTS;
401 using ::sinh _LIBCPP_USING_IF_EXISTS;
402 using ::sinhf _LIBCPP_USING_IF_EXISTS;
404 using ::sqrt _LIBCPP_USING_IF_EXISTS;
405 using ::sqrtf _LIBCPP_USING_IF_EXISTS;
406 using ::tan _LIBCPP_USING_IF_EXISTS;
407 using ::tanf _LIBCPP_USING_IF_EXISTS;
409 using ::tanh _LIBCPP_USING_IF_EXISTS;
410 using ::tanhf _LIBCPP_USING_IF_EXISTS;
412 using ::acosh _LIBCPP_USING_IF_EXISTS;
413 using ::acoshf _LIBCPP_USING_IF_EXISTS;
414 using ::asinh _LIBCPP_USING_IF_EXISTS;
415 using ::asinhf _LIBCPP_USING_IF_EXISTS;
416 using ::atanh _LIBCPP_USING_IF_EXISTS;
417 using ::atanhf _LIBCPP_USING_IF_EXISTS;
418 using ::cbrt _LIBCPP_USING_IF_EXISTS;
419 using ::cbrtf _LIBCPP_USING_IF_EXISTS;
421 using ::copysign _LIBCPP_USING_IF_EXISTS;
422 using ::copysignf _LIBCPP_USING_IF_EXISTS;
424 using ::erf _LIBCPP_USING_IF_EXISTS;
425 using ::erff _LIBCPP_USING_IF_EXISTS;
426 using ::erfc _LIBCPP_USING_IF_EXISTS;
427 using ::erfcf _LIBCPP_USING_IF_EXISTS;
428 using ::exp2 _LIBCPP_USING_IF_EXISTS;
429 using ::exp2f _LIBCPP_USING_IF_EXISTS;
430 using ::expm1 _LIBCPP_USING_IF_EXISTS;
431 using ::expm1f _LIBCPP_USING_IF_EXISTS;
432 using ::fdim _LIBCPP_USING_IF_EXISTS;
433 using ::fdimf _LIBCPP_USING_IF_EXISTS;
434 using ::fmaf _LIBCPP_USING_IF_EXISTS;
435 using ::fma _LIBCPP_USING_IF_EXISTS;
436 using ::fmax _LIBCPP_USING_IF_EXISTS;
437 using ::fmaxf _LIBCPP_USING_IF_EXISTS;
438 using ::fmin _LIBCPP_USING_IF_EXISTS;
439 using ::fminf _LIBCPP_USING_IF_EXISTS;
440 using ::hypot _LIBCPP_USING_IF_EXISTS;
441 using ::hypotf _LIBCPP_USING_IF_EXISTS;
442 using ::ilogb _LIBCPP_USING_IF_EXISTS;
443 using ::ilogbf _LIBCPP_USING_IF_EXISTS;
444 using ::lgamma _LIBCPP_USING_IF_EXISTS;
445 using ::lgammaf _LIBCPP_USING_IF_EXISTS;
446 using ::llrint _LIBCPP_USING_IF_EXISTS;
447 using ::llrintf _LIBCPP_USING_IF_EXISTS;
448 using ::llround _LIBCPP_USING_IF_EXISTS;
449 using ::llroundf _LIBCPP_USING_IF_EXISTS;
450 using ::log1p _LIBCPP_USING_IF_EXISTS;
451 using ::log1pf _LIBCPP_USING_IF_EXISTS;
452 using ::log2 _LIBCPP_USING_IF_EXISTS;
453 using ::log2f _LIBCPP_USING_IF_EXISTS;
454 using ::logb _LIBCPP_USING_IF_EXISTS;
455 using ::logbf _LIBCPP_USING_IF_EXISTS;
456 using ::lrint _LIBCPP_USING_IF_EXISTS;
457 using ::lrintf _LIBCPP_USING_IF_EXISTS;
458 using ::lround _LIBCPP_USING_IF_EXISTS;
459 using ::lroundf _LIBCPP_USING_IF_EXISTS;
461 using ::nan _LIBCPP_USING_IF_EXISTS;
462 using ::nanf _LIBCPP_USING_IF_EXISTS;
464 using ::nearbyint _LIBCPP_USING_IF_EXISTS;
465 using ::nearbyintf _LIBCPP_USING_IF_EXISTS;
466 using ::nextafter _LIBCPP_USING_IF_EXISTS;
467 using ::nextafterf _LIBCPP_USING_IF_EXISTS;
468 using ::nexttoward _LIBCPP_USING_IF_EXISTS;
469 using ::nexttowardf _LIBCPP_USING_IF_EXISTS;
470 using ::remainder _LIBCPP_USING_IF_EXISTS;
471 using ::remainderf _LIBCPP_USING_IF_EXISTS;
472 using ::remquo _LIBCPP_USING_IF_EXISTS;
473 using ::remquof _LIBCPP_USING_IF_EXISTS;
474 using ::rint _LIBCPP_USING_IF_EXISTS;
475 using ::rintf _LIBCPP_USING_IF_EXISTS;
476 using ::round _LIBCPP_USING_IF_EXISTS;
477 using ::roundf _LIBCPP_USING_IF_EXISTS;
478 using ::scalbln _LIBCPP_USING_IF_EXISTS;
479 using ::scalblnf _LIBCPP_USING_IF_EXISTS;
480 using ::scalbn _LIBCPP_USING_IF_EXISTS;
481 using ::scalbnf _LIBCPP_USING_IF_EXISTS;
482 using ::tgamma _LIBCPP_USING_IF_EXISTS;
483 using ::tgammaf _LIBCPP_USING_IF_EXISTS;
484 using ::trunc _LIBCPP_USING_IF_EXISTS;
485 using ::truncf _LIBCPP_USING_IF_EXISTS;
487 using ::acosl _LIBCPP_USING_IF_EXISTS;
488 using ::asinl _LIBCPP_USING_IF_EXISTS;
489 using ::atanl _LIBCPP_USING_IF_EXISTS;
490 using ::atan2l _LIBCPP_USING_IF_EXISTS;
491 using ::ceill _LIBCPP_USING_IF_EXISTS;
492 using ::cosl _LIBCPP_USING_IF_EXISTS;
493 using ::coshl _LIBCPP_USING_IF_EXISTS;
494 using ::expl _LIBCPP_USING_IF_EXISTS;
495 using ::fabsl _LIBCPP_USING_IF_EXISTS;
496 using ::floorl _LIBCPP_USING_IF_EXISTS;
497 using ::fmodl _LIBCPP_USING_IF_EXISTS;
498 using ::frexpl _LIBCPP_USING_IF_EXISTS;
499 using ::ldexpl _LIBCPP_USING_IF_EXISTS;
500 using ::logl _LIBCPP_USING_IF_EXISTS;
501 using ::log10l _LIBCPP_USING_IF_EXISTS;
502 using ::modfl _LIBCPP_USING_IF_EXISTS;
503 using ::powl _LIBCPP_USING_IF_EXISTS;
504 using ::sinl _LIBCPP_USING_IF_EXISTS;
505 using ::sinhl _LIBCPP_USING_IF_EXISTS;
506 using ::sqrtl _LIBCPP_USING_IF_EXISTS;
507 using ::tanl _LIBCPP_USING_IF_EXISTS;
509 using ::tanhl _LIBCPP_USING_IF_EXISTS;
510 using ::acoshl _LIBCPP_USING_IF_EXISTS;
511 using ::asinhl _LIBCPP_USING_IF_EXISTS;
512 using ::atanhl _LIBCPP_USING_IF_EXISTS;
513 using ::cbrtl _LIBCPP_USING_IF_EXISTS;
515 using ::copysignl _LIBCPP_USING_IF_EXISTS;
517 using ::erfl _LIBCPP_USING_IF_EXISTS;
518 using ::erfcl _LIBCPP_USING_IF_EXISTS;
519 using ::exp2l _LIBCPP_USING_IF_EXISTS;
520 using ::expm1l _LIBCPP_USING_IF_EXISTS;
521 using ::fdiml _LIBCPP_USING_IF_EXISTS;
522 using ::fmal _LIBCPP_USING_IF_EXISTS;
523 using ::fmaxl _LIBCPP_USING_IF_EXISTS;
524 using ::fminl _LIBCPP_USING_IF_EXISTS;
525 using ::hypotl _LIBCPP_USING_IF_EXISTS;
526 using ::ilogbl _LIBCPP_USING_IF_EXISTS;
527 using ::lgammal _LIBCPP_USING_IF_EXISTS;
528 using ::llrintl _LIBCPP_USING_IF_EXISTS;
529 using ::llroundl _LIBCPP_USING_IF_EXISTS;
530 using ::log1pl _LIBCPP_USING_IF_EXISTS;
531 using ::log2l _LIBCPP_USING_IF_EXISTS;
532 using ::logbl _LIBCPP_USING_IF_EXISTS;
533 using ::lrintl _LIBCPP_USING_IF_EXISTS;
534 using ::lroundl _LIBCPP_USING_IF_EXISTS;
535 using ::nanl _LIBCPP_USING_IF_EXISTS;
536 using ::nearbyintl _LIBCPP_USING_IF_EXISTS;
537 using ::nextafterl _LIBCPP_USING_IF_EXISTS;
538 using ::nexttowardl _LIBCPP_USING_IF_EXISTS;
539 using ::remainderl _LIBCPP_USING_IF_EXISTS;
540 using ::remquol _LIBCPP_USING_IF_EXISTS;
541 using ::rintl _LIBCPP_USING_IF_EXISTS;
542 using ::roundl _LIBCPP_USING_IF_EXISTS;
543 using ::scalblnl _LIBCPP_USING_IF_EXISTS;
544 using ::scalbnl _LIBCPP_USING_IF_EXISTS;
545 using ::tgammal _LIBCPP_USING_IF_EXISTS;
546 using ::truncl _LIBCPP_USING_IF_EXISTS;
548 #if _LIBCPP_STD_VER >= 17
549 inline _LIBCPP_INLINE_VISIBILITY float hypot( float __x, float __y, float __z ) { return sqrt(__x*__x + __y*__y + __z*__z); }
550 inline _LIBCPP_INLINE_VISIBILITY double hypot( double __x, double __y, double __z ) { return sqrt(__x*__x + __y*__y + __z*__z); }
551 inline _LIBCPP_INLINE_VISIBILITY long double hypot( long double __x, long double __y, long double __z ) { return sqrt(__x*__x + __y*__y + __z*__z); }
553 template <class _A1, class _A2, class _A3>
554 inline _LIBCPP_INLINE_VISIBILITY
557 is_arithmetic<_A1>::value &&
558 is_arithmetic<_A2>::value &&
559 is_arithmetic<_A3>::value,
560 __promote<_A1, _A2, _A3>
562 hypot(_A1 __lcpp_x, _A2 __lcpp_y, _A3 __lcpp_z) _NOEXCEPT
564 typedef typename __promote<_A1, _A2, _A3>::type __result_type;
565 static_assert((!(is_same<_A1, __result_type>::value &&
566 is_same<_A2, __result_type>::value &&
567 is_same<_A3, __result_type>::value)), "");
568 return std::hypot((__result_type)__lcpp_x, (__result_type)__lcpp_y, (__result_type)__lcpp_z);
573 _LIBCPP_INLINE_VISIBILITY
574 _LIBCPP_CONSTEXPR typename enable_if<is_floating_point<_A1>::value, bool>::type
575 __constexpr_isnan(_A1 __lcpp_x) _NOEXCEPT
577 #if __has_builtin(__builtin_isnan)
578 return __builtin_isnan(__lcpp_x);
580 return isnan(__lcpp_x);
585 _LIBCPP_INLINE_VISIBILITY
586 _LIBCPP_CONSTEXPR typename enable_if<!is_floating_point<_A1>::value, bool>::type
587 __constexpr_isnan(_A1 __lcpp_x) _NOEXCEPT
589 return std::isnan(__lcpp_x);
593 _LIBCPP_INLINE_VISIBILITY
594 _LIBCPP_CONSTEXPR typename enable_if<is_floating_point<_A1>::value, bool>::type
595 __constexpr_isinf(_A1 __lcpp_x) _NOEXCEPT
597 #if __has_builtin(__builtin_isinf)
598 return __builtin_isinf(__lcpp_x);
600 return isinf(__lcpp_x);
605 _LIBCPP_INLINE_VISIBILITY
606 _LIBCPP_CONSTEXPR typename enable_if<!is_floating_point<_A1>::value, bool>::type
607 __constexpr_isinf(_A1 __lcpp_x) _NOEXCEPT
609 return std::isinf(__lcpp_x);
613 _LIBCPP_INLINE_VISIBILITY
614 _LIBCPP_CONSTEXPR typename enable_if<is_floating_point<_A1>::value, bool>::type
615 __constexpr_isfinite(_A1 __lcpp_x) _NOEXCEPT
617 #if __has_builtin(__builtin_isfinite)
618 return __builtin_isfinite(__lcpp_x);
620 return isfinite(__lcpp_x);
625 _LIBCPP_INLINE_VISIBILITY
626 _LIBCPP_CONSTEXPR typename enable_if<!is_floating_point<_A1>::value, bool>::type
627 __constexpr_isfinite(_A1 __lcpp_x) _NOEXCEPT
629 return __builtin_isfinite(__lcpp_x);
632 _LIBCPP_CONSTEXPR inline _LIBCPP_HIDE_FROM_ABI float __constexpr_copysign(float __x, float __y) _NOEXCEPT {
633 return __builtin_copysignf(__x, __y);
636 _LIBCPP_CONSTEXPR inline _LIBCPP_HIDE_FROM_ABI double __constexpr_copysign(double __x, double __y) _NOEXCEPT {
637 return __builtin_copysign(__x, __y);
640 _LIBCPP_CONSTEXPR inline _LIBCPP_HIDE_FROM_ABI long double
641 __constexpr_copysign(long double __x, long double __y) _NOEXCEPT {
642 return __builtin_copysignl(__x, __y);
645 template <class _A1, class _A2>
646 _LIBCPP_CONSTEXPR inline _LIBCPP_HIDE_FROM_ABI
647 typename std::__enable_if_t<std::is_arithmetic<_A1>::value && std::is_arithmetic<_A2>::value,
648 std::__promote<_A1, _A2> >::type
649 __constexpr_copysign(_A1 __x, _A2 __y) _NOEXCEPT {
650 typedef typename std::__promote<_A1, _A2>::type __result_type;
651 static_assert((!(std::_IsSame<_A1, __result_type>::value && std::_IsSame<_A2, __result_type>::value)), "");
652 return __builtin_copysign((__result_type)__x, (__result_type)__y);
655 inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR float __constexpr_fabs(float __x) _NOEXCEPT {
656 return __builtin_fabsf(__x);
659 inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR double __constexpr_fabs(double __x) _NOEXCEPT {
660 return __builtin_fabs(__x);
663 inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR long double __constexpr_fabs(long double __x) _NOEXCEPT {
664 return __builtin_fabsl(__x);
667 template <class _Tp, __enable_if_t<is_integral<_Tp>::value, int> = 0>
668 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR double __constexpr_fabs(_Tp __x) _NOEXCEPT {
669 return __builtin_fabs(static_cast<double>(__x));
672 inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 float __constexpr_fmax(float __x, float __y) _NOEXCEPT {
673 #if !__has_constexpr_builtin(__builtin_fmaxf)
674 if (__libcpp_is_constant_evaluated()) {
675 if (std::__constexpr_isnan(__x))
677 if (std::__constexpr_isnan(__y))
679 return __x < __y ? __y : __x;
682 return __builtin_fmaxf(__x, __y);
685 inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 double __constexpr_fmax(double __x, double __y) _NOEXCEPT {
686 #if !__has_constexpr_builtin(__builtin_fmax)
687 if (__libcpp_is_constant_evaluated()) {
688 if (std::__constexpr_isnan(__x))
690 if (std::__constexpr_isnan(__y))
692 return __x < __y ? __y : __x;
695 return __builtin_fmax(__x, __y);
698 inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 long double
699 __constexpr_fmax(long double __x, long double __y) _NOEXCEPT {
700 #if !__has_constexpr_builtin(__builtin_fmaxl)
701 if (__libcpp_is_constant_evaluated()) {
702 if (std::__constexpr_isnan(__x))
704 if (std::__constexpr_isnan(__y))
706 return __x < __y ? __y : __x;
709 return __builtin_fmaxl(__x, __y);
712 template <class _Tp, class _Up, __enable_if_t<is_arithmetic<_Tp>::value && is_arithmetic<_Up>::value, int> = 0>
713 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 typename __promote<_Tp, _Up>::type
714 __constexpr_fmax(_Tp __x, _Up __y) _NOEXCEPT {
715 using __result_type = typename __promote<_Tp, _Up>::type;
716 return std::__constexpr_fmax(static_cast<__result_type>(__x), static_cast<__result_type>(__y));
720 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _Tp __constexpr_logb(_Tp __x) {
721 #if !__has_constexpr_builtin(__builtin_logb)
722 if (__libcpp_is_constant_evaluated()) {
724 // raise FE_DIVBYZERO
725 return -numeric_limits<_Tp>::infinity();
728 if (std::__constexpr_isinf(__x))
729 return numeric_limits<_Tp>::infinity();
731 if (std::__constexpr_isnan(__x))
732 return numeric_limits<_Tp>::quiet_NaN();
734 __x = std::__constexpr_fabs(__x);
735 unsigned long long __exp = 0;
736 while (__x >= numeric_limits<_Tp>::radix) {
737 __x /= numeric_limits<_Tp>::radix;
742 #endif // !__has_constexpr_builtin(__builtin_logb)
743 return __builtin_logb(__x);
747 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _Tp __constexpr_scalbn(_Tp __x, int __exp) {
748 #if !__has_constexpr_builtin(__builtin_scalbln)
749 if (__libcpp_is_constant_evaluated()) {
753 if (std::__constexpr_isinf(__x))
759 if (std::__constexpr_isnan(__x))
760 return numeric_limits<_Tp>::quiet_NaN();
764 __mult = numeric_limits<_Tp>::radix;
769 __mult /= numeric_limits<_Tp>::radix;
783 #endif // !__has_constexpr_builtin(__builtin_scalbln)
784 return __builtin_scalbn(__x, __exp);
787 #if _LIBCPP_STD_VER >= 20
788 template <typename _Fp>
789 _LIBCPP_HIDE_FROM_ABI constexpr
790 _Fp __lerp(_Fp __a, _Fp __b, _Fp __t) noexcept {
791 if ((__a <= 0 && __b >= 0) || (__a >= 0 && __b <= 0))
792 return __t * __b + (1 - __t) * __a;
794 if (__t == 1) return __b;
795 const _Fp __x = __a + __t * (__b - __a);
796 if ((__t > 1) == (__b > __a))
797 return __b < __x ? __x : __b;
799 return __x < __b ? __x : __b;
802 _LIBCPP_HIDE_FROM_ABI constexpr float
803 lerp(float __a, float __b, float __t) _NOEXCEPT { return __lerp(__a, __b, __t); }
805 _LIBCPP_HIDE_FROM_ABI constexpr double
806 lerp(double __a, double __b, double __t) _NOEXCEPT { return __lerp(__a, __b, __t); }
808 _LIBCPP_HIDE_FROM_ABI constexpr long double
809 lerp(long double __a, long double __b, long double __t) _NOEXCEPT { return __lerp(__a, __b, __t); }
811 template <class _A1, class _A2, class _A3>
812 inline _LIBCPP_HIDE_FROM_ABI
813 constexpr typename enable_if_t
815 is_arithmetic<_A1>::value &&
816 is_arithmetic<_A2>::value &&
817 is_arithmetic<_A3>::value,
818 __promote<_A1, _A2, _A3>
820 lerp(_A1 __a, _A2 __b, _A3 __t) noexcept
822 typedef typename __promote<_A1, _A2, _A3>::type __result_type;
823 static_assert(!(_IsSame<_A1, __result_type>::value &&
824 _IsSame<_A2, __result_type>::value &&
825 _IsSame<_A3, __result_type>::value));
826 return std::__lerp((__result_type)__a, (__result_type)__b, (__result_type)__t);
828 #endif // _LIBCPP_STD_VER >= 20
830 _LIBCPP_END_NAMESPACE_STD
834 #if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
835 # include <type_traits>
838 #endif // _LIBCPP_CMATH