tangent.cpp
1.15 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/tangent.h>
#include <poincare/complex.h>
#include <poincare/sine.h>
#include <poincare/cosine.h>
#include <poincare/fraction.h>
#include <poincare/multiplication.h>
#include <poincare/hyperbolic_tangent.h>
extern "C" {
#include <assert.h>
}
#include <cmath>
namespace Poincare {
Tangent::Tangent() :
Function("tan")
{
}
Expression * Tangent::cloneWithDifferentOperands(Expression** newOperands,
int numberOfOperands, bool cloneOperands) const {
assert(newOperands != nullptr);
Tangent * t = new Tangent();
t->setArgument(newOperands, numberOfOperands, cloneOperands);
return t;
}
Expression::Type Tangent::type() const {
return Expression::Type::Tangent;
}
template<typename T>
Complex<T> Tangent::templatedComputeComplex(const Complex<T> c, AngleUnit angleUnit) const {
Complex<T> result = Fraction::compute(Sine::compute(c, angleUnit), Cosine::compute(c, angleUnit));
if (!std::isnan(result.a()) && !std::isnan(result.b())) {
return result;
}
Complex<T> tanh = HyperbolicTangent::compute(Multiplication::compute(Complex<T>::Cartesian(0, -1), c));
return Multiplication::compute(Complex<T>::Cartesian(0, 1), tanh);
}
}