7 #if !defined(CNL_IMPL_CMATH_SQRT_H)
8 #define CNL_IMPL_CMATH_SQRT_H
10 #include "../../integer.h"
11 #include "../cnl_assert.h"
12 #include "../num_traits/digits.h"
24 template<
integer Integer>
25 [[nodiscard]] constexpr
auto sqrt(Integer
const& x)
27 CNL_ASSERT(x >= Integer{0});
29 auto root = +Integer{0};
30 auto bit = Integer{1} << ((digits_v<Integer> - 1) & ~1);
31 auto num = decltype(root + bit){x};
38 if (num >= root + bit) {
40 root = (root >> 1) + bit;
50 #endif // CNL_IMPL_CMATH_SQRT_H