mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-01-19 00:37:25 +01:00
[poincare] BasedInteger: use dot mutliplication sign around
binary/hexadecimal integers
This commit is contained in:
@@ -39,8 +39,7 @@ public:
|
||||
|
||||
private:
|
||||
Expression shallowReduce(ReductionContext reductionContext) override;
|
||||
LayoutShape leftLayoutShape() const override { return LayoutShape::Integer; }
|
||||
LayoutShape rightLayoutShape() const override;
|
||||
LayoutShape leftLayoutShape() const override { return LayoutShape::BinaryHexadecimal; }
|
||||
Integer::Base m_base;
|
||||
uint8_t m_numberOfDigits;
|
||||
native_uint_t m_digits[0];
|
||||
|
||||
@@ -210,6 +210,7 @@ public:
|
||||
enum class LayoutShape {
|
||||
Decimal,
|
||||
Integer,
|
||||
BinaryHexadecimal,
|
||||
OneLetter,
|
||||
MoreLetters,
|
||||
BoundaryPunctuation, // ( [ ∫
|
||||
|
||||
@@ -70,20 +70,6 @@ Expression BasedIntegerNode::shallowReduce(ReductionContext reductionContext) {
|
||||
return BasedInteger(this).shallowReduce();
|
||||
}
|
||||
|
||||
ExpressionNode::LayoutShape BasedIntegerNode::rightLayoutShape() const {
|
||||
if (m_base == Integer::Base::Hexadecimal) {
|
||||
Integer i = integer();
|
||||
if (i.isZero()) {
|
||||
return LayoutShape::Integer;
|
||||
}
|
||||
uint8_t lastHexadecimalDigit = i.digit(0) & 0xF;
|
||||
if (lastHexadecimalDigit > 9) {
|
||||
return LayoutShape::MoreLetters;
|
||||
}
|
||||
}
|
||||
return LayoutShape::Integer;
|
||||
}
|
||||
|
||||
/* BasedInteger */
|
||||
|
||||
// Constructors
|
||||
|
||||
@@ -88,32 +88,38 @@ static inline int maxInt(int x, int y) { return x > y ? x : y; }
|
||||
/* Operative symbol between two expressions depends on the layout shape on the
|
||||
* left and the right of the operator:
|
||||
*
|
||||
* | Decimal | Integer | OneLetter | MoreLetters | BundaryPunct. | Root | NthRoot | Fraction
|
||||
* --------------+---------+---------+-----------+-------------+---------------+------+---------+----------
|
||||
* Decimal | × | x | ø | × | × | × | × | ×
|
||||
* --------------+---------+---------+-----------+-------------+---------------+------+---------+----------
|
||||
* Integer | × | x | ø | • | ø | ø | • | ×
|
||||
* --------------+---------+---------+-----------+-------------+---------------+------+---------+----------
|
||||
* OneLetter | × | • | • | • | • | ø | • | ø
|
||||
* --------------+---------+---------+-----------+-------------+---------------+------+---------+----------
|
||||
* MoreLetters | × | • | • | • | • | ø | • | ø
|
||||
* --------------+---------+---------+-----------+-------------+---------------+------+---------+----------
|
||||
* BundaryPunct. | × | x | ø | ø | ø | ø | • | ×
|
||||
* --------------+---------+---------+-----------+-------------+---------------+------+---------+----------
|
||||
* Root | × | x | ø | ø | ø | ø | • | ×
|
||||
* --------------+---------+---------+-----------+-------------+---------------+------+---------+----------
|
||||
* Fraction | × | x | ø | ø | ø | ø | • | ×
|
||||
* --------------+---------+---------+-----------+-------------+---------------+------+---------+----------
|
||||
* RightOfPower | × | x | ø | ø | ø | ø | • | ×
|
||||
* | Decimal | Integer | OneLetter | MoreLetters | BundaryPunct. | Root | NthRoot | Fraction | Hexa/Binary
|
||||
* --------------+---------+---------+-----------+-------------+---------------+------+---------+----------+-------------
|
||||
* Decimal | × | x | ø | × | × | × | × | × | •
|
||||
* --------------+---------+---------+-----------+-------------+---------------+------+---------+----------+-------------
|
||||
* Integer | × | x | ø | • | ø | ø | • | × | •
|
||||
* --------------+---------+---------+-----------+-------------+---------------+------+---------+----------+-------------
|
||||
* OneLetter | × | • | • | • | • | ø | • | ø | •
|
||||
* --------------+---------+---------+-----------+-------------+---------------+------+---------+----------+-------------
|
||||
* MoreLetters | × | • | • | • | • | ø | • | ø | •
|
||||
* --------------+---------+---------+-----------+-------------+---------------+------+---------+----------+-------------
|
||||
* BundaryPunct. | × | x | ø | ø | ø | ø | • | × | •
|
||||
* --------------+---------+---------+-----------+-------------+---------------+------+---------+----------+-------------
|
||||
* Root | × | x | ø | ø | ø | ø | • | × | •
|
||||
* --------------+---------+---------+-----------+-------------+---------------+------+---------+----------+-------------
|
||||
* Fraction | × | x | ø | ø | ø | ø | • | × | •
|
||||
* --------------+---------+---------+-----------+-------------+---------------+------+---------+----------+-------------
|
||||
* RightOfPower | × | x | ø | ø | ø | ø | • | × | •
|
||||
* --------------+---------+---------+-----------+-------------+---------------+------+---------+----------+-------------
|
||||
* Hexa/Binary | • | • | • | • | • | • | • | • | •
|
||||
*
|
||||
* */
|
||||
|
||||
static int operatorSymbolBetween(ExpressionNode::LayoutShape left, ExpressionNode::LayoutShape right) {
|
||||
switch (left) {
|
||||
case ExpressionNode::LayoutShape::BinaryHexadecimal:
|
||||
return 1;
|
||||
case ExpressionNode::LayoutShape::Decimal:
|
||||
switch (right) {
|
||||
case ExpressionNode::LayoutShape::OneLetter:
|
||||
return 0;
|
||||
case ExpressionNode::LayoutShape::BinaryHexadecimal:
|
||||
return 1;
|
||||
default:
|
||||
return 2;
|
||||
}
|
||||
@@ -125,6 +131,7 @@ static int operatorSymbolBetween(ExpressionNode::LayoutShape left, ExpressionNod
|
||||
return 2;
|
||||
case ExpressionNode::LayoutShape::MoreLetters:
|
||||
case ExpressionNode::LayoutShape::NthRoot:
|
||||
case ExpressionNode::LayoutShape::BinaryHexadecimal:
|
||||
return 1;
|
||||
default:
|
||||
return 0;
|
||||
@@ -150,6 +157,7 @@ static int operatorSymbolBetween(ExpressionNode::LayoutShape left, ExpressionNod
|
||||
case ExpressionNode::LayoutShape::Integer:
|
||||
case ExpressionNode::LayoutShape::Fraction:
|
||||
return 2;
|
||||
case ExpressionNode::LayoutShape::BinaryHexadecimal:
|
||||
case ExpressionNode::LayoutShape::NthRoot:
|
||||
return 1;
|
||||
default:
|
||||
|
||||
@@ -50,13 +50,41 @@ QUIZ_CASE(poincare_expression_to_layout_multiplication_operator) {
|
||||
// BoundaryPunctuation x Root
|
||||
assert_expression_layouts_and_serializes_to(Multiplication::Builder(Cosine::Builder(Rational::Builder(2)), SquareRoot::Builder(Rational::Builder(2))), "cos(2)√\u00122\u0013");
|
||||
|
||||
// BasedInteger x OneLetter
|
||||
// 0b101π
|
||||
assert_expression_layouts_and_serializes_to(Multiplication::Builder(BasedInteger::Builder("5", Integer::Base::Binary), Symbol::Builder(UCodePointGreekSmallLetterPi)), "0b101π");
|
||||
// 0x23π
|
||||
assert_expression_layouts_and_serializes_to(Multiplication::Builder(BasedInteger::Builder("35", Integer::Base::Hexadecimal), Symbol::Builder(UCodePointGreekSmallLetterPi)), "0x23π");
|
||||
// 0x2Aπ
|
||||
assert_expression_layouts_and_serializes_to(Multiplication::Builder(BasedInteger::Builder("42", Integer::Base::Hexadecimal), Symbol::Builder(UCodePointGreekSmallLetterPi)), "0x2A·π");
|
||||
// BasedInteger x ?
|
||||
// 0b101·0.23
|
||||
assert_expression_layouts_and_serializes_to(Multiplication::Builder(BasedInteger::Builder("5", Integer::Base::Binary), Decimal::Builder("23", -1)), "0b101·0.23");
|
||||
// 0x2A3·23242
|
||||
assert_expression_layouts_and_serializes_to(Multiplication::Builder(BasedInteger::Builder("675", Integer::Base::Hexadecimal), Rational::Builder(23242)), "0x2A3·23242");
|
||||
// 0b101·π
|
||||
assert_expression_layouts_and_serializes_to(Multiplication::Builder(BasedInteger::Builder("5", Integer::Base::Binary), Symbol::Builder(UCodePointGreekSmallLetterPi)), "0b101·π");
|
||||
// 0x2A3·abc
|
||||
assert_expression_layouts_and_serializes_to(Multiplication::Builder(BasedInteger::Builder("675", Integer::Base::Hexadecimal), Symbol::Builder("abc", 3)), "0x2A3·abc");
|
||||
// 0b101·(1+2)
|
||||
assert_expression_layouts_and_serializes_to(Multiplication::Builder(BasedInteger::Builder("5", Integer::Base::Binary), Parenthesis::Builder(Addition::Builder(Rational::Builder(1), Rational::Builder(2)))), "0b101·(1+2)");
|
||||
// 0x2A3·√(2)
|
||||
assert_expression_layouts_and_serializes_to(Multiplication::Builder(BasedInteger::Builder("675", Integer::Base::Hexadecimal), SquareRoot::Builder(Rational::Builder(2))), "0x2A3·√\u00122\u0013");
|
||||
// 0b101·root(2,3)
|
||||
assert_expression_layouts_and_serializes_to(Multiplication::Builder(BasedInteger::Builder("5", Integer::Base::Binary), NthRoot::Builder(Rational::Builder(2), Rational::Builder(3))), "0b101·root\u0012\u00122\u0013,\u00123\u0013\u0013");
|
||||
// 0x2A3·2/3
|
||||
assert_expression_layouts_and_serializes_to(Multiplication::Builder(BasedInteger::Builder("675", Integer::Base::Hexadecimal), Rational::Builder(2,3)), "0x2A3·\u0012\u00122\u0013/\u00123\u0013\u0013");
|
||||
|
||||
// ? x BasedInteger
|
||||
// 0.23·0x2A3
|
||||
assert_expression_layouts_and_serializes_to(Multiplication::Builder(Decimal::Builder("23", -1), BasedInteger::Builder("675", Integer::Base::Hexadecimal)), "0.23·0x2A3");
|
||||
// 23242·0b101
|
||||
assert_expression_layouts_and_serializes_to(Multiplication::Builder(Rational::Builder(23242),BasedInteger::Builder("5", Integer::Base::Binary)), "23242·0b101");
|
||||
// π·0x2A3
|
||||
assert_expression_layouts_and_serializes_to(Multiplication::Builder(Symbol::Builder(UCodePointGreekSmallLetterPi), BasedInteger::Builder(675, Integer::Base::Hexadecimal)), "π·0x2A3");
|
||||
// abc·0b101
|
||||
assert_expression_layouts_and_serializes_to(Multiplication::Builder(Symbol::Builder("abc", 3), BasedInteger::Builder(5, Integer::Base::Binary)), "abc·0b101");
|
||||
// (1+2)·0x2A3
|
||||
assert_expression_layouts_and_serializes_to(Multiplication::Builder(Parenthesis::Builder(Addition::Builder(Rational::Builder(1), Rational::Builder(2))), BasedInteger::Builder(675, Integer::Base::Hexadecimal)), "(1+2)·0x2A3");
|
||||
// √(2)·0b101
|
||||
assert_expression_layouts_and_serializes_to(Multiplication::Builder(SquareRoot::Builder(Rational::Builder(2)),BasedInteger::Builder(5, Integer::Base::Binary)), "√\u00122\u0013·0b101");
|
||||
// root(2,3)·0x2A3
|
||||
assert_expression_layouts_and_serializes_to(Multiplication::Builder(NthRoot::Builder(Rational::Builder(2), Rational::Builder(3)), BasedInteger::Builder(675, Integer::Base::Hexadecimal)), "root\u0012\u00122\u0013,\u00123\u0013\u0013·0x2A3");
|
||||
// 2/3·0b101
|
||||
assert_expression_layouts_and_serializes_to(Multiplication::Builder(Rational::Builder(2,3),BasedInteger::Builder(5, Integer::Base::Binary)), "\u0012\u00122\u0013/\u00123\u0013\u0013·0b101");
|
||||
|
||||
// 2√(2)
|
||||
assert_expression_layouts_and_serializes_to(Multiplication::Builder(Rational::Builder(2), SquareRoot::Builder(Rational::Builder(2))), "2√\u00122\u0013");
|
||||
|
||||
Reference in New Issue
Block a user