diff options
| author | Diego Novillo <dnovillo@google.com> | 2015-04-30 13:22:48 +0000 |
|---|---|---|
| committer | Diego Novillo <dnovillo@google.com> | 2015-04-30 13:22:48 +0000 |
| commit | 95c93fc6d22043f34846730a8f2bbd77058e0bf5 (patch) | |
| tree | 43a8e8e9f6c96e67a327a63d0b3e608e057fe7c2 /llvm/unittests/Support/ScaledNumberTest.cpp | |
| parent | d8c1475f46dcfffde8dfd9c87dddbab176588150 (diff) | |
| download | llvm-95c93fc6d22043f34846730a8f2bbd77058e0bf5.zip llvm-95c93fc6d22043f34846730a8f2bbd77058e0bf5.tar.gz llvm-95c93fc6d22043f34846730a8f2bbd77058e0bf5.tar.bz2 | |
Fix private constructor for ScaledNumber.
Summary:
The private constructor for ScaledNumber was using uint64_t instead of
DigitsT. This was preventing instantiations of ScaledNumber with
anything other than uint64_t types.
In implementing the tests, I ran into another issue. Operators >>= and
<<= did not have variants for accepting other ScaledNumber as the shift
argument. This is expected by the SCALED_NUMBER_BOP.
It makes no sense to allow shifting a ScaledNumber by another
ScaledNumber, so the patch includes two new templates for shifting
ScaledNumbers.
Reviewers: dexonsmith
Subscribers: llvm-commits
Differential Revision: http://reviews.llvm.org/D9350
llvm-svn: 236232
Diffstat (limited to 'llvm/unittests/Support/ScaledNumberTest.cpp')
| -rw-r--r-- | llvm/unittests/Support/ScaledNumberTest.cpp | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/llvm/unittests/Support/ScaledNumberTest.cpp b/llvm/unittests/Support/ScaledNumberTest.cpp index 216292c..3872155 100644 --- a/llvm/unittests/Support/ScaledNumberTest.cpp +++ b/llvm/unittests/Support/ScaledNumberTest.cpp @@ -532,4 +532,28 @@ TEST(ScaledNumberHelpersTest, getDifference) { EXPECT_EQ(SP64(0, 0), getDifference64(1, -64, 1, -1)); } +TEST(ScaledNumberHelpersTest, arithmeticOperators) { + EXPECT_EQ(ScaledNumber<uint32_t>(10, 0), + ScaledNumber<uint32_t>(1, 3) + ScaledNumber<uint32_t>(1, 1)); + EXPECT_EQ(ScaledNumber<uint32_t>(6, 0), + ScaledNumber<uint32_t>(1, 3) - ScaledNumber<uint32_t>(1, 1)); + EXPECT_EQ(ScaledNumber<uint32_t>(2, 3), + ScaledNumber<uint32_t>(1, 3) * ScaledNumber<uint32_t>(1, 1)); + EXPECT_EQ(ScaledNumber<uint32_t>(1, 2), + ScaledNumber<uint32_t>(1, 3) / ScaledNumber<uint32_t>(1, 1)); + EXPECT_EQ(ScaledNumber<uint32_t>(1, 2), ScaledNumber<uint32_t>(1, 3) >> 1); + EXPECT_EQ(ScaledNumber<uint32_t>(1, 4), ScaledNumber<uint32_t>(1, 3) << 1); + + EXPECT_EQ(ScaledNumber<uint64_t>(10, 0), + ScaledNumber<uint64_t>(1, 3) + ScaledNumber<uint64_t>(1, 1)); + EXPECT_EQ(ScaledNumber<uint64_t>(6, 0), + ScaledNumber<uint64_t>(1, 3) - ScaledNumber<uint64_t>(1, 1)); + EXPECT_EQ(ScaledNumber<uint64_t>(2, 3), + ScaledNumber<uint64_t>(1, 3) * ScaledNumber<uint64_t>(1, 1)); + EXPECT_EQ(ScaledNumber<uint64_t>(1, 2), + ScaledNumber<uint64_t>(1, 3) / ScaledNumber<uint64_t>(1, 1)); + EXPECT_EQ(ScaledNumber<uint64_t>(1, 2), ScaledNumber<uint64_t>(1, 3) >> 1); + EXPECT_EQ(ScaledNumber<uint64_t>(1, 4), ScaledNumber<uint64_t>(1, 3) << 1); +} + } // end namespace |
