From 73bb09b90417dff12601605713e70c3603aaa503 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89milie=20Feral?= Date: Mon, 23 Apr 2018 12:08:29 +0200 Subject: [PATCH] [poincare] Avoid creating decimal before approximating it in approximateToScalar --- poincare/src/expression.cpp | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/poincare/src/expression.cpp b/poincare/src/expression.cpp index 60f90babb..101540d2b 100644 --- a/poincare/src/expression.cpp +++ b/poincare/src/expression.cpp @@ -471,11 +471,14 @@ template Expression * Expression::approximate(Context& context, Angl } template T Expression::approximateToScalar(Context& context, AngleUnit angleUnit, ComplexFormat complexFormat) const { - Expression * evaluation = approximate(context, angleUnit, complexFormat); - T result = NAN; - if (evaluation->type() == Type::Decimal) { - result = static_cast(evaluation)->toScalar(); + if (angleUnit == AngleUnit::Default) { + angleUnit = Preferences::sharedPreferences()->angleUnit(); } + if (complexFormat == ComplexFormat::Default) { + complexFormat = Preferences::sharedPreferences()->complexFormat(); + } + Evaluation * evaluation = privateApproximate(T(), context, angleUnit); + T result = evaluation->toScalar(); /*if (evaluation->type() == Type::Matrix) { if (numberOfOperands() == 1) { result = static_cast *>(operand(0))->toScalar();