mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-03-23 15:50:49 +01:00
[poincare] Implement comparison on decimal
Change-Id: I87cd42d9b1bbae0e0bb68cd2dcd6449dee9910a5
This commit is contained in:
@@ -17,10 +17,13 @@ public:
|
||||
static Integer mantissa(const char * integralPart, int integralPartLength, const char * fractionalPart, int fractionalPartLength, bool negative);
|
||||
Decimal(Integer mantissa, int exponent);
|
||||
Decimal(double f);
|
||||
int exponent() const { return m_exponent; }
|
||||
Integer mantissa() const { return m_mantissa; }
|
||||
// Expression subclassing
|
||||
Type type() const override;
|
||||
Expression * clone() const override;
|
||||
int writeTextInBuffer(char * buffer, int bufferSize) const override;
|
||||
Sign sign() const override { return m_mantissa.isNegative() ? Sign::Negative : Sign::Positive; }
|
||||
private:
|
||||
int numberOfDigitsInMantissaWithoutSign() const;
|
||||
/* Comparison */
|
||||
|
||||
@@ -228,9 +228,25 @@ Expression * Decimal::shallowBeautify(Context & context, AngleUnit angleUnit) {
|
||||
}
|
||||
|
||||
int Decimal::simplificationOrderSameType(const Expression * e) const {
|
||||
// We should not get there are decimal are turned into Rational before simplification
|
||||
assert(false);
|
||||
return 0;
|
||||
assert(e->type() == Type::Decimal);
|
||||
const Decimal * other = static_cast<const Decimal *>(e);
|
||||
if (sign() == Sign::Negative && other->sign() == Sign::Positive) {
|
||||
return -1;
|
||||
}
|
||||
if (sign() == Sign::Positive && other->sign() == Sign::Negative) {
|
||||
return 1;
|
||||
}
|
||||
assert(sign() == other->sign());
|
||||
int unsignedComparison = 0;
|
||||
if (exponent() < other->exponent()) {
|
||||
unsignedComparison = -1;
|
||||
} else if (exponent() > other->exponent()) {
|
||||
unsignedComparison = 1;
|
||||
} else {
|
||||
assert(exponent() == other->exponent());
|
||||
unsignedComparison = Integer::NaturalOrder(mantissa(), other->mantissa());
|
||||
}
|
||||
return ((int)sign())*unsignedComparison;
|
||||
}
|
||||
|
||||
int Decimal::numberOfDigitsInMantissaWithoutSign() const {
|
||||
|
||||
Reference in New Issue
Block a user