Numworks Epsilon  1.4.1
Graphing Calculator Operating System
decimal.h
Go to the documentation of this file.
1 #ifndef POINCARE_DECIMAL_H
2 #define POINCARE_DECIMAL_H
3 
5 #include <poincare/integer.h>
6 
7 namespace Poincare {
8 
9 /* A decimal as 0.01234 is stored that way:
10  * - m_mantissa = 1234
11  * - m_exponent = -2
12  */
13 
14 class Decimal : public StaticHierarchy<0> {
15 public:
16  static int exponent(const char * integralPart, int integralPartLength, const char * fractionalPart, int fractionalPartLength, const char * exponent, int exponentLength, bool exponentNegative);
17  static Integer mantissa(const char * integralPart, int integralPartLength, const char * fractionalPart, int fractionalPartLength, bool negative);
19  Decimal(double f);
20  int exponent() const { return m_exponent; }
21  Integer mantissa() const { return m_mantissa; }
22  // Expression subclassing
23  Type type() const override;
24  Expression * clone() const override;
25  int writeTextInBuffer(char * buffer, int bufferSize, int numberOfSignificantDigits = PrintFloat::k_numberOfStoredSignificantDigits) const override;
26  Sign sign() const override { return m_mantissa.isNegative() ? Sign::Negative : Sign::Positive; }
27 private:
28  constexpr static int k_doublePrecision = 15;
29  constexpr static double k_biggestMantissaFromDouble = 999999999999999;
30  constexpr static int k_maxDoubleExponent = 308;
31  int numberOfDigitsInMantissaWithoutSign() const;
32  /* Comparison */
33  int simplificationOrderSameType(const Expression * e, bool canBeInterrupted) const override;
34  /* Layout */
35  bool needParenthesisWithParent(const Expression * e) const override;
36  ExpressionLayout * privateCreateLayout(PrintFloat::Mode floatDisplayMode, ComplexFormat complexFormat) const override;
37  /* Simplification */
38  Expression * shallowReduce(Context& context, AngleUnit angleUnit) override;
39  Expression * shallowBeautify(Context& context, AngleUnit angleUnit) override;
40  /* Evaluation */
41  Expression * privateApproximate(SinglePrecision p, Context& context, AngleUnit angleUnit) const override { return templatedApproximate<float>(context, angleUnit); }
42  Expression * privateApproximate(DoublePrecision p, Context& context, AngleUnit angleUnit) const override { return templatedApproximate<double>(context, angleUnit); }
43  template<typename T> Expression * templatedApproximate(Context& context, Expression::AngleUnit angleUnit) const;
44 
45  constexpr static int k_maxLength = 15;
46  Integer m_mantissa;
47  int m_exponent;
48 };
49 
50 }
51 
52 #endif
int writeTextInBuffer(char *buffer, int bufferSize, int numberOfSignificantDigits=PrintFloat::k_numberOfStoredSignificantDigits) const override
Definition: decimal.cpp:116
int exponent() const
Definition: decimal.h:20
bool isNegative() const
Definition: integer.h:43
Decimal(Integer mantissa, int exponent)
Definition: decimal.cpp:74
Sign sign() const override
Definition: decimal.h:26
Type type() const override
Definition: decimal.cpp:102
Integer mantissa() const
Definition: decimal.h:21
Expression * clone() const override
Definition: decimal.cpp:106