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

Peter Klausler via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Aug 12 12:51:22 PDT 2021


This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGa05bae6163a3: [flang] Correct off-by-one error in SET_EXPONENT (authored by klausler).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Repository:
  rG LLVM Github Monorepo

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.366078.patch
Type: text/x-patch
Size: 1378 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210812/bd6c3328/attachment.bin>


More information about the llvm-commits mailing list