From ec5587904f195c59da2f047ae2ee3f5c83beee0a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89milie=20Feral?= Date: Thu, 9 Apr 2020 15:20:05 +0200 Subject: [PATCH] [poincare] Unit: double comparison should be done with care. On windows platform pow(10.0, -6.0) leads to small loss of precision and eventually to beautify(_Mg) --> _t --- poincare/src/unit.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/poincare/src/unit.cpp b/poincare/src/unit.cpp index eb12cf306..ff31c1cdb 100644 --- a/poincare/src/unit.cpp +++ b/poincare/src/unit.cpp @@ -303,7 +303,7 @@ void Unit::chooseBestMultipleForValue(double & value, const int exponent, Expres double val = value * std::pow(Division::Builder(clone(), Unit::Builder(dim, rep, &EmptyPrefix)).deepReduce(reductionContext).approximateToScalar(reductionContext.context(), reductionContext.complexFormat(), reductionContext.angleUnit()), exponent); // Get the best prefix and update val accordingly const Prefix * pre = rep->bestPrefixForValue(val, exponent); - if (std::fabs(std::log10(std::fabs(val))) < std::fabs(std::log10(std::fabs(bestVal)))) { + if (std::fabs(std::log10(std::fabs(bestVal))) - std::fabs(std::log10(std::fabs(val))) > Epsilon()) { /* At this point, val is closer to one than bestVal is.*/ bestRep = rep; bestPre = pre;