diff options
| author | Tilka <tilkax@gmail.com> | 2025-08-30 03:00:15 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-08-30 03:00:15 +0100 |
| commit | b47a75fa2d858f370b7dbfc0d32d13007c59be2e (patch) | |
| tree | d1cc74c83b87061c3551974507d38ab925f3a058 /Source/UnitTests/Common/MathUtilTest.cpp | |
| parent | 25be1cfe97de8b242f55f63f4f0c44631f3ed172 (diff) | |
| parent | da546bebb8601192cb7fa8ff30a840a1c43b0e03 (diff) | |
Merge pull request #13912 from jordan-woyak/simplify-saturating-cast
MathUtil: Simplify SaturatingCast implementation and fix edge case.
Diffstat (limited to 'Source/UnitTests/Common/MathUtilTest.cpp')
| -rw-r--r-- | Source/UnitTests/Common/MathUtilTest.cpp | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/Source/UnitTests/Common/MathUtilTest.cpp b/Source/UnitTests/Common/MathUtilTest.cpp index 966f3a4445..c60c19e6a1 100644 --- a/Source/UnitTests/Common/MathUtilTest.cpp +++ b/Source/UnitTests/Common/MathUtilTest.cpp @@ -66,6 +66,13 @@ TEST(MathUtil, SaturatingCast) // 16777217 = 2^24 + 1 is the first integer that cannot be represented correctly with a f32. EXPECT_EQ(16777216, MathUtil::SaturatingCast<s32>(float(16777216))); EXPECT_EQ(16777216, MathUtil::SaturatingCast<s32>(float(16777217))); + + // Note that values in the range [2147483584, 2147483776] have an equivalent float representation. + EXPECT_EQ(std::numeric_limits<s32>::max(), MathUtil::SaturatingCast<s32>(2147483648.f)); + EXPECT_EQ(std::numeric_limits<s32>::min(), MathUtil::SaturatingCast<s32>(-2147483649.f)); + + // Cast from a signed integer type to a smaller signed integer type + EXPECT_EQ(-128, (MathUtil::SaturatingCast<s8, int>(-129))); } TEST(MathUtil, RectangleEquality) |
