| 210 | } |
| 211 | |
| 212 | Unit Unit::pow(const double exp) const |
| 213 | { |
| 214 | auto apply = [&](const auto val) { |
| 215 | const auto num {val * exp}; |
| 216 | if (std::fabs(std::round(num) - num) >= std::numeric_limits<double>::epsilon()) { |
| 217 | throw UnitsMismatchError("pow() of unit not possible"); |
| 218 | } |
| 219 | |
| 220 | return static_cast<decltype(val)>(val * exp); |
| 221 | }; |
| 222 | |
| 223 | UnitExponents res {}; |
| 224 | std::transform(_exps.begin(), _exps.end(), res.begin(), apply); |
| 225 | |
| 226 | return Unit {res}; |
| 227 | } |
| 228 | |
| 229 | UnitExponents Unit::exponents() const |
| 230 | { |