From 9936d9941189cd9b4f8e4c85b461b6af0ba0a20f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89milie=20Feral?= Date: Wed, 26 Feb 2020 14:51:06 +0100 Subject: [PATCH] [poincare] Add comment on Power::templatedApproximate --- poincare/src/power.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/poincare/src/power.cpp b/poincare/src/power.cpp index 29d25e7c4..b086e6b4f 100644 --- a/poincare/src/power.cpp +++ b/poincare/src/power.cpp @@ -290,12 +290,14 @@ template Evaluation PowerNode::templatedApproximate(Context * con std::complex c = static_cast &>(base).stdComplex(); T p = NAN; T q = NAN; + // If the power has been reduced, we look for a rational index if (childAtIndex(1)->type() == ExpressionNode::Type::Rational) { const RationalNode * r = static_cast(childAtIndex(1)); p = r->signedNumerator().approximate(); q = r->denominator().approximate(); } - // Spot form p/q with p, q integers + /* If the power has been simplified (reduced + beautified), we look for an + * index of the for Division(Rational,Rational). */ if (childAtIndex(1)->type() == ExpressionNode::Type::Division && childAtIndex(1)->childAtIndex(0)->type() == ExpressionNode::Type::Rational && childAtIndex(1)->childAtIndex(1)->type() == ExpressionNode::Type::Rational) { const RationalNode * pRat = static_cast(childAtIndex(1)->childAtIndex(0)); const RationalNode * qRat = static_cast(childAtIndex(1)->childAtIndex(1)); @@ -305,6 +307,9 @@ template Evaluation PowerNode::templatedApproximate(Context * con p = pRat->signedNumerator().approximate(); q = qRat->signedNumerator().approximate(); } + /* We don't handle power that haven't been reduced or simplified as the + * index can take to many forms and still be equivalent to p/q, + * with p, q integers. */ if (std::isnan(p) || std::isnan(q)) { goto defaultApproximation; }