mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-01-19 00:37:25 +01:00
[poincare/expression] getUnit returns an uninitialized Expression
when there is no Unit instead of Undefined
This commit is contained in:
committed by
Émilie Feral
parent
f5b964339c
commit
0c4434d088
@@ -160,8 +160,12 @@ Expression Addition::shallowReduce(ExpressionNode::ReductionContext reductionCon
|
||||
* the result is not homogeneous. */
|
||||
{
|
||||
Expression unit = childAtIndex(0).getUnit();
|
||||
const bool hasUnit = !unit.isUninitialized();
|
||||
for (int i = 1; i < childrenCount; i++) {
|
||||
if (!unit.isIdenticalTo(childAtIndex(i).getUnit())) {
|
||||
Expression otherUnit = childAtIndex(i).getUnit();
|
||||
if (hasUnit == otherUnit.isUninitialized() ||
|
||||
(hasUnit && !unit.isIdenticalTo(otherUnit)))
|
||||
{
|
||||
return replaceWithUndefinedInPlace();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -137,7 +137,7 @@ bool ExpressionNode::isOfType(Type * types, int length) const {
|
||||
}
|
||||
|
||||
Expression ExpressionNode::getUnit() const {
|
||||
return Undefined::Builder();
|
||||
return Expression();
|
||||
}
|
||||
|
||||
void ExpressionNode::setChildrenInPlace(Expression other) {
|
||||
|
||||
@@ -264,13 +264,13 @@ Expression Multiplication::getUnit() const {
|
||||
int resultChildrenCount = 0;
|
||||
for (int i = 0; i < childrenCount; i++) {
|
||||
Expression currentUnit = childAtIndex(i).getUnit();
|
||||
if (!currentUnit.isUndefined()) {
|
||||
if (!currentUnit.isUninitialized()) {
|
||||
result.addChildAtIndexInPlace(currentUnit, resultChildrenCount, resultChildrenCount);
|
||||
resultChildrenCount++;
|
||||
}
|
||||
}
|
||||
if (resultChildrenCount == 0) {
|
||||
return Undefined::Builder();
|
||||
return Expression();
|
||||
}
|
||||
return std::move(result);
|
||||
}
|
||||
|
||||
@@ -987,7 +987,7 @@ Expression Power::getUnit() const {
|
||||
return clone();
|
||||
}
|
||||
Expression baseUnit = childAtIndex(0).getUnit();
|
||||
if (baseUnit.isUndefined()) {
|
||||
if (baseUnit.isUninitialized()) {
|
||||
return baseUnit;
|
||||
}
|
||||
return Power::Builder(baseUnit, childAtIndex(1).clone());
|
||||
|
||||
@@ -42,7 +42,7 @@ Expression UnitConvert::shallowReduce(ExpressionNode::ReductionContext reduction
|
||||
reductionContext.target(),
|
||||
ExpressionNode::SymbolicComputation::ReplaceAllSymbolsWithUndefinedAndReplaceUnits);
|
||||
Expression unit = childAtIndex(1).clone().reduce(reductionContextWithUnits).getUnit();
|
||||
if (unit.isUndefined()) {
|
||||
if (unit.isUninitialized()) {
|
||||
// There is no unit on the right
|
||||
return replaceWithUndefinedInPlace();
|
||||
}
|
||||
|
||||
@@ -378,7 +378,7 @@ void assert_reduced_expression_unit(const char * expression, const char * unit,
|
||||
Expression u2 = parse_expression(unit, &globalContext, false);
|
||||
u2 = u2.reduce(redContext);
|
||||
u2 = u2.getUnit();
|
||||
quiz_assert_print_if_failure(u1.isIdenticalTo(u2), expression);
|
||||
quiz_assert_print_if_failure(u1.isUninitialized() == u2.isUninitialized() && (u1.isUninitialized() || u1.isIdenticalTo(u2)), expression);
|
||||
}
|
||||
|
||||
QUIZ_CASE(poincare_properties_get_unit) {
|
||||
|
||||
Reference in New Issue
Block a user