34#ifndef _GLIBCXX_EXPERIMENTAL_NUMERIC
35#define _GLIBCXX_EXPERIMENTAL_NUMERIC 1
37#pragma GCC system_header
39#if __cplusplus >= 201402L
44namespace std _GLIBCXX_VISIBILITY(default)
46_GLIBCXX_BEGIN_NAMESPACE_VERSION
50inline namespace fundamentals_v2
52#define __cpp_lib_experimental_gcd_lcm 201411
55 template<
typename _Mn,
typename _Nn>
56 constexpr common_type_t<_Mn, _Nn>
57 gcd(_Mn __m, _Nn __n)
noexcept
59 static_assert(is_integral_v<_Mn> && is_integral_v<_Nn>,
60 "std::experimental::gcd arguments must be integers");
61 static_assert(_Mn(2) == 2 && _Nn(2) == 2,
62 "std::experimental::gcd arguments must not be bool");
65 const _Ct __m2 = __detail::__abs_r<_Ct>(__m);
66 const _Ct __n2 = __detail::__abs_r<_Ct>(__n);
67 return __detail::__gcd<make_unsigned_t<_Ct>>(__m2, __n2);
71 template<
typename _Mn,
typename _Nn>
75 static_assert(is_integral_v<_Mn> && is_integral_v<_Nn>,
76 "std::experimental::lcm arguments must be integers");
77 static_assert(_Mn(2) == 2 && _Nn(2) == 2,
78 "std::experimental::lcm arguments must not be bool");
81 const _Ct __m2 = __detail::__abs_r<_Ct>(__m);
82 const _Ct __n2 = __detail::__abs_r<_Ct>(__n);
83 if (__m2 == 0 || __n2 == 0)
85 _Ct __r = __m2 / __detail::__gcd<make_unsigned_t<_Ct>>(__m2, __n2);
87 if _GLIBCXX17_CONSTEXPR (is_signed_v<_Ct>)
88 if (__is_constant_evaluated())
91 bool __overflow = __builtin_mul_overflow(__r, __n2, &__r);
92 __glibcxx_assert(!__overflow);
98_GLIBCXX_END_NAMESPACE_VERSION
typename common_type< _Tp... >::type common_type_t
Alias template for common_type.
ISO C++ entities toplevel namespace is std.
constexpr common_type_t< _Mn, _Nn > lcm(_Mn __m, _Nn __n) noexcept
Least common multiple.
constexpr common_type_t< _Mn, _Nn > gcd(_Mn __m, _Nn __n) noexcept
Greatest common divisor.
Implementation details not part of the namespace std interface.
Parallel STL function calls corresponding to stl_numeric.h. The functions defined here mainly do case...