MCPcopy Create free account
hub / github.com/boostorg/hana / sqrt

Function sqrt

example/tutorial/integral.cpp:30–40  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

28 !hana::Constant<T>::value
29>>
30constexpr T sqrt(T x) {
31 T inf = 0, sup = (x == 1 ? 1 : x/2);
32 while (!((sup - inf) <= 1 || ((sup*sup <= x) && ((sup+1)*(sup+1) > x)))) {
33 T mid = (inf + sup) / 2;
34 bool take_inf = mid*mid > x ? 1 : 0;
35 inf = take_inf ? inf : mid;
36 sup = take_inf ? mid : sup;
37 }
38
39 return sup*sup <= x ? sup : inf;
40}
41
42template <typename T, typename = std::enable_if_t<
43 hana::Constant<T>::value

Callers 1

distanceFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected