mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-03-28 18:20:14 +01:00
[poincare] Create a class n_context
Change-Id: Icce8f8fe79c07e73587d8c0563e930c1b1e6b308
This commit is contained in:
@@ -23,6 +23,7 @@ objs += $(addprefix poincare/src/,\
|
||||
logarithm.o\
|
||||
matrix.o\
|
||||
matrix_data.o\
|
||||
n_context.o\
|
||||
nth_root.o\
|
||||
opposite.o\
|
||||
parenthesis.o\
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
#include <poincare/logarithm.h>
|
||||
#include <poincare/matrix.h>
|
||||
#include <poincare/matrix_data.h>
|
||||
#include <poincare/n_context.h>
|
||||
#include <poincare/nth_root.h>
|
||||
#include <poincare/opposite.h>
|
||||
#include <poincare/parenthesis.h>
|
||||
|
||||
17
poincare/include/poincare/n_context.h
Normal file
17
poincare/include/poincare/n_context.h
Normal file
@@ -0,0 +1,17 @@
|
||||
#ifndef POINCARE_N_CONTEXT_H
|
||||
#define POINCARE_N_CONTEXT_H
|
||||
|
||||
#include <poincare/context.h>
|
||||
#include <poincare/float.h>
|
||||
|
||||
class NContext : public Context {
|
||||
public:
|
||||
NContext(Context * parentContext = nullptr);
|
||||
void setExpressionForSymbolName(Expression * expression, const Symbol * symbol) override;
|
||||
const Expression * expressionForSymbol(const Symbol * symbol) override;
|
||||
private:
|
||||
Float m_nValue;
|
||||
Context * m_parentContext;
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -1,5 +1,5 @@
|
||||
#ifndef POINCARE_LOCAL_CONTEXT_H
|
||||
#define POINCARE_LOCAL_CONTEXT_H
|
||||
#ifndef POINCARE_X_CONTEXT_H
|
||||
#define POINCARE_X_CONTEXT_H
|
||||
|
||||
#include <poincare/context.h>
|
||||
#include <poincare/float.h>
|
||||
|
||||
24
poincare/src/n_context.cpp
Normal file
24
poincare/src/n_context.cpp
Normal file
@@ -0,0 +1,24 @@
|
||||
#include <poincare/n_context.h>
|
||||
|
||||
NContext::NContext(::Context * parentContext) :
|
||||
m_nValue(Float(0.0f)),
|
||||
m_parentContext(parentContext)
|
||||
{
|
||||
}
|
||||
|
||||
void NContext::setExpressionForSymbolName(Expression * expression, const Symbol * symbol) {
|
||||
if (symbol->name() == 'n') {
|
||||
m_nValue = Float((int)expression->approximate(*m_parentContext));
|
||||
} else {
|
||||
m_parentContext->setExpressionForSymbolName(expression, symbol);
|
||||
}
|
||||
}
|
||||
|
||||
const Expression * NContext::expressionForSymbol(const Symbol * symbol) {
|
||||
if (symbol->name() == 'n') {
|
||||
return &m_nValue;
|
||||
} else {
|
||||
return m_parentContext->expressionForSymbol(symbol);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user