mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-03-19 05:40:38 +01:00
27 lines
672 B
C++
27 lines
672 B
C++
#include <poincare/fraction.h>
|
|
#include <string.h>
|
|
#include "layout/fraction_layout.h"
|
|
|
|
Fraction::Fraction(Expression * numerator, Expression * denominator) :
|
|
m_numerator(numerator),
|
|
m_denominator(denominator) {
|
|
}
|
|
|
|
Fraction::~Fraction() {
|
|
delete m_denominator;
|
|
delete m_numerator;
|
|
}
|
|
|
|
ExpressionLayout * Fraction::createLayout(ExpressionLayout * parent) {
|
|
return new FractionLayout(parent, m_numerator, m_denominator);
|
|
}
|
|
|
|
float Fraction::approximate(Context& context) {
|
|
// TODO: handle division by zero
|
|
return m_numerator->approximate(context)/m_denominator->approximate(context);
|
|
}
|
|
|
|
Expression::Type Fraction::type() {
|
|
return Expression::Type::Fraction;
|
|
}
|