mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-03-18 21:30:38 +01:00
[poincare] Improve logarithm layout
Change-Id: I0bd84672b5e24389308e7d1fd8609056f25cf2d4
This commit is contained in:
@@ -21,7 +21,6 @@ public:
|
||||
protected:
|
||||
Expression ** m_args;
|
||||
int m_numberOfArguments;
|
||||
private:
|
||||
const char * m_name;
|
||||
};
|
||||
|
||||
|
||||
@@ -10,6 +10,7 @@ public:
|
||||
Type type() const override;
|
||||
Expression * cloneWithDifferentOperands(Expression ** newOperands,
|
||||
int numberOfOperands, bool cloneOperands = true) const override;
|
||||
ExpressionLayout * createLayout() const override;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -2,7 +2,12 @@
|
||||
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/subscript_layout.h"
|
||||
|
||||
Logarithm::Logarithm() :
|
||||
Function("log")
|
||||
@@ -28,3 +33,13 @@ float Logarithm::approximate(Context& context) const {
|
||||
}
|
||||
return log10f(m_args[1]->approximate(context))/log10f(m_args[0]->approximate(context));
|
||||
}
|
||||
|
||||
ExpressionLayout * Logarithm::createLayout() const {
|
||||
if (m_numberOfArguments == 1) {
|
||||
return Function::createLayout();
|
||||
}
|
||||
ExpressionLayout ** childrenLayouts = (ExpressionLayout **)malloc(2*sizeof(ExpressionLayout *));
|
||||
childrenLayouts[0] = new SubscriptLayout(new StringLayout(m_name, strlen(m_name)), m_args[0]->createLayout());
|
||||
childrenLayouts[1] = new ParenthesisLayout(m_args[1]->createLayout());
|
||||
return new HorizontalLayout(childrenLayouts, 2);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user