ddnet/src/test/math.cpp
Robert Müller 859727c1d3 Fix inaccurate envelope point value rounding
Round to nearest integer instead of truncating in `f2fx` to ensure correct round-trip with `fx2f`.

Add test to ensure correct round-trip with maximum `0.0005f` absolute error.
2023-11-10 19:11:10 +01:00

15 lines
262 B
C++

#include "test.h"
#include <gtest/gtest.h>
#include <base/math.h>
TEST(Math, FixedPointRoundtrip)
{
for(int i = 0; i < 100000; ++i)
{
const float Number = i / 1000.0f;
EXPECT_NEAR(Number, fx2f(f2fx(Number)), 0.0005f);
EXPECT_EQ(i, f2fx(fx2f(i)));
}
}