cMHN 1.1
C++ library for learning MHNs with pRC
Loading...
Searching...
No Matches
isqrt.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: BSD-2-Clause
2
3#ifndef pRC_CORE_BASIC_FUNCTIONS_ISQRT_H
4#define pRC_CORE_BASIC_FUNCTIONS_ISQRT_H
5
8
9namespace pRC
10{
11 template<class T, If<IsUnsignedIntegral<T>> = 0>
12 static inline constexpr T iSqrt(T const a)
13 {
14 return RecursiveLambda(
15 [&a](auto const &self, T const low, T const high)
16 {
17 if(low == high)
18 {
19 return low;
20 }
21 else
22 {
23 auto const mid = (low + high + T(1)) / T(2);
24
25 if(a / mid < mid)
26 return self(low, mid - T(1));
27 else
28 return self(mid, high);
29 }
30 })(T(0), a / T(2) + T(1));
31 }
32}
33#endif // pRC_CORE_BASIC_FUNCTIONS_ISQRT_H
pRC::Float<> T
Definition externs_nonTT.hpp:1
Definition cholesky.hpp:18
static constexpr auto makeConstantSequence()
Definition sequence.hpp:402
static constexpr T iSqrt(T const a)
Definition isqrt.hpp:12
RecursiveLambda(X &&) -> RecursiveLambda< RemoveReference< X > >