| 124 | namespace detail { |
| 125 | |
| 126 | template<class T, class Rounding> inline |
| 127 | T pow_dn(const T& x_, int pwr, Rounding& rnd) // x and pwr are positive |
| 128 | { |
| 129 | T x = x_; |
| 130 | T y = (pwr & 1) ? x_ : static_cast<T>(1); |
| 131 | pwr >>= 1; |
| 132 | while (pwr > 0) { |
| 133 | x = rnd.mul_down(x, x); |
| 134 | if (pwr & 1) y = rnd.mul_down(x, y); |
| 135 | pwr >>= 1; |
| 136 | } |
| 137 | return y; |
| 138 | } |
| 139 | |
| 140 | template<class T, class Rounding> inline |
| 141 | T pow_up(const T& x_, int pwr, Rounding& rnd) // x and pwr are positive |