| 191 | } |
| 192 | |
| 193 | Unit Unit::root(const uint8_t num) const |
| 194 | { |
| 195 | auto apply = [&](auto val) { |
| 196 | if (val % num != 0) { |
| 197 | throw UnitsMismatchError("unit values must be divisible by root"); |
| 198 | } |
| 199 | return static_cast<decltype(val)>(val / num); |
| 200 | }; |
| 201 | |
| 202 | if (num < 1) { |
| 203 | throw UnitsMismatchError("root must be > 0"); |
| 204 | } |
| 205 | |
| 206 | UnitExponents res {}; |
| 207 | std::transform(_exps.begin(), _exps.end(), res.begin(), apply); |
| 208 | |
| 209 | return Unit {res}; |
| 210 | } |
| 211 | |
| 212 | Unit Unit::pow(const double exp) const |
| 213 | { |