mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-01-19 00:37:25 +01:00
[poincare] Change names: approximate->approximateToScalar
Change-Id: I701451b35909bb577dd729e0ea76a405b9543f23
This commit is contained in:
@@ -20,7 +20,7 @@ double CartesianFunction::approximateDerivative(double x, Poincare::Context * co
|
||||
Poincare::Complex<double> abscissa = Poincare::Complex<double>::Float(x);
|
||||
Poincare::Expression * args[2] = {expression(), &abscissa};
|
||||
Poincare::Derivative derivative(args, true);
|
||||
return derivative.approximate<double>(*context);
|
||||
return derivative.approximateToScalar<double>(*context);
|
||||
}
|
||||
|
||||
char CartesianFunction::symbol() const {
|
||||
|
||||
@@ -218,7 +218,7 @@ bool CalculationController::textFieldShouldFinishEditing(TextField * textField,
|
||||
bool CalculationController::textFieldDidFinishEditing(TextField * textField, const char * text, Ion::Events::Event event) {
|
||||
App * probaApp = (App *)app();
|
||||
Context * globalContext = probaApp->container()->globalContext();
|
||||
double floatBody = Expression::approximate<double>(text, *globalContext);
|
||||
double floatBody = Expression::approximateToScalar<double>(text, *globalContext);
|
||||
if (std::isnan(floatBody) || std::isinf(floatBody)) {
|
||||
app()->displayWarning(I18n::Message::UndefinedValue);
|
||||
return false;
|
||||
|
||||
@@ -282,18 +282,18 @@ T Sequence::templatedEvaluateAtAbscissa(T x, Poincare::Context * context) const
|
||||
}
|
||||
if (n == 0) {
|
||||
setBufferIndexValue<T>(0,0);
|
||||
setBufferValue(firstInitialConditionExpression()->approximate<T>(*context), 0);
|
||||
setBufferValue(firstInitialConditionExpression()->approximateToScalar<T>(*context), 0);
|
||||
return bufferValue<T>(0);
|
||||
}
|
||||
LocalContext<T> subContext = LocalContext<T>(context);
|
||||
Poincare::Symbol nSymbol(symbol());
|
||||
int start = indexBuffer<T>(0) < 0 || indexBuffer<T>(0) > n ? 0 : indexBuffer<T>(0);
|
||||
T un = indexBuffer<T>(0) < 0 || indexBuffer<T>(0) > n ? firstInitialConditionExpression()->approximate<T>(*context) : bufferValue<T>(0);
|
||||
T un = indexBuffer<T>(0) < 0 || indexBuffer<T>(0) > n ? firstInitialConditionExpression()->approximateToScalar<T>(*context) : bufferValue<T>(0);
|
||||
for (int i = start; i < n; i++) {
|
||||
subContext.setValueForSequenceRank(un, name(), 0);
|
||||
Poincare::Complex<T> e = Poincare::Complex<T>::Float(i);
|
||||
subContext.setExpressionForSymbolName(&e, &nSymbol, subContext);
|
||||
un = expression()->approximate<T>(subContext);
|
||||
un = expression()->approximateToScalar<T>(subContext);
|
||||
}
|
||||
setBufferValue(un, 0);
|
||||
setBufferIndexValue<T>(n, 0);
|
||||
@@ -305,27 +305,27 @@ T Sequence::templatedEvaluateAtAbscissa(T x, Poincare::Context * context) const
|
||||
return NAN;
|
||||
}
|
||||
if (n == 0) {
|
||||
return firstInitialConditionExpression()->approximate<T>(*context);
|
||||
return firstInitialConditionExpression()->approximateToScalar<T>(*context);
|
||||
}
|
||||
if (n == 1) {
|
||||
setBufferIndexValue<T>(0, 0);
|
||||
setBufferValue(firstInitialConditionExpression()->approximate<T>(*context), 0);
|
||||
setBufferValue(firstInitialConditionExpression()->approximateToScalar<T>(*context), 0);
|
||||
setBufferIndexValue<T>(1, 1);
|
||||
setBufferValue(secondInitialConditionExpression()->approximate<T>(*context), 1);
|
||||
setBufferValue(secondInitialConditionExpression()->approximateToScalar<T>(*context), 1);
|
||||
return bufferValue<T>(1);
|
||||
}
|
||||
LocalContext<T> subContext = LocalContext<T>(context);
|
||||
Poincare::Symbol nSymbol(symbol());
|
||||
int start = indexBuffer<T>(0) >= 0 && indexBuffer<T>(0) < n && indexBuffer<T>(1) > 0 && indexBuffer<T>(1) <= n && indexBuffer<T>(0) + 1 == indexBuffer<T>(1) ? indexBuffer<T>(0) : 0;
|
||||
T un = indexBuffer<T>(0) >= 0 && indexBuffer<T>(0) < n && indexBuffer<T>(1) > 0 && indexBuffer<T>(1) <= n && indexBuffer<T>(0) + 1 == indexBuffer<T>(1) ? bufferValue<T>(0) : firstInitialConditionExpression()->approximate<T>(*context);
|
||||
T un1 = indexBuffer<T>(0) >= 0 && indexBuffer<T>(0) < n && indexBuffer<T>(1) > 0 && indexBuffer<T>(1) <= n && indexBuffer<T>(0) + 1 == indexBuffer<T>(1) ? bufferValue<T>(1) : secondInitialConditionExpression()->approximate<T>(*context);
|
||||
T un = indexBuffer<T>(0) >= 0 && indexBuffer<T>(0) < n && indexBuffer<T>(1) > 0 && indexBuffer<T>(1) <= n && indexBuffer<T>(0) + 1 == indexBuffer<T>(1) ? bufferValue<T>(0) : firstInitialConditionExpression()->approximateToScalar<T>(*context);
|
||||
T un1 = indexBuffer<T>(0) >= 0 && indexBuffer<T>(0) < n && indexBuffer<T>(1) > 0 && indexBuffer<T>(1) <= n && indexBuffer<T>(0) + 1 == indexBuffer<T>(1) ? bufferValue<T>(1) : secondInitialConditionExpression()->approximateToScalar<T>(*context);
|
||||
for (int i = start; i < n-1; i++) {
|
||||
subContext.setValueForSequenceRank(un, name(), 0);
|
||||
subContext.setValueForSequenceRank(un1, name(), 1);
|
||||
Poincare::Complex<T> e = Poincare::Complex<T>::Float(i);
|
||||
subContext.setExpressionForSymbolName(&e, &nSymbol, subContext);
|
||||
un = un1;
|
||||
un1 = expression()->approximate<T>(subContext);
|
||||
un1 = expression()->approximateToScalar<T>(subContext);
|
||||
}
|
||||
setBufferValue(un, 0);
|
||||
setBufferIndexValue<T>(n-1, 0);
|
||||
|
||||
@@ -24,7 +24,7 @@ bool EditableCellTableViewController::textFieldShouldFinishEditing(TextField * t
|
||||
bool EditableCellTableViewController::textFieldDidFinishEditing(TextField * textField, const char * text, Ion::Events::Event event) {
|
||||
AppsContainer * appsContainer = ((TextFieldDelegateApp *)app())->container();
|
||||
Context * globalContext = appsContainer->globalContext();
|
||||
double floatBody = Expression::approximate<double>(text, *globalContext);
|
||||
double floatBody = Expression::approximateToScalar<double>(text, *globalContext);
|
||||
if (std::isnan(floatBody) || std::isinf(floatBody)) {
|
||||
app()->displayWarning(I18n::Message::UndefinedValue);
|
||||
return false;
|
||||
|
||||
@@ -119,7 +119,7 @@ bool FloatParameterController::textFieldShouldFinishEditing(TextField * textFiel
|
||||
bool FloatParameterController::textFieldDidFinishEditing(TextField * textField, const char * text, Ion::Events::Event event) {
|
||||
AppsContainer * appsContainer = ((TextFieldDelegateApp *)app())->container();
|
||||
Context * globalContext = appsContainer->globalContext();
|
||||
double floatBody = Expression::approximate<double>(text, *globalContext);
|
||||
double floatBody = Expression::approximateToScalar<double>(text, *globalContext);
|
||||
if (std::isnan(floatBody) || std::isinf(floatBody)) {
|
||||
app()->displayWarning(I18n::Message::UndefinedValue);
|
||||
return false;
|
||||
|
||||
@@ -105,7 +105,7 @@ T Function::templatedEvaluateAtAbscissa(T x, Poincare::Context * context) const
|
||||
Poincare::Symbol xSymbol(symbol());
|
||||
Poincare::Complex<T> e = Poincare::Complex<T>::Float(x);
|
||||
variableContext.setExpressionForSymbolName(&e, &xSymbol, variableContext);
|
||||
return expression()->approximate<T>(variableContext);
|
||||
return expression()->approximateToScalar<T>(variableContext);
|
||||
}
|
||||
|
||||
void Function::tidy() {
|
||||
|
||||
@@ -214,8 +214,8 @@ public:
|
||||
* The function evaluate creates a new expression and thus mallocs memory.
|
||||
* Do not forget to delete the new expression to avoid leaking. */
|
||||
template<typename T> Expression * evaluate(Context& context, AngleUnit angleUnit = AngleUnit::Default) const;
|
||||
template<typename T> T approximate(Context& context, AngleUnit angleUnit = AngleUnit::Default) const;
|
||||
template<typename T> static T approximate(const char * text, Context& context, AngleUnit angleUnit = AngleUnit::Default);
|
||||
template<typename T> T approximateToScalar(Context& context, AngleUnit angleUnit = AngleUnit::Default) const;
|
||||
template<typename T> static T approximateToScalar(const char * text, Context& context, AngleUnit angleUnit = AngleUnit::Default);
|
||||
protected:
|
||||
/* Constructor */
|
||||
Expression() : m_parent(nullptr) {}
|
||||
|
||||
@@ -262,7 +262,7 @@ template<typename T> Expression * Expression::evaluate(Context& context, AngleUn
|
||||
}
|
||||
}
|
||||
|
||||
template<typename T> T Expression::approximate(Context& context, AngleUnit angleUnit) const {
|
||||
template<typename T> T Expression::approximateToScalar(Context& context, AngleUnit angleUnit) const {
|
||||
Expression * evaluation = evaluate<T>(context, angleUnit);
|
||||
assert(evaluation->type() == Type::Complex || evaluation->type() == Type::Matrix);
|
||||
T result = NAN;
|
||||
@@ -278,9 +278,9 @@ template<typename T> T Expression::approximate(Context& context, AngleUnit angle
|
||||
return result;
|
||||
}
|
||||
|
||||
template<typename T> T Expression::approximate(const char * text, Context& context, AngleUnit angleUnit) {
|
||||
template<typename T> T Expression::approximateToScalar(const char * text, Context& context, AngleUnit angleUnit) {
|
||||
Expression * exp = parse(text);
|
||||
T result = exp->approximate<T>(context, angleUnit);
|
||||
T result = exp->approximateToScalar<T>(context, angleUnit);
|
||||
delete exp;
|
||||
return result;
|
||||
}
|
||||
@@ -294,9 +294,9 @@ template<typename T> T Expression::epsilon() {
|
||||
|
||||
template Poincare::Expression * Poincare::Expression::evaluate<double>(Context& context, AngleUnit angleUnit) const;
|
||||
template Poincare::Expression * Poincare::Expression::evaluate<float>(Context& context, AngleUnit angleUnit) const;
|
||||
template double Poincare::Expression::approximate<double>(char const*, Poincare::Context&, Poincare::Expression::AngleUnit);
|
||||
template float Poincare::Expression::approximate<float>(char const*, Poincare::Context&, Poincare::Expression::AngleUnit);
|
||||
template double Poincare::Expression::approximate<double>(Poincare::Context&, Poincare::Expression::AngleUnit) const;
|
||||
template float Poincare::Expression::approximate<float>(Poincare::Context&, Poincare::Expression::AngleUnit) const;
|
||||
template double Poincare::Expression::approximateToScalar<double>(char const*, Poincare::Context&, Poincare::Expression::AngleUnit);
|
||||
template float Poincare::Expression::approximateToScalar<float>(char const*, Poincare::Context&, Poincare::Expression::AngleUnit);
|
||||
template double Poincare::Expression::approximateToScalar<double>(Poincare::Context&, Poincare::Expression::AngleUnit) const;
|
||||
template float Poincare::Expression::approximateToScalar<float>(Poincare::Context&, Poincare::Expression::AngleUnit) const;
|
||||
template double Poincare::Expression::epsilon<double>();
|
||||
template float Poincare::Expression::epsilon<float>();
|
||||
|
||||
@@ -60,7 +60,7 @@ void print_expression(const Expression * e, int indentationLevel) {
|
||||
break;
|
||||
case Expression::Type::Decimal:
|
||||
std::cout << "Decimal(";
|
||||
std::cout << e->approximate<double>(context, Expression::AngleUnit::Radian);
|
||||
std::cout << e->approximateToScalar<double>(context, Expression::AngleUnit::Radian);
|
||||
std::cout << ")";
|
||||
break;
|
||||
case Expression::Type::Derivative:
|
||||
|
||||
@@ -240,8 +240,8 @@ Expression * Power::shallowReduce(Context& context, AngleUnit angleUnit) {
|
||||
}
|
||||
// p^q with p, q rationals
|
||||
if (!letPowerAtRoot && operand(1)->type() == Type::Rational) {
|
||||
double p = a->approximate<double>(context, angleUnit);
|
||||
double q = operand(1)->approximate<double>(context, angleUnit);
|
||||
double p = a->approximateToScalar<double>(context, angleUnit);
|
||||
double q = operand(1)->approximateToScalar<double>(context, angleUnit);
|
||||
double approx = std::pow(std::fabs(p), std::fabs(q));
|
||||
if (std::isinf(approx) || std::isnan(approx) || std::fabs(approx)> 1E100) {
|
||||
return this;
|
||||
|
||||
@@ -22,7 +22,7 @@ Expression * Trigonometry::shallowReduceDirectFunction(Expression * e, Context&
|
||||
}
|
||||
Expression::Type correspondingType = e->type() == Expression::Type::Cosine ? Expression::Type::ArcCosine : (e->type() == Expression::Type::Sine ? Expression::Type::ArcSine : Expression::Type::ArcTangent);
|
||||
if (e->operand(0)->type() == correspondingType) {
|
||||
float trigoOp = e->operand(0)->operand(0)->approximate<float>(context, angleUnit);
|
||||
float trigoOp = e->operand(0)->operand(0)->approximateToScalar<float>(context, angleUnit);
|
||||
if (e->type() == Expression::Type::Tangent || (trigoOp >= -1.0f && trigoOp <= 1.0f)) {
|
||||
return e->replaceWith(e->editableOperand(0)->editableOperand(0), true);
|
||||
}
|
||||
@@ -83,7 +83,7 @@ bool Trigonometry::ExpressionIsEquivalentToTangent(const Expression * e) {
|
||||
Expression * Trigonometry::shallowReduceInverseFunction(Expression * e, Context& context, Expression::AngleUnit angleUnit) {
|
||||
assert(e->type() == Expression::Type::ArcCosine || e->type() == Expression::Type::ArcSine || e->type() == Expression::Type::ArcTangent);
|
||||
if (e->type() != Expression::Type::ArcTangent) {
|
||||
float approxOp = e->operand(0)->approximate<float>(context, angleUnit);
|
||||
float approxOp = e->operand(0)->approximateToScalar<float>(context, angleUnit);
|
||||
if (approxOp > 1.0f || approxOp < -1.0f) {
|
||||
return e->replaceWith(new Undefined(), true);
|
||||
}
|
||||
@@ -91,7 +91,7 @@ Expression * Trigonometry::shallowReduceInverseFunction(Expression * e, Context&
|
||||
Expression::Type correspondingType = e->type() == Expression::Type::ArcCosine ? Expression::Type::Cosine : (e->type() == Expression::Type::ArcSine ? Expression::Type::Sine : Expression::Type::Tangent);
|
||||
float pi = angleUnit == Expression::AngleUnit::Radian ? M_PI : 180;
|
||||
if (e->operand(0)->type() == correspondingType) {
|
||||
float trigoOp = e->operand(0)->operand(0)->approximate<float>(context, angleUnit);
|
||||
float trigoOp = e->operand(0)->operand(0)->approximateToScalar<float>(context, angleUnit);
|
||||
if ((e->type() == Expression::Type::ArcCosine && trigoOp >= 0.0f && trigoOp <= pi) ||
|
||||
(e->type() == Expression::Type::ArcSine && trigoOp >= -pi/2.0f && trigoOp <= pi/2.0f) ||
|
||||
(e->type() == Expression::Type::ArcTangent && trigoOp >= -pi/2.0f && trigoOp <= pi/2.0f)) {
|
||||
@@ -100,7 +100,7 @@ Expression * Trigonometry::shallowReduceInverseFunction(Expression * e, Context&
|
||||
}
|
||||
// Special case for arctan(sin(x)/cos(x))
|
||||
if (e->type() == Expression::Type::ArcTangent && ExpressionIsEquivalentToTangent(e->operand(0))) {
|
||||
float trigoOp = e->operand(0)->operand(1)->operand(0)->approximate<float>(context, angleUnit);
|
||||
float trigoOp = e->operand(0)->operand(1)->operand(0)->approximateToScalar<float>(context, angleUnit);
|
||||
if (trigoOp >= -pi/2.0f && trigoOp <= pi/2.0f) {
|
||||
return e->replaceWith(e->editableOperand(0)->editableOperand(1)->editableOperand(0), true);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user