pRC
multi-purpose Tensor Train library for C++
Loading...
Searching...
No Matches
prc
core
basic
functions
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
6
#include <
prc/core/basic/recursive_lambda.hpp
>
7
#include <
prc/core/basic/type_traits.hpp
>
8
9
namespace
pRC
10
{
11
template
<
class
T, If<IsUn
signed
Integral<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::RecursiveLambda
Definition
recursive_lambda.hpp:12
type_traits.hpp
pRC
Definition
cholesky.hpp:18
pRC::iSqrt
static constexpr T iSqrt(T const a)
Definition
isqrt.hpp:12
pRC::copy
static constexpr Conditional< IsSatisfied< C >, RemoveConstReference< X >, X > copy(X &&a)
Definition
copy.hpp:13
recursive_lambda.hpp
Generated by
1.9.8