diff options
| author | Lioncash <mathew1800@gmail.com> | 2018-05-07 01:18:41 -0400 |
|---|---|---|
| committer | Lioncash <mathew1800@gmail.com> | 2018-05-07 02:56:32 -0400 |
| commit | 86018b503b51d32ea67b6e6978ba52fce36fc175 (patch) | |
| tree | 84354d2e463360e8d7a64fd8c23d4f29d6c9f974 /Source/UnitTests/Common/MathUtilTest.cpp | |
| parent | 756ef54ab6e72e30fcd01a7e4b9cce5c4a69e047 (diff) | |
Common: Move floating-point utility functions to FloatUtils.h/.cpp
Keeps all of the floating-point utility functions in their own file to
keep them all together. This also provides a place for other
general-purpose floating-point functions to be added in the future,
which will be necessary when improving the flag-setting within the
interpreter.
Diffstat (limited to 'Source/UnitTests/Common/MathUtilTest.cpp')
| -rw-r--r-- | Source/UnitTests/Common/MathUtilTest.cpp | 60 |
1 files changed, 0 insertions, 60 deletions
diff --git a/Source/UnitTests/Common/MathUtilTest.cpp b/Source/UnitTests/Common/MathUtilTest.cpp index 9c84ad6f0a..4b21ace1c4 100644 --- a/Source/UnitTests/Common/MathUtilTest.cpp +++ b/Source/UnitTests/Common/MathUtilTest.cpp @@ -3,8 +3,6 @@ // Refer to the license.txt file included. #include <gtest/gtest.h> -#include <limits> -#include <random> #include "Common/MathUtil.h" @@ -20,18 +18,6 @@ TEST(MathUtil, Clamp) EXPECT_EQ(0.0, MathUtil::Clamp(-1.0, 0.0, 2.0)); } -TEST(MathUtil, IsQNAN) -{ - EXPECT_TRUE(MathUtil::IsQNAN(std::numeric_limits<double>::quiet_NaN())); - EXPECT_FALSE(MathUtil::IsQNAN(MathUtil::SNANConstant<double>())); -} - -TEST(MathUtil, IsSNAN) -{ - EXPECT_FALSE(MathUtil::IsSNAN(std::numeric_limits<double>::quiet_NaN())); - EXPECT_TRUE(MathUtil::IsSNAN(MathUtil::SNANConstant<double>())); -} - TEST(MathUtil, IntLog2) { EXPECT_EQ(0, IntLog2(1)); @@ -44,49 +30,3 @@ TEST(MathUtil, IntLog2) EXPECT_EQ(3, IntLog2(15)); EXPECT_EQ(63, IntLog2(0xFFFFFFFFFFFFFFFFull)); } - -TEST(MathUtil, FlushToZero) -{ - // To test the software implementation we need to make sure FTZ and DAZ are disabled. - // Using volatile here to ensure the compiler doesn't constant-fold it, - // we want the multiplication to occur at test runtime. - volatile float s = std::numeric_limits<float>::denorm_min(); - volatile double d = std::numeric_limits<double>::denorm_min(); - // Casting away the volatile attribute is required in order for msvc to resolve this to the - // correct instance of the comparison function. - EXPECT_LT(0.f, (float)(s * 2)); - EXPECT_LT(0.0, (double)(d * 2)); - - EXPECT_EQ(+0.0, MathUtil::FlushToZero(+std::numeric_limits<double>::denorm_min())); - EXPECT_EQ(-0.0, MathUtil::FlushToZero(-std::numeric_limits<double>::denorm_min())); - EXPECT_EQ(+0.0, MathUtil::FlushToZero(+std::numeric_limits<double>::min() / 2)); - EXPECT_EQ(-0.0, MathUtil::FlushToZero(-std::numeric_limits<double>::min() / 2)); - EXPECT_EQ(std::numeric_limits<double>::min(), - MathUtil::FlushToZero(std::numeric_limits<double>::min())); - EXPECT_EQ(std::numeric_limits<double>::max(), - MathUtil::FlushToZero(std::numeric_limits<double>::max())); - EXPECT_EQ(+std::numeric_limits<double>::infinity(), - MathUtil::FlushToZero(+std::numeric_limits<double>::infinity())); - EXPECT_EQ(-std::numeric_limits<double>::infinity(), - MathUtil::FlushToZero(-std::numeric_limits<double>::infinity())); - - // Test all subnormals as well as an equally large set of random normal floats. - std::default_random_engine engine(0); - std::uniform_int_distribution<u32> dist(0x00800000u, 0x7fffffffu); - for (u32 i = 0; i <= 0x007fffffu; ++i) - { - MathUtil::IntFloat x(i); - EXPECT_EQ(+0.f, MathUtil::FlushToZero(x.f)); - - x.i = i | 0x80000000u; - EXPECT_EQ(-0.f, MathUtil::FlushToZero(x.f)); - - x.i = dist(engine); - MathUtil::IntFloat y(MathUtil::FlushToZero(x.f)); - EXPECT_EQ(x.i, y.i); - - x.i |= 0x80000000u; - y.f = MathUtil::FlushToZero(x.f); - EXPECT_EQ(x.i, y.i); - } -} |
