mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-03-26 01:00:50 +01:00
46 lines
1.5 KiB
C++
46 lines
1.5 KiB
C++
#include <poincare/logarithm.h>
|
|
extern "C" {
|
|
#include <assert.h>
|
|
#include <math.h>
|
|
#include <stdlib.h>
|
|
}
|
|
#include "layout/horizontal_layout.h"
|
|
#include "layout/parenthesis_layout.h"
|
|
#include "layout/string_layout.h"
|
|
#include "layout/baseline_relative_layout.h"
|
|
|
|
Logarithm::Logarithm() :
|
|
Function("log")
|
|
{
|
|
}
|
|
|
|
Expression::Type Logarithm::type() const {
|
|
return Type::Logarithm;
|
|
}
|
|
|
|
Expression * Logarithm::cloneWithDifferentOperands(Expression** newOperands,
|
|
int numberOfOperands, bool cloneOperands) const {
|
|
assert(numberOfOperands == 1 || numberOfOperands == 2);
|
|
assert(newOperands != nullptr);
|
|
Logarithm * l = new Logarithm();
|
|
l->setArgument(newOperands, numberOfOperands, cloneOperands);
|
|
return l;
|
|
}
|
|
|
|
float Logarithm::approximate(Context& context) const {
|
|
if (m_numberOfArguments == 1) {
|
|
return log10f(m_args[0]->approximate(context));
|
|
}
|
|
return log10f(m_args[1]->approximate(context))/log10f(m_args[0]->approximate(context));
|
|
}
|
|
|
|
ExpressionLayout * Logarithm::createLayout(DisplayMode displayMode) const {
|
|
if (m_numberOfArguments == 1) {
|
|
return Function::createLayout(displayMode);
|
|
}
|
|
ExpressionLayout ** childrenLayouts = (ExpressionLayout **)malloc(2*sizeof(ExpressionLayout *));
|
|
childrenLayouts[0] = new BaselineRelativeLayout(new StringLayout(m_name, strlen(m_name)), m_args[0]->createLayout(displayMode), BaselineRelativeLayout::Type::Subscript);
|
|
childrenLayouts[1] = new ParenthesisLayout(m_args[1]->createLayout(displayMode));
|
|
return new HorizontalLayout(childrenLayouts, 2);
|
|
}
|