division_quotient.cpp
1.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include <poincare/division_quotient.h>
extern "C" {
#include <assert.h>
}
#include <cmath>
namespace Poincare {
DivisionQuotient::DivisionQuotient() :
Function("quo", 2)
{
}
Expression::Type DivisionQuotient::type() const {
return Type::DivisionQuotient;
}
Expression * DivisionQuotient::cloneWithDifferentOperands(Expression** newOperands,
int numberOfOperands, bool cloneOperands) const {
assert(newOperands != nullptr);
DivisionQuotient * dq = new DivisionQuotient();
dq->setArgument(newOperands, numberOfOperands, cloneOperands);
return dq;
}
template<typename T>
Evaluation<T> * DivisionQuotient::templatedEvaluate(Context& context, AngleUnit angleUnit) const {
Evaluation<T> * f1Input = m_args[0]->evaluate<T>(context, angleUnit);
Evaluation<T> * f2Input = m_args[1]->evaluate<T>(context, angleUnit);
T f1 = f1Input->toScalar();
T f2 = f2Input->toScalar();
delete f1Input;
delete f2Input;
if (std::isnan(f1) || std::isnan(f2) || f1 != (int)f1 || f2 != (int)f2) {
return new Complex<T>(Complex<T>::Float(NAN));
}
return new Complex<T>(Complex<T>::Float(std::floor(f1/f2)));
}
}