[Lldb-commits] [PATCH] D44693: Correctly handle float division in Scalar

Tom Tromey via Phabricator via lldb-commits lldb-commits at lists.llvm.org
Fri Mar 23 11:10:25 PDT 2018


tromey updated this revision to Diff 139616.
tromey added a comment.

Add unit test


https://reviews.llvm.org/D44693

Files:
  source/Core/Scalar.cpp
  unittests/Core/ScalarTest.cpp


Index: unittests/Core/ScalarTest.cpp
===================================================================
--- unittests/Core/ScalarTest.cpp
+++ unittests/Core/ScalarTest.cpp
@@ -132,3 +132,11 @@
   EXPECT_EQ(std::to_string(std::numeric_limits<unsigned long long>::max()),
             ScalarGetValue(std::numeric_limits<unsigned long long>::max()));
 }
+
+TEST(ScalarTest, Division) {
+  Scalar lhs(5.0);
+  Scalar rhs(2.0);
+  Scalar r = lhs / rhs;
+  EXPECT_TRUE(r.IsValid());
+  EXPECT_EQ(r, Scalar(2.5));
+}
Index: source/Core/Scalar.cpp
===================================================================
--- source/Core/Scalar.cpp
+++ source/Core/Scalar.cpp
@@ -2266,7 +2266,7 @@
     case Scalar::e_float:
     case Scalar::e_double:
     case Scalar::e_long_double:
-      if (b->m_float.isZero()) {
+      if (!b->m_float.isZero()) {
         result.m_float = a->m_float / b->m_float;
         return result;
       }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D44693.139616.patch
Type: text/x-patch
Size: 926 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20180323/10607318/attachment.bin>


More information about the lldb-commits mailing list