-
Notifications
You must be signed in to change notification settings - Fork 13.6k
add power function to APInt #122788
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add power function to APInt #122788
Changes from 6 commits
93da597
3a8a088
40f5262
073727c
77d8c07
a30e29f
13cfbb3
34d9b96
d02314b
564f2dc
e90a9c8
160dcdb
3271991
ee57ffa
7aea8ba
f492dfc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,6 +29,51 @@ TEST(APIntTest, ValueInit) { | |
EXPECT_TRUE(!Zero.sext(64)); | ||
} | ||
|
||
// Test that 0^5 == 0 | ||
TEST(APIntTest, PowZeroTo5) { | ||
APInt Zero = APInt(); | ||
EXPECT_TRUE(!Zero); | ||
APInt ZeroTo5 = APIntOps::pow(Zero, 5); | ||
EXPECT_TRUE(!ZeroTo5); | ||
} | ||
|
||
// Test that 1^16 == 1 | ||
TEST(APIntTest, PowOneTo16) { | ||
APInt One = APInt::getZero(32) + 1; | ||
ImanHosseini marked this conversation as resolved.
Show resolved
Hide resolved
|
||
APInt OneTo16 = APIntOps::pow(One, 16); | ||
EXPECT_EQ(One, OneTo16); | ||
} | ||
|
||
// Test that 2^10 == 1024 | ||
TEST(APIntTest, PowerTwoTo10) { | ||
APInt Two = APInt::getZero(32) + 2; | ||
ImanHosseini marked this conversation as resolved.
Show resolved
Hide resolved
|
||
APInt TwoTo20 = APIntOps::pow(Two, 10); | ||
APInt V_1024 = APInt::getZero(32) + 1024; | ||
ImanHosseini marked this conversation as resolved.
Show resolved
Hide resolved
|
||
EXPECT_EQ(TwoTo20, V_1024); | ||
} | ||
|
||
// Test that 3^3 == 27 | ||
TEST(APIntTest, PowerThreeTo3) { | ||
APInt Three = APInt::getZero(32) + 3; | ||
ImanHosseini marked this conversation as resolved.
Show resolved
Hide resolved
|
||
APInt ThreeTo3 = APIntOps::pow(Three, 3); | ||
APInt V_27 = APInt::getZero(32) + 27; | ||
EXPECT_EQ(ThreeTo3, V_27); | ||
} | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Test getMaxValue, getMaxSignedValue, getMinSignedValue cases There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added tests for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I mean APInt::getSignedMinValue There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this the right check?
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes |
||
// Test that SignedMaxValue^3 == SignedMaxValue | ||
TEST(APIntTest, PowerSignedMaxValue) { | ||
APInt SignedMaxValue = APInt::getSignedMaxValue(32); | ||
APInt MaxTo3 = APIntOps::pow(SignedMaxValue, 3); | ||
EXPECT_EQ(MaxTo3, SignedMaxValue); | ||
} | ||
|
||
// Test that MaxValue^3 == MaxValue | ||
TEST(APIntTest, PowerMaxValue) { | ||
APInt MaxValue = APInt::getMaxValue(32); | ||
APInt MaxTo3 = APIntOps::pow(MaxValue, 3); | ||
EXPECT_EQ(MaxValue, MaxTo3); | ||
} | ||
|
||
ImanHosseini marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// Test that APInt shift left works when bitwidth > 64 and shiftamt == 0 | ||
TEST(APIntTest, ShiftLeftByZero) { | ||
APInt One = APInt::getZero(65) + 1; | ||
|
Uh oh!
There was an error while loading. Please reload this page.