mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-10 01:58:19 +00:00
Merge pull request #7431 from Robyt3/Editor-Envelope-Accuracy
Fix inaccurate envelope point value rounding
This commit is contained in:
commit
de52ded86d
|
@ -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
|
||||||
|
|
|
@ -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
14
src/test/math.cpp
Normal 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)));
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue