[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
This commit is contained in:
Émilie Feral
2020-04-09 15:20:05 +02:00
committed by Ecco
parent 8c844a772b
commit ec5587904f

View File

@@ -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<double>(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<double>()) {
/* At this point, val is closer to one than bestVal is.*/
bestRep = rep;
bestPre = pre;