Merge pull request #7431 from Robyt3/Editor-Envelope-Accuracy

Fix inaccurate envelope point value rounding
This commit is contained in:
heinrich5991 2023-11-10 18:31:31 +00:00 committed by GitHub
commit de52ded86d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 16 additions and 1 deletions

View file

@ -2744,6 +2744,7 @@ if(GTEST_FOUND OR DOWNLOAD_GTEST)
jsonwriter.cpp jsonwriter.cpp
linereader.cpp linereader.cpp
mapbugs.cpp mapbugs.cpp
math.cpp
name_ban.cpp name_ban.cpp
net.cpp net.cpp
netaddr.cpp netaddr.cpp

View file

@ -66,7 +66,7 @@ constexpr int fxpscale = 1 << 10;
// float to fixed // float to fixed
constexpr inline int f2fx(float v) constexpr inline int f2fx(float v)
{ {
return (int)(v * fxpscale); return round_to_int(v * fxpscale);
} }
constexpr inline float fx2f(int v) constexpr inline float fx2f(int v)
{ {

14
src/test/math.cpp Normal file
View file

@ -0,0 +1,14 @@
#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)));
}
}