[poincare] Decimal: templatize Decimal constructor on float/double

This commit is contained in:
Émilie Feral
2018-04-13 15:53:18 +02:00
parent 9fcb22ef8e
commit b0d94f6ead
5 changed files with 14 additions and 10 deletions

View File

@@ -47,14 +47,14 @@ Expression * CubicModel::simplifiedExpression(double * modelCoefficients, Poinca
new Decimal(a),
new Power(
new Symbol('x'),
new Decimal(3),
new Decimal(3.0),
false),
false);
Expression * bx2Expression = new Multiplication(
new Decimal(b),
new Power(
new Symbol('x'),
new Decimal(2),
new Decimal(2.0),
false),
false);
Expression * cxExpression = new Multiplication(

View File

@@ -38,7 +38,7 @@ Expression * QuadraticModel::simplifiedExpression(double * modelCoefficients, Po
new Decimal(a),
new Power(
new Symbol('x'),
new Decimal(2),
new Decimal(2.0),
false),
false);
Expression * bxExpression = new Multiplication(

View File

@@ -56,21 +56,21 @@ Expression * QuarticModel::simplifiedExpression(double * modelCoefficients, Poin
new Decimal(a),
new Power(
new Symbol('x'),
new Decimal(4),
new Decimal(4.0),
false),
false);
Expression * bx3Expression = new Multiplication(
new Decimal(b),
new Power(
new Symbol('x'),
new Decimal(3),
new Decimal(3.0),
false),
false);
Expression * cx2Expression = new Multiplication(
new Decimal(c),
new Power(
new Symbol('x'),
new Decimal(2),
new Decimal(2.0),
false),
false);
Expression * dxExpression = new Multiplication(

View File

@@ -16,7 +16,7 @@ public:
static int exponent(const char * integralPart, int integralPartLength, const char * fractionalPart, int fractionalPartLength, const char * exponent, int exponentLength, bool exponentNegative);
static Integer mantissa(const char * integralPart, int integralPartLength, const char * fractionalPart, int fractionalPartLength, bool negative);
Decimal(Integer mantissa, int exponent);
Decimal(double f);
template <typename T> Decimal(T f);
int exponent() const { return m_exponent; }
Integer mantissa() const { return m_mantissa; }
// Expression subclassing

View File

@@ -75,9 +75,10 @@ Decimal::Decimal(Integer mantissa, int exponent) :
{
}
Decimal::Decimal(double f) {
m_exponent = IEEE754<double>::exponentBase10(f);
int64_t mantissaf = std::round(f * std::pow(10.0, -m_exponent+PrintFloat::k_numberOfStoredSignificantDigits+1));
template <typename T>
Decimal::Decimal(T f) {
m_exponent = IEEE754<T>::exponentBase10(f);
int64_t mantissaf = std::round((double)f * std::pow((double)10.0, (double)(-m_exponent+PrintFloat::k_numberOfStoredSignificantDigits+1)));
m_mantissa = Integer(mantissaf);
}
@@ -275,4 +276,7 @@ int Decimal::simplificationOrderSameType(const Expression * e, bool canBeInterru
return ((int)sign())*unsignedComparison;
}
template Decimal::Decimal(double);
template Decimal::Decimal(float);
}