43 m_numerator = other.m_numerator;
44 m_denominator = other.m_denominator;
48 m_numerator = other.m_numerator;
49 m_numerator = other.m_numerator;
50 m_denominator = other.m_denominator;
69 return new Rational(m_numerator, m_denominator);
86 Expression * Rational::shallowBeautify(Context & context, AngleUnit angleUnit) {
96 if (m_denominator.
isOne()) {
107 return Rational(newNumerator, newDenominator);
113 return Rational(newNumerator, newDenominator);
122 return Rational(newDenominator, newNumerator);
124 return Rational(newNumerator, newDenominator);
135 int Rational::simplificationOrderSameType(
const Expression * e,
bool canBeInterrupted)
const {
147 bool Rational::needParenthesisWithParent(
const Expression * e)
const {
148 if (m_denominator.
isOne()) {
152 return e->isOfType(types, 3);
155 ExpressionLayout * Rational::privateCreateLayout(
PrintFloat::Mode floatDisplayMode, ComplexFormat complexFormat)
const {
156 ExpressionLayout * numeratorLayout = m_numerator.
createLayout();
157 if (m_denominator.
isOne()) {
158 return numeratorLayout;
160 ExpressionLayout * denominatorLayout = m_denominator.
createLayout();
161 return new FractionLayout(numeratorLayout, denominatorLayout);
164 int Rational::writeTextInBuffer(
char * buffer,
int bufferSize,
int numberOfSignificantDigits)
const {
165 buffer[bufferSize-1] = 0;
167 if (m_denominator.
isOne()) {
170 if (numberOfChar >= bufferSize-1) {
173 buffer[numberOfChar++] =
'/';
174 numberOfChar += m_denominator.
writeTextInBuffer(buffer+numberOfChar, bufferSize-numberOfChar);
static Integer Power(const Integer &i, const Integer &j)
int writeTextInBuffer(char *buffer, int bufferSize) const
friend class Multiplication
Expression * replaceWith(Expression *newOperand, bool deleteAfterReplace=true)
static Rational Addition(const Rational &i, const Rational &j)
static Integer GCD(const Integer *i, const Integer *j)
Rational(const Integer numerator, const Integer denominator)
Rational & operator=(const Rational &other)
const Integer denominator() const
Sign sign() const override
Type type() const override
void setNegative(bool negative)
static int NaturalOrder(const Rational &i, const Rational &j)
static Integer Addition(const Integer &i, const Integer &j)
const Integer numerator() const
static int NaturalOrder(const Integer &i, const Integer &j)
static Complex< T > Float(T x)
Expression * cloneDenominator(Context &context, AngleUnit angleUnit) const override
ExpressionLayout * createLayout() const
Expression * clone() const override
static Integer Multiplication(const Integer &i, const Integer &j)
static IntegerDivision Division(const Integer &numerator, const Integer &denominator)
virtual Type type() const =0