[flang-commits] [PATCH] D107986: [flang] Correct off-by-one error in SET_EXPONENT

Peter Klausler via Phabricator via flang-commits flang-commits at lists.llvm.org
Thu Aug 12 12:27:10 PDT 2021


klausler updated this revision to Diff 366073.
klausler retitled this revision from "[flang] Correct expected unit test results for SET_EXPONENT" to "[flang] Correct off-by-one error in SET_EXPONENT".
klausler edited the summary of this revision.
klausler added a comment.

Fix both SET_EXPONENT and test.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D107986/new/

https://reviews.llvm.org/D107986

Files:
  flang/runtime/numeric.cpp
  flang/unittests/Runtime/Numeric.cpp


Index: flang/unittests/Runtime/Numeric.cpp
===================================================================
--- flang/unittests/Runtime/Numeric.cpp
+++ flang/unittests/Runtime/Numeric.cpp
@@ -142,10 +142,10 @@
 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(
Index: flang/runtime/numeric.cpp
===================================================================
--- flang/runtime/numeric.cpp
+++ flang/runtime/numeric.cpp
@@ -109,7 +109,7 @@
   } 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()


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D107986.366073.patch
Type: text/x-patch
Size: 1378 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/flang-commits/attachments/20210812/032caf23/attachment.bin>


More information about the flang-commits mailing list