Numworks Epsilon  1.4.1
Graphing Calculator Operating System
sine.cpp
Go to the documentation of this file.
1 #include <poincare/sine.h>
4 #include <poincare/complex.h>
6 #include <poincare/symbol.h>
8 #include <ion.h>
9 extern "C" {
10 #include <assert.h>
11 }
12 #include <cmath>
13 
14 namespace Poincare {
15 
18 }
19 
21  Sine * a = new Sine(m_operands, true);
22  return a;
23 }
24 
25 float Sine::characteristicXRange(Context & context, AngleUnit angleUnit) const {
26  return Trigonometry::characteristicXRange(this, context, angleUnit);
27 }
28 
29 Expression * Sine::shallowReduce(Context& context, AngleUnit angleUnit) {
30  Expression * e = Expression::shallowReduce(context, angleUnit);
31  if (e != this) {
32  return e;
33  }
34 #if MATRIX_EXACT_REDUCING
35  Expression * op = editableOperand(0);
36  if (op->type() == Type::Matrix) {
37  return SimplificationEngine::map(this, context, angleUnit);
38  }
39 #endif
40  return Trigonometry::shallowReduceDirectFunction(this, context, angleUnit);
41 }
42 
43 template<typename T>
45  if (c.b() == 0) {
46  T input = c.a();
47  if (angleUnit == AngleUnit::Degree) {
48  input *= M_PI/180;
49  }
50  T result = std::sin(input);
51  /* Cheat: see comment in cosine.cpp
52  * We cheat to avoid returning sin(Pi) = epsilon */
53  if (input != 0 && std::fabs(result/input) <= epsilon<T>()) {
54  return Complex<T>::Float(0);
55  }
56  return Complex<T>::Float(result);
57  }
58  Complex<T> arg = Complex<T>::Cartesian(-c.b(), c.a());
61 }
62 
63 }
static float characteristicXRange(const Expression *e, Context &context, Expression::AngleUnit angleUnit)
Type type() const override
Definition: sine.cpp:16
static Complex< T > Cartesian(T a, T b)
Definition: complex.cpp:28
Expression * clone() const override
Definition: sine.cpp:20
friend class Sine
Definition: expression.h:27
#define M_PI
Definition: math.h:17
#define T(x)
Definition: events.cpp:26
#define fabs(x)
Definition: math.h:178
c(generic_all_nodes)
Expression * editableOperand(int i)
Definition: expression.h:176
#define sin(x)
Definition: math.h:194
static Complex< T > computeOnComplex(const Complex< T > c, AngleUnit angleUnit)
const Expression * m_operands[T]
#define sinh(x)
Definition: math.h:195
static Expression * shallowReduceDirectFunction(Expression *e, Context &context, Expression::AngleUnit angleUnit)
static Complex< T > Float(T x)
Definition: complex.cpp:23
static Complex< T > compute(const Complex< T > c, const Complex< T > d)
static Complex< T > computeOnComplex(const Complex< T > c, AngleUnit angleUnit=AngleUnit::Radian)
Definition: sine.cpp:44