From ce14c5d6945756a836b99b2cb5a4e44971197765 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9a=20Saviot?= Date: Fri, 28 Sep 2018 11:10:35 +0200 Subject: [PATCH] [poincare] Fix Power::shallowReduce. Real complexes are not NAN --- poincare/src/power.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/poincare/src/power.cpp b/poincare/src/power.cpp index d2b59bcb9..ecba61ae9 100644 --- a/poincare/src/power.cpp +++ b/poincare/src/power.cpp @@ -295,13 +295,12 @@ Expression Power::shallowReduce(Context & context, Preferences::AngleUnit angleU Evaluation c1Approximated = childAtIndex(1).node()->approximate(1.0f, context, angleUnit); Complex c0 = static_cast&>(c0Approximated); Complex c1 = static_cast&>(c1Approximated); - bool bothChildrenComplexes = c0.imag() != 0 && c1.imag() != 0; + bool bothChildrenComplexes = c0.imag() != 0 && c1.imag() != 0 && !std::isnan(c0.imag()) && !std::isnan(c1.imag()); bool nonComplexNegativeChild0 = c0.imag() == 0 && c0.real() < 0; if (bothChildrenComplexes) { return *this; } - /* Step 1: We handle simple cases as x^0, x^1, 0^x and 1^x first for 2 reasons: * - we can assert this step that there is no division by 0: * for instance, 0^(-2)->undefined @@ -443,7 +442,7 @@ Expression Power::shallowReduce(Context & context, Preferences::AngleUnit angleU // (a^b)^c -> a^(b*c) if a > 0 or c is integer if (childAtIndex(0).type() == ExpressionNode::Type::Power) { Power p = childAtIndex(0).convert(); - // Check is a > 0 or c is Integer + // Check if a > 0 or c is Integer if (p.childAtIndex(0).sign() == ExpressionNode::Sign::Positive || (childAtIndex(1).type() == ExpressionNode::Type::Rational && childAtIndex(1).convert().integerDenominator().isOne()))