Support: Clean up getRounded() tests

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@211337 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Duncan P. N. Exon Smith 2014-06-20 02:31:07 +00:00
parent 5cf39383da
commit af08b8b820
2 changed files with 24 additions and 14 deletions

View File

@ -53,6 +53,18 @@ inline std::pair<DigitsT, int16_t> getRounded(DigitsT Digits, int16_t Scale,
return std::make_pair(Digits, Scale);
}
/// \brief Convenience helper for 32-bit rounding.
inline std::pair<uint32_t, int16_t> getRounded32(uint32_t Digits, int16_t Scale,
bool ShouldRound) {
return getRounded(Digits, Scale, ShouldRound);
}
/// \brief Convenience helper for 64-bit rounding.
inline std::pair<uint64_t, int16_t> getRounded64(uint64_t Digits, int16_t Scale,
bool ShouldRound) {
return getRounded(Digits, Scale, ShouldRound);
}
/// \brief Adjust a 64-bit scaled number down to the appropriate width.
///
/// Adjust a soft float with 64-bits of digits down, keeping as much

View File

@ -41,21 +41,19 @@ typedef ScaledPair<uint32_t> SP32;
typedef ScaledPair<uint64_t> SP64;
TEST(ScaledNumberHelpersTest, getRounded) {
EXPECT_EQ(getRounded<uint32_t>(0, 0, false), SP32(0, 0));
EXPECT_EQ(getRounded<uint32_t>(0, 0, true), SP32(1, 0));
EXPECT_EQ(getRounded<uint32_t>(20, 21, true), SP32(21, 21));
EXPECT_EQ(getRounded<uint32_t>(UINT32_MAX, 0, false), SP32(UINT32_MAX, 0));
EXPECT_EQ(getRounded<uint32_t>(UINT32_MAX, 0, true), SP32(1 << 31, 1));
EXPECT_EQ(getRounded32(0, 0, false), SP32(0, 0));
EXPECT_EQ(getRounded32(0, 0, true), SP32(1, 0));
EXPECT_EQ(getRounded32(20, 21, true), SP32(21, 21));
EXPECT_EQ(getRounded32(UINT32_MAX, 0, false), SP32(UINT32_MAX, 0));
EXPECT_EQ(getRounded32(UINT32_MAX, 0, true), SP32(1 << 31, 1));
EXPECT_EQ(getRounded<uint64_t>(0, 0, false), SP64(0, 0));
EXPECT_EQ(getRounded<uint64_t>(0, 0, true), SP64(1, 0));
EXPECT_EQ(getRounded<uint64_t>(20, 21, true), SP64(21, 21));
EXPECT_EQ(getRounded<uint64_t>(UINT32_MAX, 0, false), SP64(UINT32_MAX, 0));
EXPECT_EQ(getRounded<uint64_t>(UINT32_MAX, 0, true),
SP64(UINT64_C(1) << 32, 0));
EXPECT_EQ(getRounded<uint64_t>(UINT64_MAX, 0, false), SP64(UINT64_MAX, 0));
EXPECT_EQ(getRounded<uint64_t>(UINT64_MAX, 0, true),
SP64(UINT64_C(1) << 63, 1));
EXPECT_EQ(getRounded64(0, 0, false), SP64(0, 0));
EXPECT_EQ(getRounded64(0, 0, true), SP64(1, 0));
EXPECT_EQ(getRounded64(20, 21, true), SP64(21, 21));
EXPECT_EQ(getRounded64(UINT32_MAX, 0, false), SP64(UINT32_MAX, 0));
EXPECT_EQ(getRounded64(UINT32_MAX, 0, true), SP64(UINT64_C(1) << 32, 0));
EXPECT_EQ(getRounded64(UINT64_MAX, 0, false), SP64(UINT64_MAX, 0));
EXPECT_EQ(getRounded64(UINT64_MAX, 0, true), SP64(UINT64_C(1) << 63, 1));
}
TEST(FloatsTest, getAdjusted) {