diff --git a/apps/apps_container.cpp b/apps/apps_container.cpp index 2b038e6e5..9963aaa24 100644 --- a/apps/apps_container.cpp +++ b/apps/apps_container.cpp @@ -84,7 +84,7 @@ AppsContainer::AppsContainer() : * We just remove the circuit breaker for now. * TODO: Put the Poincare circuit breaker back on epsilon's web emulator */ #else - Poincare::Expression::setCircuitBreaker(AppsContainer::poincareCircuitBreaker); + Poincare::Expression::SetCircuitBreaker(AppsContainer::poincareCircuitBreaker); #endif Ion::Storage::sharedStorage()->setDelegate(this); } diff --git a/apps/regression/model/model.cpp b/apps/regression/model/model.cpp index f4a3e2cf6..3b287687d 100644 --- a/apps/regression/model/model.cpp +++ b/apps/regression/model/model.cpp @@ -128,8 +128,8 @@ double Model::alphaPrimeCoefficient(Store * store, int series, double * modelCoe * a'(k,k) = 2*epsilon so that the inversion method does not detect a'(k,k) * as a zero. */ result = alphaCoefficient(store, series, modelCoefficients, k, l)*(1.0+lambda); - if (std::fabs(result) < Expression::epsilon()) { - result = 2*Expression::epsilon(); + if (std::fabs(result) < Expression::Epsilon()) { + result = 2*Expression::Epsilon(); } } else { result = alphaCoefficient(store, series, modelCoefficients, l, k); diff --git a/apps/shared/poincare_helpers.h b/apps/shared/poincare_helpers.h index af2d43fa8..e401f58f5 100644 --- a/apps/shared/poincare_helpers.h +++ b/apps/shared/poincare_helpers.h @@ -48,7 +48,7 @@ template inline T ApproximateToScalar(const char * text, Poincare::Context & context) { Poincare::Preferences * preferences = Poincare::Preferences::sharedPreferences(); Poincare::Preferences::ComplexFormat complexFormat = Poincare::Expression::UpdatedComplexFormatWithTextInput(preferences->complexFormat(), text); - return Poincare::Expression::approximateToScalar(text, context, complexFormat, preferences->angleUnit()); + return Poincare::Expression::ApproximateToScalar(text, context, complexFormat, preferences->angleUnit()); } inline Poincare::Expression ParseAndSimplify(const char * text, Poincare::Context & context) { diff --git a/poincare/include/poincare/expression.h b/poincare/include/poincare/expression.h index 9fc2dd62a..4832cc711 100644 --- a/poincare/include/poincare/expression.h +++ b/poincare/include/poincare/expression.h @@ -99,7 +99,7 @@ class Expression : public TreeHandle { friend class SymbolNode; public: - static bool isExpression() { return true; } + static bool IsExpression() { return true; } /* Constructor & Destructor */ Expression() : TreeHandle() {} @@ -109,9 +109,9 @@ public: /* Circuit breaker */ typedef bool (*CircuitBreaker)(); - static void setCircuitBreaker(CircuitBreaker cb); - static bool shouldStopProcessing(); - static void setInterruption(bool interrupt); + static void SetCircuitBreaker(CircuitBreaker cb); + static bool ShouldStopProcessing(); + static void SetInterruption(bool interrupt); /* Hierarchy */ Expression childAtIndex(int i) const; @@ -196,10 +196,10 @@ public: /* Approximation Helper */ // These methods reset the sApproximationEncounteredComplex flag. They should not be use to implement node approximation - template static U epsilon(); + template static U Epsilon(); template Expression approximate(Context& context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit) const; template U approximateToScalar(Context& context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit) const; - template static U approximateToScalar(const char * text, Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit); + template static U ApproximateToScalar(const char * text, Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit); template U approximateWithValueForSymbol(const char * symbol, U x, Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit) const; /* Expression roots/extrema solver */ struct Coordinate2D { @@ -247,7 +247,7 @@ protected: * ie, you can write: 'Rational a(2); AbsoluteValue b(a);' * */ - assert(T::isExpression()); + assert(T::IsExpression()); static_assert(sizeof(T) == sizeof(Expression), "Size mismatch"); return *reinterpret_cast(const_cast(this)); } @@ -309,9 +309,9 @@ private: int defaultGetPolynomialCoefficients(Context & context, const char * symbol, Expression expression[]) const; /* Builder */ - static bool isZero(const Expression e); - static bool isOne(const Expression e); - static bool isMinusOne(const Expression e); + static bool IsZero(const Expression e); + static bool IsOne(const Expression e); + static bool IsMinusOne(const Expression e); static Expression CreateComplexExpression(Expression ra, Expression tb, Preferences::ComplexFormat complexFormat, bool undefined, bool isZeroRa, bool isOneRa, bool isZeroTb, bool isOneTb, bool isNegativeRa, bool isNegativeTb); /* Expression roots/extrema solver*/ diff --git a/poincare/src/absolute_value.cpp b/poincare/src/absolute_value.cpp index e3b97bf27..9111efbec 100644 --- a/poincare/src/absolute_value.cpp +++ b/poincare/src/absolute_value.cpp @@ -50,11 +50,11 @@ Expression AbsoluteValue::shallowReduce(Context & context, Preferences::ComplexF Expression c = childAtIndex(0); if (c.isReal(context)) { float app = c.node()->approximate(float(), context, angleUnit).toScalar(); - if (!std::isnan(app) && app >= Expression::epsilon()) { + if (!std::isnan(app) && app >= Expression::Epsilon()) { // abs(a) = a with a > 0 replaceWithInPlace(c); return c; - } else if (!std::isnan(app) && app <= -Expression::epsilon()) { + } else if (!std::isnan(app) && app <= -Expression::Epsilon()) { // abs(a) = -a with a < 0 Multiplication m(Rational(-1), c); replaceWithInPlace(m); diff --git a/poincare/src/approximation_helper.cpp b/poincare/src/approximation_helper.cpp index d0f22e9f8..e0dfb7387 100644 --- a/poincare/src/approximation_helper.cpp +++ b/poincare/src/approximation_helper.cpp @@ -16,7 +16,7 @@ template T absMod(T a, T b) { template std::complex ApproximationHelper::TruncateRealOrImaginaryPartAccordingToArgument(std::complex c) { T arg = std::arg(c); - T precision = 10*Expression::epsilon(); + T precision = 10*Expression::Epsilon(); if (absMod(arg, (T)M_PI) <= precision) { c.imag(0); } diff --git a/poincare/src/complex_argument.cpp b/poincare/src/complex_argument.cpp index c4c6d9b0d..10ce8c9d3 100644 --- a/poincare/src/complex_argument.cpp +++ b/poincare/src/complex_argument.cpp @@ -49,12 +49,12 @@ Expression ComplexArgument::shallowReduce(Context & context, Preferences::Comple bool real = c.isReal(context); if (real) { float app = c.node()->approximate(float(), context, angleUnit).toScalar(); - if (!std::isnan(app) && app >= Expression::epsilon()) { + if (!std::isnan(app) && app >= Expression::Epsilon()) { // arg(x) = 0 if x > 0 Expression result = Rational(0); replaceWithInPlace(result); return result; - } else if (!std::isnan(app) && app <= -Expression::epsilon()) { + } else if (!std::isnan(app) && app <= -Expression::Epsilon()) { // arg(x) = Pi if x < 0 Expression result = Constant(Ion::Charset::SmallPi); replaceWithInPlace(result); diff --git a/poincare/src/complex_cartesian.cpp b/poincare/src/complex_cartesian.cpp index edcee823e..23de92eab 100644 --- a/poincare/src/complex_cartesian.cpp +++ b/poincare/src/complex_cartesian.cpp @@ -58,7 +58,7 @@ Expression ComplexCartesian::shallowBeautify(Context & context, Preferences::Com b = oppositeB.isUninitialized() ? b : oppositeB; Expression e = Expression::CreateComplexExpression(a, b, Preferences::ComplexFormat::Cartesian, a.isUndefined() || b.isUndefined(), - Expression::isZero(a), Expression::isOne(a), Expression::isZero(b), Expression::isOne(b), + Expression::IsZero(a), Expression::IsOne(a), Expression::IsZero(b), Expression::IsOne(b), !oppositeA.isUninitialized(), !oppositeB.isUninitialized() ); @@ -357,7 +357,7 @@ ComplexCartesian ComplexCartesian::power(ComplexCartesian & other, Context & con ComplexCartesian ComplexCartesian::interruptComputationIfManyNodes() { if (numberOfDescendants(true) > k_maxNumberOfNodesBeforeInterrupting) { - Expression::setInterruption(true); + Expression::SetInterruption(true); return ComplexCartesian(Undefined(), Undefined()); } return *this; diff --git a/poincare/src/expression.cpp b/poincare/src/expression.cpp index 0238a0327..ed3801e07 100644 --- a/poincare/src/expression.cpp +++ b/poincare/src/expression.cpp @@ -45,11 +45,11 @@ Expression Expression::ExpressionFromAddress(const void * address, size_t size) static Expression::CircuitBreaker sCircuitBreaker = nullptr; static bool sSimplificationHasBeenInterrupted = false; -void Expression::setCircuitBreaker(CircuitBreaker cb) { +void Expression::SetCircuitBreaker(CircuitBreaker cb) { sCircuitBreaker = cb; } -bool Expression::shouldStopProcessing() { +bool Expression::ShouldStopProcessing() { if (sCircuitBreaker == nullptr) { return false; } @@ -60,7 +60,7 @@ bool Expression::shouldStopProcessing() { return false; } -void Expression::setInterruption(bool interrupt) { +void Expression::SetInterruption(bool interrupt) { sSimplificationHasBeenInterrupted = interrupt; } @@ -474,7 +474,7 @@ void Expression::simplifyAndApproximate(Expression * simplifiedExpression, Expre bool tbIsNegative = false; makePositive(&ra, &raIsNegative); makePositive(&tb, &tbIsNegative); - *simplifiedExpression = CreateComplexExpression(ra, tb, complexFormat, ra.isUndefined() || tb.isUndefined(), isZero(ra), isOne(ra), isZero(tb), isOne(tb), raIsNegative, tbIsNegative); + *simplifiedExpression = CreateComplexExpression(ra, tb, complexFormat, ra.isUndefined() || tb.isUndefined(), IsZero(ra), IsOne(ra), IsZero(tb), IsOne(tb), raIsNegative, tbIsNegative); } else { /* Case 2: The reduced expression has a complex component that could not * be bubbled up. */ @@ -575,7 +575,7 @@ U Expression::approximateToScalar(Context& context, Preferences::ComplexFormat c } template -U Expression::approximateToScalar(const char * text, Context& context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit) { +U Expression::ApproximateToScalar(const char * text, Context& context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit) { Expression exp = ParseAndSimplify(text, context, complexFormat, angleUnit); assert(!exp.isUninitialized()); return exp.approximateToScalar(context, complexFormat, angleUnit); @@ -589,20 +589,20 @@ U Expression::approximateWithValueForSymbol(const char * symbol, U x, Context & } template -U Expression::epsilon() { +U Expression::Epsilon() { static U epsilon = sizeof(U) == sizeof(double) ? 1E-15 : 1E-7f; return epsilon; } /* Builder */ -bool Expression::isZero(const Expression e) { +bool Expression::IsZero(const Expression e) { return e.type() == ExpressionNode::Type::Rational && static_cast(e).isZero(); } -bool Expression::isOne(const Expression e) { +bool Expression::IsOne(const Expression e) { return e.type() == ExpressionNode::Type::Rational && static_cast(e).isOne(); } -bool Expression::isMinusOne(const Expression e) { +bool Expression::IsMinusOne(const Expression e) { return e.type() == ExpressionNode::Type::Rational && static_cast(e).isMinusOne(); } @@ -996,8 +996,8 @@ double Expression::brentRoot(const char * symbol, double ax, double bx, double p return NAN; } -template float Expression::epsilon(); -template double Expression::epsilon(); +template float Expression::Epsilon(); +template double Expression::Epsilon(); template Expression Expression::approximate(Context& context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit) const; template Expression Expression::approximate(Context& context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit) const; @@ -1005,8 +1005,8 @@ template Expression Expression::approximate(Context& context, Preference template float Expression::approximateToScalar(Context& context, Preferences::ComplexFormat, Preferences::AngleUnit angleUnit) const; template double Expression::approximateToScalar(Context& context, Preferences::ComplexFormat, Preferences::AngleUnit angleUnit) const; -template float Expression::approximateToScalar(const char * text, Context& context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit); -template double Expression::approximateToScalar(const char * text, Context& context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit); +template float Expression::ApproximateToScalar(const char * text, Context& context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit); +template double Expression::ApproximateToScalar(const char * text, Context& context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit); template Evaluation Expression::approximateToEvaluation(Context& context, Preferences::ComplexFormat, Preferences::AngleUnit angleUnit) const; template Evaluation Expression::approximateToEvaluation(Context& context, Preferences::ComplexFormat, Preferences::AngleUnit angleUnit) const; diff --git a/poincare/src/expression_node.cpp b/poincare/src/expression_node.cpp index 73e7c3417..476cc2e4f 100644 --- a/poincare/src/expression_node.cpp +++ b/poincare/src/expression_node.cpp @@ -74,14 +74,14 @@ float ExpressionNode::characteristicXRange(Context & context, Preferences::Angle int ExpressionNode::SimplificationOrder(const ExpressionNode * e1, const ExpressionNode * e2, bool ascending, bool canBeInterrupted) { if (e1->type() > e2->type()) { - if (canBeInterrupted && Expression::shouldStopProcessing()) { + if (canBeInterrupted && Expression::ShouldStopProcessing()) { return 1; } return -(e2->simplificationOrderGreaterType(e1, ascending, canBeInterrupted)); } else if (e1->type() == e2->type()) { return e1->simplificationOrderSameType(e2, ascending, canBeInterrupted); } else { - if (canBeInterrupted && Expression::shouldStopProcessing()) { + if (canBeInterrupted && Expression::ShouldStopProcessing()) { return -1; } return e1->simplificationOrderGreaterType(e2, ascending, canBeInterrupted); diff --git a/poincare/src/integral.cpp b/poincare/src/integral.cpp index 187bf27cf..bb5be5305 100644 --- a/poincare/src/integral.cpp +++ b/poincare/src/integral.cpp @@ -184,7 +184,7 @@ IntegralNode::DetailedResult IntegralNode::kronrodGaussQuadrature(T a, T b, C template T IntegralNode::adaptiveQuadrature(T a, T b, T eps, int numberOfIterations, Context & context, Preferences::AngleUnit angleUnit) const { - if (Integral::shouldStopProcessing()) { + if (Expression::ShouldStopProcessing()) { return NAN; } DetailedResult quadKG = kronrodGaussQuadrature(a, b, context, angleUnit); diff --git a/poincare/src/matrix.cpp b/poincare/src/matrix.cpp index 6d5bd5398..6a88201cf 100644 --- a/poincare/src/matrix.cpp +++ b/poincare/src/matrix.cpp @@ -147,7 +147,7 @@ int Matrix::ArrayInverse(T * array, int numberOfRows, int numberOfColumns) { ArrayRowCanonize(operands, dim, 2*dim); // Check inversibility for (int i = 0; i < dim; i++) { - if (std::abs(operands[i*2*dim+i] - (T)1.0) > Expression::epsilon()) { + if (std::abs(operands[i*2*dim+i] - (T)1.0) > Expression::Epsilon()) { return -2; } } @@ -160,7 +160,7 @@ int Matrix::ArrayInverse(T * array, int numberOfRows, int numberOfColumns) { } Matrix Matrix::rowCanonize(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, Multiplication determinant) { - Expression::setInterruption(false); + Expression::SetInterruption(false); // The matrix children have to be reduced to be able to spot 0 deepReduceChildren(context, complexFormat, angleUnit, ExpressionNode::ReductionTarget::TopDownComputation); @@ -230,7 +230,7 @@ void Matrix::ArrayRowCanonize(T * array, int numberOfRows, int numberOfColumns, while (h < numberOfRows && k < numberOfColumns) { // Find the first non-null pivot int iPivot = h; - while (iPivot < numberOfRows && std::abs(array[iPivot*numberOfColumns+k]) < Expression::epsilon()) { + while (iPivot < numberOfRows && std::abs(array[iPivot*numberOfColumns+k]) < Expression::Epsilon()) { iPivot++; } if (iPivot == numberOfRows) { diff --git a/poincare/src/power.cpp b/poincare/src/power.cpp index d58c6bf2d..e3a397372 100644 --- a/poincare/src/power.cpp +++ b/poincare/src/power.cpp @@ -28,7 +28,7 @@ namespace Poincare { // Properties ExpressionNode::Sign PowerNode::sign(Context * context) const { - if (Expression::shouldStopProcessing()) { + if (Expression::ShouldStopProcessing()) { return Sign::Unknown; } if (childAtIndex(0)->sign(context) == Sign::Positive && childAtIndex(1)->sign(context) != Sign::Unknown) { @@ -221,7 +221,7 @@ template MatrixComplex PowerNode::computeOnMatrixAndComplex(const MatrixComplex result = MatrixComplex::createIdentity(m.numberOfRows()); // TODO: implement a quick exponentiation for (int k = 0; k < (int)power; k++) { - if (Expression::shouldStopProcessing()) { + if (Expression::ShouldStopProcessing()) { return MatrixComplex::Undefined(); } result = MultiplicationNode::computeOnMatrices(result, m); diff --git a/poincare/src/sequence.cpp b/poincare/src/sequence.cpp index 5e3748ac6..33eebc3d6 100644 --- a/poincare/src/sequence.cpp +++ b/poincare/src/sequence.cpp @@ -31,7 +31,7 @@ Evaluation SequenceNode::templatedApproximate(Context& context, Preferences:: VariableContext nContext = VariableContext(static_cast(childAtIndex(1))->name(), &context); Evaluation result = Complex((T)emptySequenceValue()); for (int i = (int)start; i <= (int)end; i++) { - if (Expression::shouldStopProcessing()) { + if (Expression::ShouldStopProcessing()) { return Complex::Undefined(); } nContext.setApproximationForVariable((T)i); diff --git a/poincare/src/store.cpp b/poincare/src/store.cpp index 7b733528d..35bb87b2c 100644 --- a/poincare/src/store.cpp +++ b/poincare/src/store.cpp @@ -87,7 +87,7 @@ Expression Store::shallowReduce(Context & context, Preferences::ComplexFormat co e = reducedE; } // Restore the previous interruption flag - setInterruption(interruptedSimplification); + SetInterruption(interruptedSimplification); replaceWithInPlace(e); return e; diff --git a/poincare/src/trigonometry.cpp b/poincare/src/trigonometry.cpp index 07c761684..d27aa2530 100644 --- a/poincare/src/trigonometry.cpp +++ b/poincare/src/trigonometry.cpp @@ -455,7 +455,7 @@ Expression Trigonometry::table(const Expression e, ExpressionNode::Type type, Co } for (int i = 0; i < k_numberOfEntries; i++) { float inputValue = cheatTable[i][inputIndex].value; - if (std::isnan(inputValue) || std::fabs(inputValue-eValue) > Expression::epsilon()) { + if (std::isnan(inputValue) || std::fabs(inputValue-eValue) > Expression::Epsilon()) { continue; } // Our given expression approximation matches a table entry, we check that both expressions are identical @@ -502,8 +502,8 @@ T Trigonometry::RoundToMeaningfulDigits(T result, T input) { * have sin(pi) ~ 0 and sin(1E-15)=1E-15. * We can't do that for all evaluation as the user can operate on values as * small as 1E-308 (in double) and most results still be correct. */ - if (input == 0.0 || std::fabs(result/input) <= Expression::epsilon()) { - T precision = 10*Expression::epsilon(); + if (input == 0.0 || std::fabs(result/input) <= Expression::Epsilon()) { + T precision = 10*Expression::Epsilon(); result = std::round(result/precision)*precision; } return result; diff --git a/poincare/test/helper.cpp b/poincare/test/helper.cpp index 1674a519b..5b8340e85 100644 --- a/poincare/test/helper.cpp +++ b/poincare/test/helper.cpp @@ -166,7 +166,7 @@ template void assert_parsed_expression_approximates_with_value_for_symbol(Expression expression, const char * symbol, T value, T approximation, Poincare::Preferences::ComplexFormat complexFormat, Poincare::Preferences::AngleUnit angleUnit) { Shared::GlobalContext globalContext; T result = expression.approximateWithValueForSymbol(symbol, value, globalContext, complexFormat, angleUnit); - quiz_assert((std::isnan(result) && std::isnan(approximation)) || std::fabs(result - approximation) < 10.0*Expression::epsilon()); + quiz_assert((std::isnan(result) && std::isnan(approximation)) || std::fabs(result - approximation) < 10.0*Expression::Epsilon()); } void assert_parsed_expression_simplify_to(const char * expression, const char * simplifiedExpression, Preferences::AngleUnit angleUnit, Preferences::ComplexFormat complexFormat) {