forked from OSchip/llvm-project
[flang] Correct off-by-one error in SET_EXPONENT
SET_EXPONENT is returning values that are too large by a factor of two. Differential Revision: https://reviews.llvm.org/D107986
This commit is contained in:
parent
a2556bf44c
commit
a05bae6163
|
@ -109,7 +109,7 @@ template <typename T> inline T SetExponent(T x, std::int64_t p) {
|
|||
} else if (x == 0) {
|
||||
return 0; // 0 -> 0
|
||||
} else {
|
||||
int expo{std::ilogb(x)};
|
||||
int expo{std::ilogb(x) + 1};
|
||||
auto ip{static_cast<int>(p - expo)};
|
||||
if (ip != p - expo) {
|
||||
ip = p < 0 ? std::numeric_limits<int>::min()
|
||||
|
|
|
@ -142,10 +142,10 @@ TEST(Numeric, Scale) {
|
|||
TEST(Numeric, SetExponent) {
|
||||
EXPECT_EQ(RTNAME(SetExponent4)(Real<4>{0}, 0), 0);
|
||||
EXPECT_EQ(RTNAME(SetExponent8)(Real<8>{0}, 666), 0);
|
||||
EXPECT_EQ(RTNAME(SetExponent8)(Real<8>{3.0}, 0), 1.5);
|
||||
EXPECT_EQ(RTNAME(SetExponent4)(Real<4>{1.0}, 0), 1.0);
|
||||
EXPECT_EQ(RTNAME(SetExponent4)(Real<4>{1.0}, 1), 2.0);
|
||||
EXPECT_EQ(RTNAME(SetExponent4)(Real<4>{1.0}, -1), 0.5);
|
||||
EXPECT_EQ(RTNAME(SetExponent8)(Real<8>{3.0}, 0), 0.75);
|
||||
EXPECT_EQ(RTNAME(SetExponent4)(Real<4>{1.0}, 0), 0.5);
|
||||
EXPECT_EQ(RTNAME(SetExponent4)(Real<4>{1.0}, 1), 1.0);
|
||||
EXPECT_EQ(RTNAME(SetExponent4)(Real<4>{1.0}, -1), 0.25);
|
||||
EXPECT_TRUE(std::isnan(
|
||||
RTNAME(SetExponent4)(std::numeric_limits<Real<4>>::infinity(), 1)));
|
||||
EXPECT_TRUE(std::isnan(
|
||||
|
|
Loading…
Reference in New Issue