mirror of
https://github.com/ddnet/ddnet.git
synced 2024-10-20 07:48:18 +00:00
859727c1d3
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.
15 lines
262 B
C++
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)));
|
|
}
|
|
}
|