13#include <catch2/catch.hpp>
18 constexpr auto size = 40;
19 const auto input = [&] {
20 std::vector<float> exponential(
size);
21 std::iota(exponential.begin(), exponential.end(), -20.f);
22 std::vector<float> input(exponential.size());
24 exponential.begin(), exponential.end(), input.begin(),
25 [](
float x) { return std::exp(x); });
28 const auto expected = [&] {
29 std::vector<float> expected(
size);
30 std::transform(input.begin(), input.end(), expected.begin(), [](
float x) {
35 const auto actual = [&] {
36 std::vector<float> actual(
size);
37 std::transform(input.begin(), input.end(), actual.begin(),
FastLog2);
40 const auto error = [&] {
41 std::vector<float> error(
size);
43 expected.begin(), expected.end(), actual.begin(), error.begin(),
44 [](
float e,
float a) { return std::abs(e - a); });
47 const auto maxError = *std::max_element(error.begin(), error.end());
48 REQUIRE(maxError < 1e-2);
constexpr float FastLog2(float x)
Approximates the base-2 logarithm of a float to two decimal places, adapted from https://stackoverflo...