[poincare] Unit::chooseBestMultipleForValue handles edge cases (inf, 1,

0) cases itself
This commit is contained in:
Émilie Feral
2020-04-24 10:56:27 +02:00
parent 687766567d
commit ec7382c75e
2 changed files with 5 additions and 2 deletions

View File

@@ -440,7 +440,7 @@ Expression Multiplication::shallowBeautify(ExpressionNode::ReductionContext redu
result = Undefined::Builder();
} else {
// Find the right unit prefix when the value ≠ 0
if (unitConversionMode == ExpressionNode::UnitConversion::Default && value != 0.0 && value != 1.0 && !std::isinf(value)) {
if (unitConversionMode == ExpressionNode::UnitConversion::Default) {
// Identify the first Unit factor and its exponent
Expression firstFactor = units;
int exponent = 1;

View File

@@ -319,7 +319,10 @@ Expression Unit::shallowReduce(ExpressionNode::ReductionContext reductionContext
}
void Unit::chooseBestMultipleForValue(double & value, const int exponent, ExpressionNode::ReductionContext reductionContext) {
assert(value != 0 && !std::isnan(value) && !std::isinf(value) && exponent != 0);
assert(!std::isnan(value) && exponent != 0);
if (value == 0 || value == 1.0 || std::isinf(value)) {
return;
}
UnitNode * unitNode = node();
const Dimension * dim = unitNode->dimension();
/* Find in the Dimension 'dim' which unit (Representative and Prefix) make