Files
Upsilon/poincare/src/absolute_value.cpp
Émilie Feral 2cacda6d20 [poincare] Change isPositive method by int sign()
Change-Id: I575e7a48c4d5b82c93094f772bbafd41913646cc
2017-10-10 15:56:41 +02:00

39 lines
1002 B
C++

#include <poincare/absolute_value.h>
#include <poincare/complex.h>
#include "layout/absolute_value_layout.h"
extern "C" {
#include <assert.h>
}
#include <cmath>
namespace Poincare {
Expression::Type AbsoluteValue::type() const {
return Type::AbsoluteValue;
}
Expression * AbsoluteValue::clone() const {
AbsoluteValue * a = new AbsoluteValue(m_operands, true);
return a;
}
void AbsoluteValue::immediateSimplify() {
if (operand(0)->sign() > 0) {
replaceWith(const_cast<Expression *>(operand(0)), true);
}
}
template<typename T>
Complex<T> AbsoluteValue::computeOnComplex(const Complex<T> c, AngleUnit angleUnit) {
return Complex<T>::Float(c.r());
}
ExpressionLayout * AbsoluteValue::privateCreateLayout(FloatDisplayMode floatDisplayMode, ComplexFormat complexFormat) const {
assert(floatDisplayMode != FloatDisplayMode::Default);
assert(complexFormat != ComplexFormat::Default);
return new AbsoluteValueLayout(operand(0)->createLayout(floatDisplayMode, complexFormat));
}
}