| 28 | !hana::Constant<T>::value |
| 29 | >> |
| 30 | constexpr 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 | |
| 42 | template <typename T, typename = std::enable_if_t< |
| 43 | hana::Constant<T>::value |