mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-01-19 00:37:25 +01:00
[poincare] A (Power of) Unit must not be orphan
This commit is contained in:
committed by
Émilie Feral
parent
c12ab3a2e2
commit
9a762f1bf6
@@ -5,7 +5,6 @@
|
||||
#include <poincare/constant.h>
|
||||
#include <poincare/cosine.h>
|
||||
#include <poincare/division.h>
|
||||
#include <poincare/float.h>
|
||||
#include <poincare/horizontal_layout.h>
|
||||
#include <poincare/infinity.h>
|
||||
#include <poincare/matrix.h>
|
||||
@@ -398,6 +397,10 @@ Expression Power::shallowReduce(ExpressionNode::ReductionContext reductionContex
|
||||
// The exponent must be an Integer
|
||||
return replaceWithUndefinedInPlace();
|
||||
}
|
||||
if (parent().isUninitialized() && base.type() == ExpressionNode::Type::Unit) {
|
||||
// A Power of Unit must not be orphan
|
||||
return Multiplication::Builder(Rational::Builder(1), *this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -979,15 +982,6 @@ Expression Power::shallowBeautify(ExpressionNode::ReductionContext reductionCont
|
||||
replaceWithInPlace(result);
|
||||
return result;
|
||||
}
|
||||
|
||||
// Step 4: Force Float(1) in front of an orphan Power of Unit
|
||||
if (parent().isUninitialized() && childAtIndex(0).type() == ExpressionNode::Type::Unit) {
|
||||
Multiplication m = Multiplication::Builder(Float<double>::Builder(1.0));
|
||||
replaceWithInPlace(m);
|
||||
m.addChildAtIndexInPlace(*this, 1, 1);
|
||||
return std::move(m);
|
||||
}
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
#include <poincare/unit.h>
|
||||
#include <poincare/division.h>
|
||||
#include <poincare/float.h>
|
||||
#include <poincare/ieee754.h>
|
||||
#include <poincare/multiplication.h>
|
||||
#include <poincare/power.h>
|
||||
@@ -310,19 +309,16 @@ Expression Unit::shallowReduce(ExpressionNode::ReductionContext reductionContext
|
||||
Expression multiplier = Power::Builder(Rational::Builder(10), Rational::Builder(prefixMultiplier)).shallowReduce(reductionContext);
|
||||
result = Multiplication::Builder(multiplier, result).shallowReduce(reductionContext);
|
||||
}
|
||||
if (parent().isUninitialized() && result.type() == ExpressionNode::Type::Unit) {
|
||||
// A Unit must not be orphan
|
||||
result = Multiplication::Builder(Rational::Builder(1), result);
|
||||
}
|
||||
replaceWithInPlace(result);
|
||||
return result;
|
||||
}
|
||||
|
||||
Expression Unit::shallowBeautify(ExpressionNode::ReductionContext reductionContext) {
|
||||
Expression ancestor = parent();
|
||||
// Force Float(1) in front of an orphan Unit
|
||||
if (ancestor.isUninitialized()) {
|
||||
Multiplication m = Multiplication::Builder(Float<double>::Builder(1.0));
|
||||
replaceWithInPlace(m);
|
||||
m.addChildAtIndexInPlace(*this, 1, 1);
|
||||
return std::move(m);
|
||||
}
|
||||
if (!ancestor.isUninitialized() && ancestor.type() == ExpressionNode::Type::Power) {
|
||||
ancestor = ancestor.parent();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user