#include #include #include #include extern "C" { #include } #include namespace Poincare { Sine::Sine() : Function("sin") { } Expression::Type Sine::type() const { return Expression::Type::Sine; } Expression * Sine::cloneWithDifferentOperands(Expression** newOperands, int numberOfOperands, bool cloneOperands) const { assert(newOperands != nullptr); Sine * s = new Sine(); s->setArgument(newOperands, numberOfOperands, cloneOperands); return s; } template Complex Sine::compute(const Complex c, AngleUnit angleUnit) { if (c.b() == 0) { T input = c.a(); if (angleUnit == AngleUnit::Degree) { input *= M_PI/180; } T result = std::sin(input); /* Cheat: see comment in cosine.cpp * We cheat to avoid returning sin(Pi) = epsilon */ if (input != 0 && std::fabs(result/input) <= epsilon()) { return Complex::Float(0); } return Complex::Float(result); } Complex arg = Complex::Cartesian(-c.b(), c.a()); Complex sinh = HyperbolicSine::compute(arg); return Multiplication::compute(Complex::Cartesian(0, -1), sinh); } }