From 33a20b93f5dcc80596e3bfcf2990d2a913063bd5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9a=20Saviot?= Date: Thu, 4 Jul 2019 11:19:19 +0200 Subject: [PATCH] [poincare] Log + negative argument gives unreal if complexFormat=real --- poincare/src/logarithm.cpp | 12 ++++++++---- poincare/test/complex.cpp | 2 +- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/poincare/src/logarithm.cpp b/poincare/src/logarithm.cpp index 2386e4084..4d621ca6f 100644 --- a/poincare/src/logarithm.cpp +++ b/poincare/src/logarithm.cpp @@ -1,19 +1,18 @@ #include - #include #include #include +#include #include #include +#include #include #include #include #include -#include #include - -#include #include +#include #include #include #include @@ -118,6 +117,11 @@ Expression Logarithm::shallowReduce(ExpressionNode::ReductionContext reductionCo if (c.sign(reductionContext.context()) == ExpressionNode::Sign::Negative || childAtIndex(1).sign(reductionContext.context()) == ExpressionNode::Sign::Negative) { + if (reductionContext.complexFormat() == Preferences::ComplexFormat::Real) { + Expression result = Unreal::Builder(); + replaceWithInPlace(result); + return result; + } return *this; } Expression f = simpleShallowReduce(reductionContext.context(), reductionContext.complexFormat(), reductionContext.angleUnit()); diff --git a/poincare/test/complex.cpp b/poincare/test/complex.cpp index 9ae0a374c..2f24eab66 100644 --- a/poincare/test/complex.cpp +++ b/poincare/test/complex.cpp @@ -40,7 +40,7 @@ QUIZ_CASE(poincare_complex_simplify) { assert_parsed_expression_simplify_to("𝐢", "unreal", User, Radian, Real); assert_parsed_expression_simplify_to("√(-1)", "unreal", User, Radian, Real); assert_parsed_expression_simplify_to("√(-1)×√(-1)", "unreal", User, Radian, Real); - assert_parsed_expression_simplify_to("ln(-2)", "ln(-2)", User, Radian, Real); + assert_parsed_expression_simplify_to("ln(-2)", "unreal", User, Radian, Real); assert_parsed_expression_simplify_to("(-8)^(2/3)", "4", User, Radian, Real); assert_parsed_expression_simplify_to("(-8)^(2/5)", "2×root(2,5)", User, Radian, Real); assert_parsed_expression_simplify_to("(-8)^(1/5)", "-root(8,5)", User, Radian, Real);