#include #include #include #include "layout/nth_root_layout.h" extern "C" { #include } #include namespace Poincare { SquareRoot::SquareRoot() : Function("squareRoot") { } Expression::Type SquareRoot::type() const { return Type::SquareRoot; } Expression * SquareRoot::cloneWithDifferentOperands(Expression** newOperands, int numberOfOperands, bool cloneOperands) const { assert(newOperands != nullptr); SquareRoot * sr = new SquareRoot(); sr->setArgument(newOperands, numberOfOperands, cloneOperands); return sr; } ExpressionLayout * SquareRoot::privateCreateLayout(FloatDisplayMode floatDisplayMode, ComplexFormat complexFormat) const { assert(floatDisplayMode != FloatDisplayMode::Default); assert(complexFormat != ComplexFormat::Default); return new NthRootLayout(m_args[0]->createLayout(floatDisplayMode, complexFormat),nullptr); } template Complex SquareRoot::templatedComputeComplex(const Complex c) const { if (c.b() == 0 && c.a() >= 0) { return Complex::Float(std::sqrt(c.a())); } return Power::compute(c, Complex::Float(0.5)); } }