mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-01-18 16:27:34 +01:00
Fix spelling (#128)
* Fix spelling in .cpp files * Fix spelling in all files
This commit is contained in:
@@ -50,7 +50,7 @@ private:
|
||||
class BasedInteger final : public Number {
|
||||
friend class BasedIntegerNode;
|
||||
public:
|
||||
/* The constructor build a irreductible fraction */
|
||||
/* The constructor build a irreducible fraction */
|
||||
BasedInteger(const BasedIntegerNode * node) : Number(node) {}
|
||||
static BasedInteger Builder(const char * digits, size_t size, Integer::Base base);
|
||||
static BasedInteger Builder(const Integer & m, Integer::Base base = Integer::Base::Decimal);
|
||||
|
||||
@@ -27,7 +27,7 @@ private:
|
||||
// Layout
|
||||
Layout createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override;
|
||||
int serialize(char * buffer, int bufferSize, Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override;
|
||||
// Evalutation
|
||||
// Evaluation
|
||||
Evaluation<float> approximate(SinglePrecision p, ApproximationContext approximationContext) const override { return templatedApproximate<float>(approximationContext); }
|
||||
Evaluation<double> approximate(DoublePrecision p, ApproximationContext approximationContext) const override { return templatedApproximate<double>(approximationContext); }
|
||||
template<typename T> Evaluation<T> templatedApproximate(ApproximationContext approximationContext) const;
|
||||
|
||||
@@ -338,7 +338,7 @@ protected:
|
||||
* Float to Symbol for instance).
|
||||
*
|
||||
* We could have overriden the operator T(). However, even with the
|
||||
* 'explicit' keyword (which prevents implicit casts), direct initilization
|
||||
* 'explicit' keyword (which prevents implicit casts), direct initialization
|
||||
* are enable which can lead to weird code:
|
||||
* ie, you can write: 'Rational a(2); AbsoluteValue b(a);'
|
||||
* */
|
||||
@@ -407,7 +407,7 @@ private:
|
||||
static constexpr int k_maxSymbolReplacementsCount = 10;
|
||||
static bool sSymbolReplacementsCountLock;
|
||||
|
||||
/* Add missing parenthesis will add parentheses that easen the reading of the
|
||||
/* Add missing parenthesis will add parentheses that ease the reading of the
|
||||
* expression or that are required by math rules. For example:
|
||||
* 2+-1 --> 2+(-1)
|
||||
* *(+(2,1),3) --> (2+1)*3
|
||||
|
||||
@@ -298,7 +298,7 @@ public:
|
||||
virtual Expression unaryFunctionDifferential(ReductionContext reductionContext);
|
||||
/* Return a clone of the denominator part of the expression */
|
||||
/*!*/ virtual Expression denominator(ExpressionNode::ReductionContext reductionContext) const;
|
||||
/* LayoutShape is used to check if the multiplication sign can be omitted between two expressions. It depends on the "layout syle" of the on the right of the left expression */
|
||||
/* LayoutShape is used to check if the multiplication sign can be omitted between two expressions. It depends on the "layout style" of the on the right of the left expression */
|
||||
enum class LayoutShape {
|
||||
Decimal,
|
||||
Integer,
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
|
||||
namespace Poincare {
|
||||
|
||||
/* Float reprensents an approximated number. This class is use to avoid turning
|
||||
/* Float represents an approximated number. This class is use to avoid turning
|
||||
* float/double into Decimal back and forth because performances are
|
||||
* dramatically affected when doing so. For instance, when plotting a graph, we
|
||||
* need to set a float/double value for a symbol and approximate an expression
|
||||
|
||||
@@ -39,7 +39,7 @@ public:
|
||||
int serialize(char * buffer, int bufferSize, Preferences::PrintFloatMode floatDisplayMode = Preferences::PrintFloatMode::Decimal, int numberOfSignificantDigits = 0) const override;
|
||||
|
||||
/* Derivation
|
||||
* Unlike Numbers that derivate to 0, Infinity derivates to Undefined. */
|
||||
* Unlike Numbers that derivate to 0, Infinity derivatives to Undefined. */
|
||||
bool derivate(ReductionContext reductionContext, Expression symbol, Expression symbolValue) override;
|
||||
|
||||
private:
|
||||
|
||||
@@ -48,7 +48,7 @@ public:
|
||||
/* allChildrenAreReal returns:
|
||||
* - 1 if all children are real
|
||||
* - 0 if all non real children are ComplexCartesian
|
||||
* - -1 if some chidren are non-real and non ComplexCartesian */
|
||||
* - -1 if some children are non-real and non ComplexCartesian */
|
||||
int allChildrenAreReal(Context * context) const;
|
||||
protected:
|
||||
void sortChildrenInPlace(NAryExpressionNode::ExpressionOrder order, Context * context, bool canSwapMatrices, bool canBeInterrupted) {
|
||||
|
||||
@@ -21,13 +21,13 @@ public:
|
||||
constexpr static int k_maxFloatGlyphLength = 2 // '-' and '.'
|
||||
+ k_numberOfStoredSignificantDigits // mantissa
|
||||
+ 1 // ᴇ
|
||||
+ 1 // exponant '-'
|
||||
+ 3; // exponant
|
||||
+ 1 // exponent '-'
|
||||
+ 3; // exponent
|
||||
constexpr static int k_maxFloatCharSize = 2 // '-' and '.'
|
||||
+ k_numberOfStoredSignificantDigits // mantissa
|
||||
+ k_specialECodePointByteLength // ᴇ
|
||||
+ 1 // exponant '-'
|
||||
+ 3 // exponant
|
||||
+ 1 // exponent '-'
|
||||
+ 3 // exponent
|
||||
+ 1; // null-terminated
|
||||
|
||||
constexpr static int glyphLengthForFloatWithPrecision(int numberOfSignificantDigits) {
|
||||
@@ -36,15 +36,15 @@ public:
|
||||
+ numberOfSignificantDigits // mantissa
|
||||
+ 1 // glyph ᴇ
|
||||
+ 1 // '-'
|
||||
+ 3; // exponant
|
||||
+ 3; // exponent
|
||||
}
|
||||
constexpr static int charSizeForFloatsWithPrecision(int numberOfSignificantDigits) {
|
||||
// The worst case is -1.234ᴇ-328
|
||||
return 2 // '-' and '.'
|
||||
+ numberOfSignificantDigits // mantissa
|
||||
+ k_specialECodePointByteLength // ᴇ
|
||||
+ 1 // exponant '-'
|
||||
+ 3 // exponant
|
||||
+ 1 // exponent '-'
|
||||
+ 3 // exponent
|
||||
+ 1; // null-terminated
|
||||
}
|
||||
|
||||
|
||||
@@ -73,7 +73,7 @@ class Rational final : public Number {
|
||||
friend class PowerNode;
|
||||
friend class Power;
|
||||
public:
|
||||
/* The constructor build a irreductible fraction */
|
||||
/* The constructor build a irreducible fraction */
|
||||
Rational(const RationalNode * node) : Number(node) {}
|
||||
static Rational Builder(Integer & num, Integer & den);
|
||||
static Rational Builder(const Integer & numerator);
|
||||
|
||||
@@ -22,7 +22,7 @@ public:
|
||||
private:
|
||||
// Simplification
|
||||
Expression shallowReduce(ReductionContext reductionContext) override;
|
||||
// Evalutation
|
||||
// Evaluation
|
||||
Evaluation<float> approximate(SinglePrecision p, ApproximationContext approximationContext) const override { return templatedApproximate<float>(approximationContext); }
|
||||
Evaluation<double> approximate(DoublePrecision p, ApproximationContext approximationContext) const override { return templatedApproximate<double>(approximationContext); }
|
||||
template<typename T> Evaluation<T> templatedApproximate(ApproximationContext approximationContext) const;
|
||||
|
||||
@@ -30,7 +30,7 @@ public:
|
||||
}
|
||||
|
||||
/* Derivation
|
||||
* Unlike Numbers that derivate to 0, Undefined derivates to Undefined. */
|
||||
* Unlike Numbers that derivate to 0, Undefined derivatives to Undefined. */
|
||||
bool derivate(ReductionContext reductionContext, Expression symbol, Expression symbolValue) override { return true; }
|
||||
|
||||
// Layout
|
||||
|
||||
@@ -60,15 +60,15 @@ public:
|
||||
static Vector FromBaseUnits(const Expression baseUnits);
|
||||
const T coefficientAtIndex(size_t i) const {
|
||||
assert(i < k_numberOfBaseUnits);
|
||||
const T coefficients[k_numberOfBaseUnits] = {time, distance, mass, current, temperature, amountOfSubstance, luminuousIntensity};
|
||||
const T coefficients[k_numberOfBaseUnits] = {time, distance, mass, current, temperature, amountOfSubstance, luminousIntensity};
|
||||
return coefficients[i];
|
||||
}
|
||||
void setCoefficientAtIndex(size_t i, T c) {
|
||||
assert(i < k_numberOfBaseUnits);
|
||||
T * coefficientsAddresses[k_numberOfBaseUnits] = {&time, &distance, &mass, ¤t, &temperature, &amountOfSubstance, &luminuousIntensity};
|
||||
T * coefficientsAddresses[k_numberOfBaseUnits] = {&time, &distance, &mass, ¤t, &temperature, &amountOfSubstance, &luminousIntensity};
|
||||
*(coefficientsAddresses[i]) = c;
|
||||
}
|
||||
bool operator==(const Vector &rhs) const { return time == rhs.time && distance == rhs.distance && mass == rhs.mass && current == rhs.current && temperature == rhs.temperature && amountOfSubstance == rhs.amountOfSubstance && luminuousIntensity == rhs.luminuousIntensity; }
|
||||
bool operator==(const Vector &rhs) const { return time == rhs.time && distance == rhs.distance && mass == rhs.mass && current == rhs.current && temperature == rhs.temperature && amountOfSubstance == rhs.amountOfSubstance && luminousIntensity == rhs.luminousIntensity; }
|
||||
bool operator!=(const Vector &rhs) const { return !(*this == rhs); }
|
||||
void addAllCoefficients(const Vector other, int factor);
|
||||
Expression toBaseUnits() const;
|
||||
@@ -78,7 +78,7 @@ public:
|
||||
T current;
|
||||
T temperature;
|
||||
T amountOfSubstance;
|
||||
T luminuousIntensity;
|
||||
T luminousIntensity;
|
||||
};
|
||||
|
||||
class Representative {
|
||||
@@ -104,7 +104,7 @@ public:
|
||||
m_outputPrefixable(outputPrefixable)
|
||||
{}
|
||||
|
||||
virtual const Vector<int> dimensionVector() const { return Vector<int>{.time = 0, .distance = 0, .mass = 0, .current = 0, .temperature = 0, .amountOfSubstance = 0, .luminuousIntensity = 0}; };
|
||||
virtual const Vector<int> dimensionVector() const { return Vector<int>{.time = 0, .distance = 0, .mass = 0, .current = 0, .temperature = 0, .amountOfSubstance = 0, .luminousIntensity = 0}; };
|
||||
virtual int numberOfRepresentatives() const { return 0; };
|
||||
/* representativesOfSameDimension returns a pointer to the array containing
|
||||
* all representatives for this's dimension. */
|
||||
@@ -113,7 +113,7 @@ public:
|
||||
virtual bool isBaseUnit() const { return false; }
|
||||
virtual const Representative * standardRepresentative(double value, double exponent, ExpressionNode::ReductionContext reductionContext, const Prefix * * prefix) const { return DefaultFindBestRepresentative(value, exponent, representativesOfSameDimension(), numberOfRepresentatives(), prefix); }
|
||||
/* hasSpecialAdditionalExpressions return true if the unit has special
|
||||
* forms suchas as splits (for time and imperial units) or common
|
||||
* forms such as as splits (for time and imperial units) or common
|
||||
* conversions (such as speed and energy). */
|
||||
virtual bool hasSpecialAdditionalExpressions(double value, Preferences::UnitFormat unitFormat) const { return false; }
|
||||
virtual int setAdditionalExpressions(double value, Expression * dest, int availableLength, ExpressionNode::ReductionContext reductionContext) const { return 0; }
|
||||
@@ -145,7 +145,7 @@ public:
|
||||
friend class Unit;
|
||||
public:
|
||||
constexpr static TimeRepresentative Default() { return TimeRepresentative(nullptr, 0., Prefixable::None, Prefixable::None); }
|
||||
const Vector<int> dimensionVector() const override { return Vector<int>{.time = 1, .distance = 0, .mass = 0, .current = 0, .temperature = 0, .amountOfSubstance = 0, .luminuousIntensity = 0}; }
|
||||
const Vector<int> dimensionVector() const override { return Vector<int>{.time = 1, .distance = 0, .mass = 0, .current = 0, .temperature = 0, .amountOfSubstance = 0, .luminousIntensity = 0}; }
|
||||
int numberOfRepresentatives() const override { return 7; }
|
||||
const Representative * representativesOfSameDimension() const override;
|
||||
bool isBaseUnit() const override { return this == representativesOfSameDimension(); }
|
||||
@@ -159,7 +159,7 @@ public:
|
||||
friend class Unit;
|
||||
public:
|
||||
constexpr static DistanceRepresentative Default() { return DistanceRepresentative(nullptr, 0., Prefixable::None, Prefixable::None); }
|
||||
const Vector<int> dimensionVector() const override { return Vector<int>{.time = 0, .distance = 1, .mass = 0, .current = 0, .temperature = 0, .amountOfSubstance = 0, .luminuousIntensity = 0}; }
|
||||
const Vector<int> dimensionVector() const override { return Vector<int>{.time = 0, .distance = 1, .mass = 0, .current = 0, .temperature = 0, .amountOfSubstance = 0, .luminousIntensity = 0}; }
|
||||
int numberOfRepresentatives() const override { return 8; }
|
||||
const Representative * representativesOfSameDimension() const override;
|
||||
bool isBaseUnit() const override { return this == representativesOfSameDimension(); }
|
||||
@@ -174,7 +174,7 @@ public:
|
||||
friend class Unit;
|
||||
public:
|
||||
constexpr static MassRepresentative Default() { return MassRepresentative(nullptr, 0., Prefixable::None, Prefixable::None); }
|
||||
const Vector<int> dimensionVector() const override { return Vector<int>{.time = 0, .distance = 0, .mass = 1, .current = 0, .temperature = 0, .amountOfSubstance = 0, .luminuousIntensity = 0}; }
|
||||
const Vector<int> dimensionVector() const override { return Vector<int>{.time = 0, .distance = 0, .mass = 1, .current = 0, .temperature = 0, .amountOfSubstance = 0, .luminousIntensity = 0}; }
|
||||
int numberOfRepresentatives() const override { return 7; }
|
||||
const Representative * representativesOfSameDimension() const override;
|
||||
const Prefix * basePrefix() const override;
|
||||
@@ -190,7 +190,7 @@ public:
|
||||
friend class Unit;
|
||||
public:
|
||||
constexpr static CurrentRepresentative Default() { return CurrentRepresentative(nullptr, 0., Prefixable::None, Prefixable::None); }
|
||||
const Vector<int> dimensionVector() const override { return Vector<int>{.time = 0, .distance = 0, .mass = 0, .current = 1, .temperature = 0, .amountOfSubstance = 0, .luminuousIntensity = 0}; }
|
||||
const Vector<int> dimensionVector() const override { return Vector<int>{.time = 0, .distance = 0, .mass = 0, .current = 1, .temperature = 0, .amountOfSubstance = 0, .luminousIntensity = 0}; }
|
||||
int numberOfRepresentatives() const override { return 1; }
|
||||
const Representative * representativesOfSameDimension() const override;
|
||||
bool isBaseUnit() const override { return this == representativesOfSameDimension(); }
|
||||
@@ -203,7 +203,7 @@ public:
|
||||
public:
|
||||
static double ConvertTemperatures(double value, const Representative * source, const Representative * target);
|
||||
constexpr static TemperatureRepresentative Default() { return TemperatureRepresentative(nullptr, 0., Prefixable::None, Prefixable::None); }
|
||||
const Vector<int> dimensionVector() const override { return Vector<int>{.time = 0, .distance = 0, .mass = 0, .current = 0, .temperature = 1, .amountOfSubstance = 0, .luminuousIntensity = 0}; }
|
||||
const Vector<int> dimensionVector() const override { return Vector<int>{.time = 0, .distance = 0, .mass = 0, .current = 0, .temperature = 1, .amountOfSubstance = 0, .luminousIntensity = 0}; }
|
||||
int numberOfRepresentatives() const override { return 3; }
|
||||
const Representative * representativesOfSameDimension() const override;
|
||||
bool isBaseUnit() const override { return this == representativesOfSameDimension(); }
|
||||
@@ -220,7 +220,7 @@ public:
|
||||
friend class Unit;
|
||||
public:
|
||||
constexpr static AmountOfSubstanceRepresentative Default() { return AmountOfSubstanceRepresentative(nullptr, 0., Prefixable::None, Prefixable::None); }
|
||||
const Vector<int> dimensionVector() const override { return Vector<int>{.time = 0, .distance = 0, .mass = 0, .current = 0, .temperature = 0, .amountOfSubstance = 1, .luminuousIntensity = 0}; }
|
||||
const Vector<int> dimensionVector() const override { return Vector<int>{.time = 0, .distance = 0, .mass = 0, .current = 0, .temperature = 0, .amountOfSubstance = 1, .luminousIntensity = 0}; }
|
||||
int numberOfRepresentatives() const override { return 1; }
|
||||
const Representative * representativesOfSameDimension() const override;
|
||||
bool isBaseUnit() const override { return this == representativesOfSameDimension(); }
|
||||
@@ -232,7 +232,7 @@ public:
|
||||
friend class Unit;
|
||||
public:
|
||||
constexpr static LuminousIntensityRepresentative Default() { return LuminousIntensityRepresentative(nullptr, 0., Prefixable::None, Prefixable::None); }
|
||||
const Vector<int> dimensionVector() const override { return Vector<int>{.time = 0, .distance = 0, .mass = 0, .current = 0, .temperature = 0, .amountOfSubstance = 0, .luminuousIntensity = 1}; }
|
||||
const Vector<int> dimensionVector() const override { return Vector<int>{.time = 0, .distance = 0, .mass = 0, .current = 0, .temperature = 0, .amountOfSubstance = 0, .luminousIntensity = 1}; }
|
||||
int numberOfRepresentatives() const override { return 1; }
|
||||
const Representative * representativesOfSameDimension() const override;
|
||||
bool isBaseUnit() const override { return this == representativesOfSameDimension(); }
|
||||
@@ -244,7 +244,7 @@ public:
|
||||
friend class Unit;
|
||||
public:
|
||||
constexpr static FrequencyRepresentative Default() { return FrequencyRepresentative(nullptr, 0., Prefixable::None, Prefixable::None); }
|
||||
const Vector<int> dimensionVector() const override { return Vector<int>{.time = -1, .distance = 0, .mass = 0, .current = 0, .temperature = 0, .amountOfSubstance = 0, .luminuousIntensity = 0}; }
|
||||
const Vector<int> dimensionVector() const override { return Vector<int>{.time = -1, .distance = 0, .mass = 0, .current = 0, .temperature = 0, .amountOfSubstance = 0, .luminousIntensity = 0}; }
|
||||
int numberOfRepresentatives() const override { return 1; }
|
||||
const Representative * representativesOfSameDimension() const override;
|
||||
private:
|
||||
@@ -255,7 +255,7 @@ public:
|
||||
friend class Unit;
|
||||
public:
|
||||
constexpr static ForceRepresentative Default() { return ForceRepresentative(nullptr, 0., Prefixable::None, Prefixable::None); }
|
||||
const Vector<int> dimensionVector() const override { return Vector<int>{.time = -2, .distance = 1, .mass = 1, .current = 0, .temperature = 0, .amountOfSubstance = 0, .luminuousIntensity = 0}; }
|
||||
const Vector<int> dimensionVector() const override { return Vector<int>{.time = -2, .distance = 1, .mass = 1, .current = 0, .temperature = 0, .amountOfSubstance = 0, .luminousIntensity = 0}; }
|
||||
int numberOfRepresentatives() const override { return 1; }
|
||||
const Representative * representativesOfSameDimension() const override;
|
||||
private:
|
||||
@@ -266,7 +266,7 @@ public:
|
||||
friend class Unit;
|
||||
public:
|
||||
constexpr static PressureRepresentative Default() { return PressureRepresentative(nullptr, 0., Prefixable::None, Prefixable::None); }
|
||||
const Vector<int> dimensionVector() const override { return Vector<int>{.time = -2, .distance = -1, .mass = 1, .current = 0, .temperature = 0, .amountOfSubstance = 0, .luminuousIntensity = 0}; }
|
||||
const Vector<int> dimensionVector() const override { return Vector<int>{.time = -2, .distance = -1, .mass = 1, .current = 0, .temperature = 0, .amountOfSubstance = 0, .luminousIntensity = 0}; }
|
||||
int numberOfRepresentatives() const override { return 3; }
|
||||
const Representative * representativesOfSameDimension() const override;
|
||||
private:
|
||||
@@ -277,7 +277,7 @@ public:
|
||||
friend class Unit;
|
||||
public:
|
||||
constexpr static EnergyRepresentative Default() { return EnergyRepresentative(nullptr, 0., Prefixable::None, Prefixable::None); }
|
||||
const Vector<int> dimensionVector() const override { return Vector<int>{.time = -2, .distance = 2, .mass = 1, .current = 0, .temperature = 0, .amountOfSubstance = 0, .luminuousIntensity = 0}; }
|
||||
const Vector<int> dimensionVector() const override { return Vector<int>{.time = -2, .distance = 2, .mass = 1, .current = 0, .temperature = 0, .amountOfSubstance = 0, .luminousIntensity = 0}; }
|
||||
int numberOfRepresentatives() const override { return 2; }
|
||||
const Representative * representativesOfSameDimension() const override;
|
||||
bool hasSpecialAdditionalExpressions(double value, Preferences::UnitFormat unitFormat) const override { return true; }
|
||||
@@ -290,7 +290,7 @@ public:
|
||||
friend class Unit;
|
||||
public:
|
||||
constexpr static PowerRepresentative Default() { return PowerRepresentative(nullptr, 0., Prefixable::None, Prefixable::None); }
|
||||
const Vector<int> dimensionVector() const override { return Vector<int>{.time = -3, .distance = 2, .mass = 1, .current = 0, .temperature = 0, .amountOfSubstance = 0, .luminuousIntensity = 0}; }
|
||||
const Vector<int> dimensionVector() const override { return Vector<int>{.time = -3, .distance = 2, .mass = 1, .current = 0, .temperature = 0, .amountOfSubstance = 0, .luminousIntensity = 0}; }
|
||||
int numberOfRepresentatives() const override { return 1; }
|
||||
const Representative * representativesOfSameDimension() const override;
|
||||
private:
|
||||
@@ -302,7 +302,7 @@ public:
|
||||
public:
|
||||
using Representative::Representative;
|
||||
constexpr static ElectricChargeRepresentative Default() { return ElectricChargeRepresentative(nullptr, 0., Prefixable::None, Prefixable::None); }
|
||||
const Vector<int> dimensionVector() const override { return Vector<int>{.time = 1, .distance = 0, .mass = 0, .current = 1, .temperature = 0, .amountOfSubstance = 0, .luminuousIntensity = 0}; }
|
||||
const Vector<int> dimensionVector() const override { return Vector<int>{.time = 1, .distance = 0, .mass = 0, .current = 1, .temperature = 0, .amountOfSubstance = 0, .luminousIntensity = 0}; }
|
||||
int numberOfRepresentatives() const override { return 1; }
|
||||
const Representative * representativesOfSameDimension() const override;
|
||||
};
|
||||
@@ -311,7 +311,7 @@ public:
|
||||
friend class Unit;
|
||||
public:
|
||||
constexpr static ElectricPotentialRepresentative Default() { return ElectricPotentialRepresentative(nullptr, 0., Prefixable::None, Prefixable::None); }
|
||||
const Vector<int> dimensionVector() const override { return Vector<int>{.time = -3, .distance = 2, .mass = 1, .current = -1, .temperature = 0, .amountOfSubstance = 0, .luminuousIntensity = 0}; }
|
||||
const Vector<int> dimensionVector() const override { return Vector<int>{.time = -3, .distance = 2, .mass = 1, .current = -1, .temperature = 0, .amountOfSubstance = 0, .luminousIntensity = 0}; }
|
||||
int numberOfRepresentatives() const override { return 1; }
|
||||
const Representative * representativesOfSameDimension() const override;
|
||||
private:
|
||||
@@ -322,7 +322,7 @@ public:
|
||||
friend class Unit;
|
||||
public:
|
||||
constexpr static ElectricCapacitanceRepresentative Default() { return ElectricCapacitanceRepresentative(nullptr, 0., Prefixable::None, Prefixable::None); }
|
||||
const Vector<int> dimensionVector() const override { return Vector<int>{.time = 4, .distance = -2, .mass = -1, .current = 2, .temperature = 0, .amountOfSubstance = 0, .luminuousIntensity = 0}; }
|
||||
const Vector<int> dimensionVector() const override { return Vector<int>{.time = 4, .distance = -2, .mass = -1, .current = 2, .temperature = 0, .amountOfSubstance = 0, .luminousIntensity = 0}; }
|
||||
int numberOfRepresentatives() const override { return 1; }
|
||||
const Representative * representativesOfSameDimension() const override;
|
||||
private:
|
||||
@@ -333,7 +333,7 @@ public:
|
||||
friend class Unit;
|
||||
public:
|
||||
constexpr static ElectricResistanceRepresentative Default() { return ElectricResistanceRepresentative(nullptr, 0., Prefixable::None, Prefixable::None); }
|
||||
const Vector<int> dimensionVector() const override { return Vector<int>{.time = -3, .distance = 2, .mass = 1, .current = -2, .temperature = 0, .amountOfSubstance = 0, .luminuousIntensity = 0}; }
|
||||
const Vector<int> dimensionVector() const override { return Vector<int>{.time = -3, .distance = 2, .mass = 1, .current = -2, .temperature = 0, .amountOfSubstance = 0, .luminousIntensity = 0}; }
|
||||
int numberOfRepresentatives() const override { return 1; }
|
||||
const Representative * representativesOfSameDimension() const override;
|
||||
private:
|
||||
@@ -344,7 +344,7 @@ public:
|
||||
friend class Unit;
|
||||
public:
|
||||
constexpr static ElectricConductanceRepresentative Default() { return ElectricConductanceRepresentative(nullptr, 1., Prefixable::None, Prefixable::None); }
|
||||
const Vector<int> dimensionVector() const override { return Vector<int>{.time = 3, .distance = -2, .mass = -1, .current = 2, .temperature = 0, .amountOfSubstance = 0, .luminuousIntensity = 0}; }
|
||||
const Vector<int> dimensionVector() const override { return Vector<int>{.time = 3, .distance = -2, .mass = -1, .current = 2, .temperature = 0, .amountOfSubstance = 0, .luminousIntensity = 0}; }
|
||||
int numberOfRepresentatives() const override { return 1; }
|
||||
const Representative * representativesOfSameDimension() const override;
|
||||
private:
|
||||
@@ -355,7 +355,7 @@ public:
|
||||
friend class Unit;
|
||||
public:
|
||||
constexpr static MagneticFluxRepresentative Default() { return MagneticFluxRepresentative(nullptr, 0., Prefixable::None, Prefixable::None); }
|
||||
const Vector<int> dimensionVector() const override { return Vector<int>{.time = -2, .distance = 2, .mass = 1, .current = -1, .temperature = 0, .amountOfSubstance = 0, .luminuousIntensity = 0}; }
|
||||
const Vector<int> dimensionVector() const override { return Vector<int>{.time = -2, .distance = 2, .mass = 1, .current = -1, .temperature = 0, .amountOfSubstance = 0, .luminousIntensity = 0}; }
|
||||
int numberOfRepresentatives() const override { return 1; }
|
||||
const Representative * representativesOfSameDimension() const override;
|
||||
private:
|
||||
@@ -366,7 +366,7 @@ public:
|
||||
friend class Unit;
|
||||
public:
|
||||
constexpr static MagneticFieldRepresentative Default() { return MagneticFieldRepresentative(nullptr, 0., Prefixable::None, Prefixable::None); }
|
||||
const Vector<int> dimensionVector() const override { return Vector<int>{.time = -2, .distance = 0, .mass = 1, .current = -1, .temperature = 0, .amountOfSubstance = 0, .luminuousIntensity = 0}; }
|
||||
const Vector<int> dimensionVector() const override { return Vector<int>{.time = -2, .distance = 0, .mass = 1, .current = -1, .temperature = 0, .amountOfSubstance = 0, .luminousIntensity = 0}; }
|
||||
int numberOfRepresentatives() const override { return 1; }
|
||||
const Representative * representativesOfSameDimension() const override;
|
||||
private:
|
||||
@@ -377,7 +377,7 @@ public:
|
||||
friend class Unit;
|
||||
public:
|
||||
constexpr static InductanceRepresentative Default() { return InductanceRepresentative(nullptr, 0., Prefixable::None, Prefixable::None); }
|
||||
const Vector<int> dimensionVector() const override { return Vector<int>{.time = -2, .distance = 2, .mass = 1, .current = -2, .temperature = 0, .amountOfSubstance = 0, .luminuousIntensity = 0}; }
|
||||
const Vector<int> dimensionVector() const override { return Vector<int>{.time = -2, .distance = 2, .mass = 1, .current = -2, .temperature = 0, .amountOfSubstance = 0, .luminousIntensity = 0}; }
|
||||
int numberOfRepresentatives() const override { return 1; }
|
||||
const Representative * representativesOfSameDimension() const override;
|
||||
private:
|
||||
@@ -388,7 +388,7 @@ public:
|
||||
friend class Unit;
|
||||
public:
|
||||
constexpr static CatalyticActivityRepresentative Default() { return CatalyticActivityRepresentative(nullptr, 0., Prefixable::None, Prefixable::None); }
|
||||
const Vector<int> dimensionVector() const override { return Vector<int>{.time = -1, .distance = 0, .mass = 0, .current = 0, .temperature = 0, .amountOfSubstance = 1, .luminuousIntensity = 0}; }
|
||||
const Vector<int> dimensionVector() const override { return Vector<int>{.time = -1, .distance = 0, .mass = 0, .current = 0, .temperature = 0, .amountOfSubstance = 1, .luminousIntensity = 0}; }
|
||||
int numberOfRepresentatives() const override { return 1; }
|
||||
const Representative * representativesOfSameDimension() const override;
|
||||
private:
|
||||
@@ -399,7 +399,7 @@ public:
|
||||
friend class Unit;
|
||||
public:
|
||||
constexpr static SurfaceRepresentative Default() { return SurfaceRepresentative(nullptr, 0., Prefixable::None, Prefixable::None); }
|
||||
const Vector<int> dimensionVector() const override { return Vector<int>{.time = 0, .distance = 2, .mass = 0, .current = 0, .temperature = 0, .amountOfSubstance = 0, .luminuousIntensity = 0}; }
|
||||
const Vector<int> dimensionVector() const override { return Vector<int>{.time = 0, .distance = 2, .mass = 0, .current = 0, .temperature = 0, .amountOfSubstance = 0, .luminousIntensity = 0}; }
|
||||
int numberOfRepresentatives() const override { return 2; }
|
||||
const Representative * representativesOfSameDimension() const override;
|
||||
const Representative * standardRepresentative(double value, double exponent, ExpressionNode::ReductionContext reductionContext, const Prefix * * prefix) const override;
|
||||
@@ -413,7 +413,7 @@ public:
|
||||
friend class Unit;
|
||||
public:
|
||||
constexpr static VolumeRepresentative Default() { return VolumeRepresentative(nullptr, 0., Prefixable::None, Prefixable::None); }
|
||||
const Vector<int> dimensionVector() const override { return Vector<int>{.time = 0, .distance = 3, .mass = 0, .current = 0, .temperature = 0, .amountOfSubstance = 0, .luminuousIntensity = 0}; }
|
||||
const Vector<int> dimensionVector() const override { return Vector<int>{.time = 0, .distance = 3, .mass = 0, .current = 0, .temperature = 0, .amountOfSubstance = 0, .luminousIntensity = 0}; }
|
||||
int numberOfRepresentatives() const override { return 8; }
|
||||
const Representative * representativesOfSameDimension() const override;
|
||||
const Representative * standardRepresentative(double value, double exponent, ExpressionNode::ReductionContext reductionContext, const Prefix * * prefix) const override;
|
||||
@@ -427,7 +427,7 @@ public:
|
||||
friend class Unit;
|
||||
public:
|
||||
constexpr static SpeedRepresentative Default() { return SpeedRepresentative(nullptr, 0., Prefixable::None, Prefixable::None); }
|
||||
const Vector<int>dimensionVector() const override { return Vector<int>{.time = -1, .distance = 1, .mass = 0, .current = 0, .temperature = 0, .amountOfSubstance = 0, .luminuousIntensity = 0}; }
|
||||
const Vector<int>dimensionVector() const override { return Vector<int>{.time = -1, .distance = 1, .mass = 0, .current = 0, .temperature = 0, .amountOfSubstance = 0, .luminousIntensity = 0}; }
|
||||
const Representative * standardRepresentative(double value, double exponent, ExpressionNode::ReductionContext reductionContext, const Prefix * * prefix) const override { return nullptr; }
|
||||
bool hasSpecialAdditionalExpressions(double value, Preferences::UnitFormat unitFormat) const override { return true; }
|
||||
int setAdditionalExpressions(double value, Expression * dest, int availableLength, ExpressionNode::ReductionContext reductionContext) const override;
|
||||
@@ -494,7 +494,7 @@ constexpr bool strings_equal(const char * s1, const char * s2) { return *s1 == *
|
||||
class Unit : public Expression {
|
||||
friend class UnitNode;
|
||||
public:
|
||||
/* Prefixes and Representativees defined below must be defined only once and
|
||||
/* Prefixes and Representatives defined below must be defined only once and
|
||||
* all units must be constructed from their pointers. This way we can easily
|
||||
* check if two Unit objects are equal by comparing pointers. This saves us
|
||||
* from overloading the == operator on Prefix and Representative and saves
|
||||
@@ -613,7 +613,7 @@ public:
|
||||
VolumeRepresentative("gal", 128*0.0000295735295625, Prefixable::None, Prefixable::None),
|
||||
};
|
||||
/* FIXME : Some ratio are too precise too be well approximated by double.
|
||||
* Maybe switch to a rationnal representation with two int. */
|
||||
* Maybe switch to a rational representation with two int. */
|
||||
|
||||
/* Define access points to some prefixes and representatives. */
|
||||
static constexpr int k_emptyPrefixIndex = 6;
|
||||
|
||||
@@ -25,7 +25,7 @@ private:
|
||||
void deepReduceChildren(ExpressionNode::ReductionContext reductionContext) override;
|
||||
void deepBeautifyChildren(ExpressionNode::ReductionContext reductionContext) override;
|
||||
Expression shallowBeautify(ReductionContext * reductionContext) override;
|
||||
// Evalutation
|
||||
// Evaluation
|
||||
Evaluation<float> approximate(SinglePrecision p, ApproximationContext approximationContext) const override { return templatedApproximate<float>(approximationContext); }
|
||||
Evaluation<double> approximate(DoublePrecision p, ApproximationContext approximationContext) const override { return templatedApproximate<double>(approximationContext); }
|
||||
template<typename T> Evaluation<T> templatedApproximate(ApproximationContext approximationContext) const;
|
||||
|
||||
@@ -28,7 +28,7 @@ public:
|
||||
}
|
||||
|
||||
/* Derivation
|
||||
* Unlike Numbers that derivate to 0, Unreal derivates to Unreal. */
|
||||
* Unlike Numbers that derivate to 0, Unreal derivatives to Unreal. */
|
||||
bool derivate(ReductionContext reductionContext, Expression symbol, Expression symbolValue) override { return true; }
|
||||
|
||||
// Layout
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
|
||||
/* FIXME : This class is concerned with manipulating the ranges of graphing
|
||||
* window, often represented by four float xMin, xMax, yMin, yMax. Handling
|
||||
* those same four values has proven repetititve, tredious, and prone to error.
|
||||
* those same four values has proven repetitive, tedious, and prone to error.
|
||||
* This code could benefit from a data structure to regroup those values in a
|
||||
* single object. */
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@ extern "C" {
|
||||
|
||||
namespace Poincare {
|
||||
|
||||
template <typename T> bool isNegligeable(T x, T precision, T norm1, T norm2) {
|
||||
template <typename T> bool isNegligible(T x, T precision, T norm1, T norm2) {
|
||||
T absX = std::fabs(x);
|
||||
return absX <= 10.0*precision && absX/norm1 <= precision && absX/norm2 <= precision;
|
||||
}
|
||||
@@ -70,10 +70,10 @@ template <typename T> std::complex<T> ApproximationHelper::NeglectRealOrImaginar
|
||||
T magnitude1 = minimalNonNullMagnitudeOfParts(input1);
|
||||
T magnitude2 = minimalNonNullMagnitudeOfParts(input2);
|
||||
T precision = Epsilon<T>();
|
||||
if (isNegligeable(result.imag(), precision, magnitude1, magnitude2)) {
|
||||
if (isNegligible(result.imag(), precision, magnitude1, magnitude2)) {
|
||||
result.imag(0);
|
||||
}
|
||||
if (isNegligeable(result.real(), precision, magnitude1, magnitude2)) {
|
||||
if (isNegligible(result.real(), precision, magnitude1, magnitude2)) {
|
||||
result.real(0);
|
||||
}
|
||||
return result;
|
||||
|
||||
@@ -39,18 +39,18 @@ Expression ComplexCartesianNode::shallowBeautify(ReductionContext * reductionCon
|
||||
template<typename T>
|
||||
Complex<T> ComplexCartesianNode::templatedApproximate(ApproximationContext approximationContext) const {
|
||||
Evaluation<T> realEvaluation = childAtIndex(0)->approximate(T(), approximationContext);
|
||||
Evaluation<T> imagEvalution = childAtIndex(1)->approximate(T(), approximationContext);
|
||||
Evaluation<T> imagEvaluation = childAtIndex(1)->approximate(T(), approximationContext);
|
||||
assert(realEvaluation.type() == EvaluationNode<T>::Type::Complex);
|
||||
assert(imagEvalution.type() == EvaluationNode<T>::Type::Complex);
|
||||
assert(imagEvaluation.type() == EvaluationNode<T>::Type::Complex);
|
||||
std::complex<T> a = static_cast<Complex<T> &>(realEvaluation).stdComplex();
|
||||
std::complex<T> b = static_cast<Complex<T> &>(imagEvalution).stdComplex();
|
||||
std::complex<T> b = static_cast<Complex<T> &>(imagEvaluation).stdComplex();
|
||||
if ((a.imag() != (T)0.0 && !std::isnan(a.imag())) || (b.imag() != (T)0.0 && !std::isnan(b.imag()))) {
|
||||
/* a and b are supposed to be real (if they are not undefined). However,
|
||||
* due to double precision limit, the approximation of the real part or the
|
||||
* imaginary part can lead to complex values.
|
||||
* For instance, let the real part be
|
||||
* sqrt(2*sqrt(5E23+1)-1E12*sqrt(2)) ~ 1.1892E-6. Due to std::sqrt(2.0)
|
||||
* unprecision, 2*sqrt(5E23+1)-1E12*sqrt(2) < 0 which leads to
|
||||
* imprecision, 2*sqrt(5E23+1)-1E12*sqrt(2) < 0 which leads to
|
||||
* sqrt(2*sqrt(5E23+1)-1E12*sqrt(2)) being a complex number.
|
||||
* In this case, we return an undefined complex because the approximation
|
||||
* is very likely to be false. */
|
||||
|
||||
@@ -234,7 +234,7 @@ int DecimalNode::convertToText(char * buffer, int bufferSize, Preferences::Print
|
||||
*
|
||||
* We should use the UTF8Helper to manipulate chars, but it is clearer to
|
||||
* manipulate chars directly, so we just put assumptions on the char size
|
||||
* of the code points we manipuate. */
|
||||
* of the code points we manipulate. */
|
||||
assert(UTF8Decoder::CharSizeOfCodePoint('.') == 1);
|
||||
currentChar++;
|
||||
if (currentChar >= bufferSize-1) { return bufferSize-1; }
|
||||
@@ -275,7 +275,7 @@ int DecimalNode::convertToText(char * buffer, int bufferSize, Preferences::Print
|
||||
}
|
||||
}
|
||||
currentChar += mantissaLength;
|
||||
if (currentChar >= bufferSize - 1) { return bufferSize-1; } // Check if strlcpy returned prematuraly
|
||||
if (currentChar >= bufferSize - 1) { return bufferSize-1; } // Check if strlcpy returned prematurely
|
||||
if (exponent >= 0 && exponent < mantissaLength-1) {
|
||||
if (currentChar+1 >= bufferSize-1) { return bufferSize-1; }
|
||||
int decimalMarkerPosition = m_negative ? exponent + 1 : exponent;
|
||||
|
||||
@@ -102,7 +102,7 @@ T DerivativeNode::growthRateAroundAbscissa(T x, T h, ApproximationContext approx
|
||||
template<typename T>
|
||||
T DerivativeNode::riddersApproximation(ApproximationContext approximationContext, T x, T h, T * error) const {
|
||||
/* Ridders' Algorithm
|
||||
* Blibliography:
|
||||
* Bibliography:
|
||||
* - Ridders, C.J.F. 1982, Advances in Helperering Software, vol. 4, no. 2,
|
||||
* pp. 75–76. */
|
||||
|
||||
|
||||
@@ -31,7 +31,7 @@ namespace Poincare {
|
||||
* library. */
|
||||
double erfInv(double x) {
|
||||
// beware that the logarithm argument must be
|
||||
// commputed as (1.0 - x) * (1.0 + x),
|
||||
// computed as (1.0 - x) * (1.0 + x),
|
||||
// it must NOT be simplified as 1.0 - x * x as this
|
||||
// would induce rounding errors near the boundaries +/-1
|
||||
double w = - std::log((1.0 - x) * (1.0 + x));
|
||||
|
||||
@@ -570,7 +570,7 @@ bool Expression::isReal(Context * context) const {
|
||||
|
||||
bool Expression::isIdenticalTo(const Expression e) const {
|
||||
/* We use the simplification order only because it is a already-coded total
|
||||
* order on expresssions. */
|
||||
* order on expressions. */
|
||||
return ExpressionNode::SimplificationOrder(node(), e.node(), true, true) == 0;
|
||||
}
|
||||
|
||||
@@ -656,7 +656,7 @@ void Expression::beautifyAndApproximateScalar(Expression * simplifiedExpression,
|
||||
if (approximateExpression) {
|
||||
/* Step 1: Approximation
|
||||
* We compute the approximate expression from the Cartesian form to avoid
|
||||
* unprecision. For example, if the result is the ComplexCartesian(a,b),
|
||||
* imprecision. For example, if the result is the ComplexCartesian(a,b),
|
||||
* the final expression is going to be sqrt(a^2+b^2)*exp(i*atan(b/a)...
|
||||
* in Polar ComplexFormat. If we approximate this expression instead of
|
||||
* ComplexCartesian(a,b), we are going to loose precision on the resulting
|
||||
|
||||
@@ -23,7 +23,7 @@ Complex<T> HyperbolicArcTangentNode::computeOnComplex(const std::complex<T> c, P
|
||||
* this cut. We followed the convention chosen by the lib c++ of llvm on
|
||||
* ]-inf+0i, -1+0i[ (warning: atanh takes the other side of the cut values on
|
||||
* ]-inf-0i, -1-0i[) and choose the values on ]1+0i, +inf+0i[ to comply with
|
||||
* atanh(-x) = -atanh(x) and sin(artanh(x)) = x/sqrt(1-x^2). */
|
||||
* atanh(-x) = -atanh(x) and sin(atanh(x)) = x/sqrt(1-x^2). */
|
||||
if (c.imag() == 0 && c.real() > 1) {
|
||||
result.imag(-result.imag()); // other side of the cut
|
||||
}
|
||||
|
||||
@@ -247,8 +247,8 @@ Expression Logarithm::shallowReduce(ExpressionNode::ReductionContext reductionCo
|
||||
if (childAtIndex(1).type() == ExpressionNode::Type::Rational && childAtIndex(1).convert<Rational>().isInteger()) {
|
||||
Integer b = childAtIndex(1).convert<Rational>().signedIntegerNumerator();
|
||||
Integer newNumerator = simplifyLogarithmIntegerBaseInteger(r.signedIntegerNumerator(), b, a, false);
|
||||
Integer newDenomitor = simplifyLogarithmIntegerBaseInteger(r.integerDenominator(), b, a, true);
|
||||
r = Rational::Builder(newNumerator, newDenomitor);
|
||||
Integer newDenominator = simplifyLogarithmIntegerBaseInteger(r.integerDenominator(), b, a, true);
|
||||
r = Rational::Builder(newNumerator, newDenominator);
|
||||
}
|
||||
// log(r) = a0log(p0)+a1log(p1)+... with r = p0^a0*p1^a1*... (Prime decomposition)
|
||||
a.addChildAtIndexInPlace(splitLogarithmInteger(r.signedIntegerNumerator(), false, reductionContext), a.numberOfChildren(), a.numberOfChildren());
|
||||
|
||||
@@ -185,7 +185,7 @@ int Matrix::ArrayInverse(T * array, int numberOfRows, int numberOfColumns) {
|
||||
}
|
||||
}
|
||||
ArrayRowCanonize(operands, dim, 2*dim);
|
||||
// Check inversibility
|
||||
// Check invertibility
|
||||
for (int i = 0; i < dim; i++) {
|
||||
T cell = operands[i*2*dim+i];
|
||||
if (!std::isfinite(std::abs(cell)) || std::abs(cell - (T)1.0) > Expression::Epsilon<float>()) {
|
||||
@@ -407,7 +407,7 @@ Expression Matrix::createRef(ExpressionNode::ReductionContext reductionContext,
|
||||
if (ExceptionRun(ecp)) {
|
||||
/* We clone the current matrix to extract its children later. We can't clone
|
||||
* its children directly. Indeed, the current matrix node (this->node()) is
|
||||
* located before the exception checkpoint. In order to clone its chidlren,
|
||||
* located before the exception checkpoint. In order to clone its children,
|
||||
* we would temporary increase the reference counter of each child (also
|
||||
* located before the checkpoint). If an exception is raised before
|
||||
* destroying the child handle, its reference counter would be off by one
|
||||
@@ -568,7 +568,7 @@ Expression Matrix::computeInverseOrDeterminant(bool computeDeterminant, Expressi
|
||||
if (ExceptionRun(ecp)) {
|
||||
/* We clone the current matrix to extract its children later. We can't clone
|
||||
* its children directly. Indeed, the current matrix node (this->node()) is
|
||||
* located before the exception checkpoint. In order to clone its chidlren,
|
||||
* located before the exception checkpoint. In order to clone its children,
|
||||
* we would temporary increase the reference counter of each child (also
|
||||
* located before the checkpoint). If an exception is raised before
|
||||
* destroying the child handle, its reference counter would be off by one
|
||||
@@ -596,7 +596,7 @@ Expression Matrix::computeInverseOrDeterminant(bool computeDeterminant, Expressi
|
||||
}
|
||||
// Compute the inverse
|
||||
matrixAI = matrixAI.rowCanonize(reductionContext, nullptr);
|
||||
// Check inversibility
|
||||
// Check invertibility
|
||||
for (int i = 0; i < dim; i++) {
|
||||
if (!matrixAI.matrixChild(i, i).isRationalOne()) {
|
||||
return Undefined::Builder();
|
||||
|
||||
@@ -444,7 +444,7 @@ Expression Multiplication::shallowBeautify(ExpressionNode::ReductionContext * re
|
||||
if (hasUnit()) {
|
||||
Expression units;
|
||||
/* removeUnit has to be called on reduced expression but we want to modify
|
||||
* the least the expression so we use the uninvasive reduction context. */
|
||||
* the least the expression so we use the noninvasive reduction context. */
|
||||
self = self.reduceAndRemoveUnit(ExpressionNode::ReductionContext::NonInvasiveReductionContext(*reductionContext), &units);
|
||||
|
||||
if (self.isUndefined() || units.isUninitialized()) {
|
||||
|
||||
@@ -159,7 +159,7 @@ void Parser::parseNumber(Expression & leftHandSide, Token::Type stoppingType) {
|
||||
leftHandSide = m_currentToken.expression();
|
||||
// No implicit multiplication between two numbers
|
||||
if (m_nextToken.isNumber()
|
||||
// No implicit multiplication between a hexadecimal number and an identifer (avoid parsing 0x2abch as 0x2ABC*h)
|
||||
// No implicit multiplication between a hexadecimal number and an identifier (avoid parsing 0x2abch as 0x2ABC*h)
|
||||
|| (m_currentToken.is(Token::Type::HexadecimalNumber) && m_nextToken.is(Token::Type::Identifier))) {
|
||||
m_status = Status::Error;
|
||||
return;
|
||||
@@ -239,7 +239,7 @@ void Parser::parseCaret(Expression & leftHandSide, Token::Type stoppingType) {
|
||||
void Parser::parseCaretWithParenthesis(Expression & leftHandSide, Token::Type stoppingType) {
|
||||
/* When parsing 2^(4) ! (with system parentheses), the factorial should stay
|
||||
* out of the power. To do this, we tokenized ^( as one token that should be
|
||||
* matched by a closing parenthesis. Otherwise, the ! would take precendence
|
||||
* matched by a closing parenthesis. Otherwise, the ! would take precedence
|
||||
* over the power. */
|
||||
if (leftHandSide.isUninitialized()) {
|
||||
m_status = Status::Error; // Power must have a left operand
|
||||
|
||||
@@ -195,10 +195,10 @@ Complex<T> PowerNode::compute(const std::complex<T> c, const std::complex<T> d,
|
||||
* avoid weird results as e(i*pi) = -1+6E-17*i, we compute the argument of
|
||||
* the result of c^d and if arg ~ 0 [Pi], we discard the residual imaginary
|
||||
* part and if arg ~ Pi/2 [Pi], we discard the residual real part.
|
||||
* Let's determine when the arg [Pi] (or arg [Pi/2]) is negligeable:
|
||||
* Let's determine when the arg [Pi] (or arg [Pi/2]) is negligible:
|
||||
* With c = r*e^(iθ) and d = x+iy, c^d = r^x*e^(yθ)*e^i(yln(r)+xθ)
|
||||
* so arg(c^d) = y*ln(r)+xθ.
|
||||
* We consider that arg[π] is negligeable if it is negligeable compared to
|
||||
* We consider that arg[π] is negligible if it is negligible compared to
|
||||
* norm(d) = sqrt(x^2+y^2) and ln(r) = ln(norm(c)).*/
|
||||
return Complex<T>::Builder(ApproximationHelper::NeglectRealOrImaginaryPartIfNeglectable(result, c, d, false));
|
||||
}
|
||||
|
||||
@@ -243,7 +243,7 @@ PrintFloat::TextLengths PrintFloat::ConvertFloatToTextPrivate(T f, char * buffer
|
||||
|
||||
if (mode == Preferences::PrintFloatMode::Decimal && exponentInBase10 >= numberOfSignificantDigits) {
|
||||
/* Exception 1: avoid inventing digits to fill the printed float: when
|
||||
* displaying 12345 with 2 significant digis in Decimal mode for instance.
|
||||
* displaying 12345 with 2 significant digits in Decimal mode for instance.
|
||||
* This exception is caught by ConvertFloatToText and forces the mode to
|
||||
* Scientific */
|
||||
return exceptionResult;
|
||||
|
||||
@@ -233,7 +233,7 @@ TreeHandle TreeHandle::BuildWithGhostChildren(TreeNode * node) {
|
||||
assert(node != nullptr);
|
||||
TreePool * pool = TreePool::sharedPool();
|
||||
int expectedNumberOfChildren = node->numberOfChildren();
|
||||
/* Ensure the pool is syntaxically correct by creating ghost children for
|
||||
/* Ensure the pool is syntactically correct by creating ghost children for
|
||||
* nodes that have a fixed, non-zero number of children. */
|
||||
for (int i = 0; i < expectedNumberOfChildren; i++) {
|
||||
GhostNode * ghost = new (pool->alloc(sizeof(GhostNode))) GhostNode();
|
||||
|
||||
@@ -230,9 +230,9 @@ Expression Trigonometry::shallowReduceDirectFunction(Expression & e, ExpressionN
|
||||
/* Step 4.1. In radians:
|
||||
* We first check if p/q * π is already in the right quadrant:
|
||||
* p/q * π < π/2 => p/q < 2 => 2p < q */
|
||||
Integer dividand = Integer::Addition(r.unsignedIntegerNumerator(), r.unsignedIntegerNumerator());
|
||||
Integer dividend = Integer::Addition(r.unsignedIntegerNumerator(), r.unsignedIntegerNumerator());
|
||||
Integer divisor = Integer::Multiplication(r.integerDenominator(), Integer(s_piDivisor[(int)angleUnit]));
|
||||
if (divisor.isLowerThan(dividand)) {
|
||||
if (divisor.isLowerThan(dividend)) {
|
||||
/* Step 4.2. p/q * π is not in the wanted trigonometrical quadrant.
|
||||
* We could subtract n*π to p/q with n an integer.
|
||||
* Given p/q = (q'*q+r')/q, we have
|
||||
@@ -241,8 +241,8 @@ Expression Trigonometry::shallowReduceDirectFunction(Expression & e, ExpressionN
|
||||
int unaryCoefficient = 1; // store 1 or -1 for the final result.
|
||||
Integer piDivisor = Integer::Multiplication(r.integerDenominator(), Integer(s_piDivisor[(int)angleUnit]));
|
||||
IntegerDivision div = Integer::Division(r.unsignedIntegerNumerator(), piDivisor);
|
||||
dividand = Integer::Addition(div.remainder, div.remainder);
|
||||
if (divisor.isLowerThan(dividand)) {
|
||||
dividend = Integer::Addition(div.remainder, div.remainder);
|
||||
if (divisor.isLowerThan(dividend)) {
|
||||
/* Step 4.3. r'/q * π is not in the wanted trigonometrical quadrant,
|
||||
* and because r'<q (as r' is the remainder of an euclidian division
|
||||
* by q), we know that r'/q*π is in [π/2; π[.
|
||||
|
||||
@@ -79,7 +79,7 @@ Expression TrigonometryCheatTable::simplify(const Expression e, ExpressionNode::
|
||||
}
|
||||
|
||||
/* Some cheat tables values were not entered because they would never be needed
|
||||
* For instance, when simplfy a Cosine, we always compute the value for an angle
|
||||
* For instance, when simplify a Cosine, we always compute the value for an angle
|
||||
* in the top right trigonometric quadrant. */
|
||||
const TrigonometryCheatTable * TrigonometryCheatTable::Table() {
|
||||
static const Row sTableRows[] = {
|
||||
|
||||
@@ -109,7 +109,7 @@ UnitNode::Vector<int> UnitNode::Vector<int>::FromBaseUnits(const Expression base
|
||||
.current = 0,
|
||||
.temperature = 0,
|
||||
.amountOfSubstance = 0,
|
||||
.luminuousIntensity = 0,
|
||||
.luminousIntensity = 0,
|
||||
};
|
||||
int numberOfFactors;
|
||||
int factorIndex = 0;
|
||||
|
||||
@@ -987,7 +987,7 @@ QUIZ_CASE(poincare_approximation_complex_format) {
|
||||
QUIZ_CASE(poincare_approximation_mix) {
|
||||
assert_expression_approximates_to<float>("-2-3", "-5");
|
||||
assert_expression_approximates_to<float>("1.2×ℯ^(1)", "3.261938");
|
||||
assert_expression_approximates_to<float>("2ℯ^(3)", "40.1711", Radian, Metric, Cartesian, 6); // WARNING: the 7th significant digit is wrong on blackbos simulator
|
||||
assert_expression_approximates_to<float>("2ℯ^(3)", "40.1711", Radian, Metric, Cartesian, 6); // WARNING: the 7th significant digit is wrong on blackbox simulator
|
||||
assert_expression_approximates_to<float>("ℯ^2×ℯ^(1)", "20.0855", Radian, Metric, Cartesian, 6); // WARNING: the 7th significant digit is wrong on simulator
|
||||
assert_expression_approximates_to<double>("ℯ^2×ℯ^(1)", "20.085536923188");
|
||||
assert_expression_approximates_to<double>("2×3^4+2", "164");
|
||||
|
||||
@@ -393,7 +393,7 @@ QUIZ_CASE(poincare_properties_get_polynomial_coefficients) {
|
||||
assert_reduced_expression_has_polynomial_coefficient("x^2+x+2", "x", coefficient0);
|
||||
const char * coefficient1[] = {"12+(-6)×π", "12", "3", 0}; //3×x^2+12×x-6×π+12
|
||||
assert_reduced_expression_has_polynomial_coefficient("3×(x+2)^2-6×π", "x", coefficient1);
|
||||
// TODO: decomment when enable 3-degree polynomes
|
||||
// TODO: uncomment when enable 3-degree polynomials
|
||||
//const char * coefficient2[] = {"2+32×x", "2", "6", "2", 0}; //2×n^3+6×n^2+2×n+2+32×x
|
||||
//assert_reduced_expression_has_polynomial_coefficient("2×(n+1)^3-4n+32×x", "n", coefficient2);
|
||||
const char * coefficient3[] = {"1", "-π", "1", 0}; //x^2-π×x+1
|
||||
|
||||
Reference in New Issue
Block a user