6 //---------------------------------------------------------------------------
8 template < typename T >
9 T IntegerRoot<T>::operator()(T n, std::size_t N)
11 // this split is just to avoid annoying warning that the n<0 test always fails for unsigned types.
12 return this->compute(n, N, cat2type<is_signed, T>());
15 //---------------------------------------------------------------------------
17 template < typename T >
18 T IntegerRoot<T>::compute(T n, std::size_t N, label::Passed<is_signed>)
28 return -this->solve(-n, N);
33 return this->solve(n, N);
37 //---------------------------------------------------------------------------
39 template < typename T >
40 T IntegerRoot<T>::compute(T n, std::size_t N, label::Failed<is_signed>)
42 return this->solve(n, N);
45 //---------------------------------------------------------------------------
47 template < typename T >
48 T IntegerRoot<T>::solve(T n, std::size_t N)
50 for (std::size_t i = 0;;++i)
52 T p = integer_pow(i, N);
54 else if (p > n) throw NoRoot();
56 // should never go here
60 //---------------------------------------------------------------------------
62 /// Sort a, b, c in decreasing order (a>=b>=c).
63 template < typename T >
64 void sort(T & a, T & b, T & c)
67 if (a>=c) { // a >= b c
68 if (b>=c) { // a >= b >= c
70 } else { // a >= c > b
73 } else { // c > a >= b
78 if (b<=c) { // c > b > a