| 2 | #include <fpm/math.hpp> |
| 3 | |
| 4 | TEST(power, exp) |
| 5 | { |
| 6 | // For several values, verify that fpm::exp is close to std::exp. |
| 7 | using P = fpm::fixed<std::int32_t, std::int64_t, 12>; |
| 8 | |
| 9 | // Maximum relative error (percentage) we allow |
| 10 | constexpr auto MAX_ERROR_PERC = 0.02; |
| 11 | |
| 12 | for (double value = -5; value <= 5; value += 0.1) |
| 13 | { |
| 14 | auto exp_real = std::exp(value); |
| 15 | auto exp_fixed = static_cast<double>(exp(P(value))); |
| 16 | EXPECT_TRUE(HasMaximumError(exp_fixed, exp_real, MAX_ERROR_PERC)); |
| 17 | } |
| 18 | } |
| 19 | |
| 20 | TEST(power, exp2) |
| 21 | { |