From 01c33b818950af40a7bd2089211a24db8c1f7dd0 Mon Sep 17 00:00:00 2001 From: Davide Italiano Date: Tue, 27 Mar 2018 18:37:54 +0000 Subject: [PATCH] [Core] Correctly handle float division in Scalar. Patch by Tom Tromey! Differential Revision: https://reviews.llvm.org/D44693 llvm-svn: 328649 --- lldb/source/Core/Scalar.cpp | 2 +- lldb/unittests/Core/ScalarTest.cpp | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/lldb/source/Core/Scalar.cpp b/lldb/source/Core/Scalar.cpp index 630083b..4ef29e7 100644 --- a/lldb/source/Core/Scalar.cpp +++ b/lldb/source/Core/Scalar.cpp @@ -2266,7 +2266,7 @@ const Scalar lldb_private::operator/(const Scalar &lhs, const Scalar &rhs) { 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; } diff --git a/lldb/unittests/Core/ScalarTest.cpp b/lldb/unittests/Core/ScalarTest.cpp index fedcd19..47fa021 100644 --- a/lldb/unittests/Core/ScalarTest.cpp +++ b/lldb/unittests/Core/ScalarTest.cpp @@ -132,3 +132,11 @@ TEST(ScalarTest, GetValue) { EXPECT_EQ(std::to_string(std::numeric_limits::max()), ScalarGetValue(std::numeric_limits::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)); +} -- 2.7.4