[Core] Correctly handle float division in Scalar.

Patch by Tom Tromey!

Differential Revision:  https://reviews.llvm.org/D44693

llvm-svn: 328649
This commit is contained in:
Davide Italiano 2018-03-27 18:37:54 +00:00
parent 0375cd46ef
commit 01c33b8189
2 changed files with 9 additions and 1 deletions

View File

@ -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;
}

View File

@ -132,3 +132,11 @@ TEST(ScalarTest, GetValue) {
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));
}