mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-06-20 01:01:40 +00:00
FloatUtils: Remove IntDouble and IntFloat
Type punning via unions in C++ invokes undefined behavior. Instead, leverage BitCast, our variant of C++2a's std::bit_cast
This commit is contained in:
parent
bde4e970f1
commit
0a3631cc76
3 changed files with 32 additions and 46 deletions
|
@ -7,6 +7,7 @@
|
|||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include "Common/BitUtils.h"
|
||||
#include "Common/FloatUtils.h"
|
||||
|
||||
TEST(FloatUtils, IsQNAN)
|
||||
|
@ -51,18 +52,16 @@ TEST(FloatUtils, FlushToZero)
|
|||
std::uniform_int_distribution<u32> dist(0x00800000u, 0x7fffffffu);
|
||||
for (u32 i = 0; i <= 0x007fffffu; ++i)
|
||||
{
|
||||
Common::IntFloat x(i);
|
||||
EXPECT_EQ(+0.f, Common::FlushToZero(x.f));
|
||||
u32 i_tmp = i;
|
||||
EXPECT_EQ(+0.f, Common::FlushToZero(Common::BitCast<float>(i_tmp)));
|
||||
|
||||
x.i = i | 0x80000000u;
|
||||
EXPECT_EQ(-0.f, Common::FlushToZero(x.f));
|
||||
i_tmp |= 0x80000000u;
|
||||
EXPECT_EQ(-0.f, Common::FlushToZero(Common::BitCast<float>(i_tmp)));
|
||||
|
||||
x.i = dist(engine);
|
||||
Common::IntFloat y(Common::FlushToZero(x.f));
|
||||
EXPECT_EQ(x.i, y.i);
|
||||
i_tmp = dist(engine);
|
||||
EXPECT_EQ(i_tmp, Common::BitCast<u32>(Common::FlushToZero(Common::BitCast<float>(i_tmp))));
|
||||
|
||||
x.i |= 0x80000000u;
|
||||
y.f = Common::FlushToZero(x.f);
|
||||
EXPECT_EQ(x.i, y.i);
|
||||
i_tmp |= 0x80000000u;
|
||||
EXPECT_EQ(i_tmp, Common::BitCast<u32>(Common::FlushToZero(Common::BitCast<float>(i_tmp))));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue