diff --git a/poincare/src/unit.cpp b/poincare/src/unit.cpp index 901085695..f92b0bc7a 100644 --- a/poincare/src/unit.cpp +++ b/poincare/src/unit.cpp @@ -922,11 +922,15 @@ void Unit::chooseBestRepresentativeAndPrefix(double * value, double exponent, Ex double baseValue = *value * std::pow(node()->representative()->ratio() * std::pow(10., node()->prefix()->exponent() - node()->representative()->basePrefix()->exponent()), exponent); const Prefix * bestPrefix = (optimizePrefix) ? Prefix::EmptyPrefix() : nullptr; const Representative * bestRepresentative = node()->representative()->standardRepresentative(baseValue, exponent, reductionContext, &bestPrefix); + if (!optimizePrefix) { + bestPrefix = bestRepresentative->basePrefix(); + } + if (bestRepresentative != node()->representative()) { *value = *value * std::pow(node()->representative()->ratio() / bestRepresentative->ratio() * std::pow(10., bestRepresentative->basePrefix()->exponent() - node()->representative()->basePrefix()->exponent()), exponent); node()->setRepresentative(bestRepresentative); } - if (optimizePrefix && bestPrefix != node()->prefix()) { + if (bestPrefix != node()->prefix()) { *value = *value * std::pow(10., exponent * (node()->prefix()->exponent() - bestPrefix->exponent())); node()->setPrefix(bestPrefix); } diff --git a/poincare/test/simplification.cpp b/poincare/test/simplification.cpp index 8ccc7718b..32b5bf580 100644 --- a/poincare/test/simplification.cpp +++ b/poincare/test/simplification.cpp @@ -536,6 +536,7 @@ QUIZ_CASE(poincare_simplification_units) { assert_parsed_expression_simplify_to("cos(1_s/1_s)", "cos(1)"); assert_parsed_expression_simplify_to("1_m+π_m+√(2)_m-cos(15)_m", "6.3154941288217×_m"); assert_parsed_expression_simplify_to("√(16×_m^2)", "4×_m"); + assert_parsed_expression_simplify_to("1×_A_kg", "2.2046226218488×_A×_lb", User, Radian, Imperial); } QUIZ_CASE(poincare_simplification_power) {