mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-07-23 14:19:46 -06: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:
@ -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))));
|
||||
}
|
||||
}
|
||||
|
@ -10,8 +10,8 @@
|
||||
|
||||
#include <gtest/gtest.h> // NOLINT
|
||||
|
||||
#include "Common/BitUtils.h"
|
||||
#include "Common/Common.h"
|
||||
#include "Common/FloatUtils.h"
|
||||
#include "VideoCommon/CPMemory.h"
|
||||
#include "VideoCommon/DataReader.h"
|
||||
#include "VideoCommon/OpcodeDecoding.h"
|
||||
@ -72,14 +72,15 @@ protected:
|
||||
m_src.Write<T, true>(val);
|
||||
}
|
||||
|
||||
void ExpectOut(float val)
|
||||
void ExpectOut(float expected)
|
||||
{
|
||||
// Read unswapped.
|
||||
Common::IntFloat expected(val), actual(m_dst.Read<float, false>());
|
||||
if (!actual.f || actual.f != actual.f)
|
||||
EXPECT_EQ(expected.i, actual.i);
|
||||
const float actual = m_dst.Read<float, false>();
|
||||
|
||||
if (!actual || actual != actual)
|
||||
EXPECT_EQ(Common::BitCast<u32>(expected), Common::BitCast<u32>(actual));
|
||||
else
|
||||
EXPECT_EQ(expected.f, actual.f);
|
||||
EXPECT_EQ(expected, actual);
|
||||
}
|
||||
|
||||
void RunVertices(int count, int expected_count = -1)
|
||||
|
Reference in New Issue
Block a user