[poincare/expression_node] Added Double type

Float<float> and Float<double> used to share the same expression type
(Float), and the distinction was made by comparing their size. However,
due to padding, their size could be the same, leading to some issues :
  - On the simulator, in Calculation, type 1_mm^3 and go to the
    additional outputs. One of the results would be -0.0003081979_µm^3.

Change-Id: Ic8f9328bf462104776fbab636c34d0d152cd7e58
This commit is contained in:
Gabriel Ozouf
2020-07-17 10:15:25 +02:00
committed by Émilie Feral
parent 1e82d5012b
commit 891366c51d
5 changed files with 7 additions and 9 deletions

View File

@@ -30,6 +30,7 @@ public:
Rational,
BasedInteger,
Decimal,
Double,
Float,
Infinity,
Multiplication,

View File

@@ -36,7 +36,7 @@ public:
#endif
// Properties
Type type() const override { return Type::Float; }
Type type() const override { return (sizeof(T) == sizeof(float)) ? Type::Float : Type::Double; }
Sign sign(Context * context) const override { return m_value < 0 ? Sign::Negative : Sign::Positive; }
Expression setSign(Sign s, ReductionContext reductionContext) override;
int simplificationOrderSameType(const ExpressionNode * e, bool ascending, bool canBeInterrupted, bool ignoreParentheses) const override;

View File

@@ -167,7 +167,7 @@ bool Expression::deepIsMatrix(Context * context) const {
}
bool Expression::IsApproximate(const Expression e, Context * context) {
return e.type() == ExpressionNode::Type::Decimal || e.type() == ExpressionNode::Type::Float;
return e.type() == ExpressionNode::Type::Decimal || e.type() == ExpressionNode::Type::Float || e.type() == ExpressionNode::Type::Double;
}
bool Expression::IsRandom(const Expression e, Context * context) {

View File

@@ -18,7 +18,7 @@ int FloatNode<T>::simplificationOrderSameType(const ExpressionNode * e, bool asc
if (!ascending) {
return e->simplificationOrderSameType(this, true, canBeInterrupted, ignoreParentheses);
}
assert(e->type() == ExpressionNode::Type::Float);
assert((e->type() == ExpressionNode::Type::Float && sizeof(T) == sizeof(float)) || (e->type() == ExpressionNode::Type::Double && sizeof(T) == sizeof(double)));
const FloatNode<T> * other = static_cast<const FloatNode<T> *>(e);
if (value() < other->value()) {
return -1;

View File

@@ -25,12 +25,9 @@ double NumberNode::doubleApproximation() const {
assert(Number(this).sign() == Sign::Negative || Number(this).sign() == Sign::Positive);
return Number(this).sign() == Sign::Negative ? -INFINITY : INFINITY;
case Type::Float:
if (size() == sizeof(FloatNode<float>)) {
return static_cast<const FloatNode<float> *>(this)->value();
} else {
assert(size() == sizeof(FloatNode<double>));
return static_cast<const FloatNode<double> *>(this)->value();
}
return static_cast<const FloatNode<float> *>(this)->value();
case Type::Double:
return static_cast<const FloatNode<double> *>(this)->value();
case Type::Rational:
return static_cast<const RationalNode *>(this)->templatedApproximate<double>();
case Type::BasedInteger: