diff --git a/poincare/include/poincare/power.h b/poincare/include/poincare/power.h index 1f40e978f..77f2dda77 100644 --- a/poincare/include/poincare/power.h +++ b/poincare/include/poincare/power.h @@ -34,7 +34,7 @@ public: int polynomialDegree(Context * context, const char * symbolName) const override; int getPolynomialCoefficients(Context * context, const char * symbolName, Expression coefficients[], ExpressionNode::SymbolicComputation symbolicComputation) const override; - template static Complex tryComputeRealRootOfRationalPow(const std::complex c, T p, T q); + template static Complex computeNotPrincipalRealRootOfRationalPow(const std::complex c, T p, T q); template static Complex compute(const std::complex c, const std::complex d, Preferences::ComplexFormat complexFormat); private: diff --git a/poincare/src/nth_root.cpp b/poincare/src/nth_root.cpp index 3af471605..db4748a47 100644 --- a/poincare/src/nth_root.cpp +++ b/poincare/src/nth_root.cpp @@ -48,7 +48,7 @@ Evaluation NthRootNode::templatedApproximate(Context * context, Preferences:: * correspond to the principale angle. */ if (complexFormat == Preferences::ComplexFormat::Real && indexc.imag() == 0.0 && std::round(indexc.real()) == indexc.real()) { // root(x, q) with q integer and x real - Complex result = PowerNode::tryComputeRealRootOfRationalPow(basec, (T)1.0, indexc.real()); + Complex result = PowerNode::computeNotPrincipalRealRootOfRationalPow(basec, (T)1.0, indexc.real()); if (!result.isUndefined()) { return result; } diff --git a/poincare/src/power.cpp b/poincare/src/power.cpp index 712c5ab79..c7362383e 100644 --- a/poincare/src/power.cpp +++ b/poincare/src/power.cpp @@ -128,12 +128,14 @@ bool PowerNode::childAtIndexNeedsUserParentheses(const Expression & child, int c // Private template -Complex PowerNode::tryComputeRealRootOfRationalPow(const std::complex c, T p, T q) { +Complex PowerNode::computeNotPrincipalRealRootOfRationalPow(const std::complex c, T p, T q) { // Assert p and q are in fact integers assert(std::round(p) == p); assert(std::round(q) == q); - /* Try to find a real root of c^(p/q) with p, q integers. If none is found - * easily, return undefined -> this does not mean there is no real root. */ + /* Try to find a real root of c^(p/q) with p, q integers. We ignore cases + * where the principal root is real as these cases are handled generically + * later (for instance 1232^(1/8) which has a real principal root is not + * handled here). */ if (c.imag() == 0 && std::pow((T)-1.0, q) < 0.0) { /* If c real and q odd integer (q odd if (-1)^q = -1), a real root does * exist (which is not necessarily the principal root)! @@ -321,7 +323,7 @@ template Evaluation PowerNode::templatedApproximate(Context * con if (std::isnan(p) || std::isnan(q)) { goto defaultApproximation; } - Complex result = tryComputeRealRootOfRationalPow(c, p, q); + Complex result = computeNotPrincipalRealRootOfRationalPow(c, p, q); if (!result.isUndefined()) { return result; }