Skip to content

Commit 81ced86

Browse files
authored
Merge pull request #308 from joecrop/logic-toolbox
Logic Toolbox
2 parents 18f979d + c1f5b4a commit 81ced86

25 files changed

+1887
-9
lines changed

apps/calculation/additional_outputs/integer_list_controller.cpp

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#include "integer_list_controller.h"
22
#include <poincare/based_integer.h>
3+
#include <poincare/opposite.h>
34
#include <poincare/integer.h>
5+
#include <poincare/logarithm.h>
46
#include <poincare/empty_layout.h>
57
#include <poincare/factor.h>
68
#include "../app.h"
@@ -26,10 +28,30 @@ Integer::Base baseAtIndex(int index) {
2628
void IntegerListController::setExpression(Poincare::Expression e) {
2729
ExpressionsListController::setExpression(e);
2830
static_assert(k_maxNumberOfRows >= k_indexOfFactorExpression + 1, "k_maxNumberOfRows must be greater than k_indexOfFactorExpression");
29-
assert(!m_expression.isUninitialized() && m_expression.type() == ExpressionNode::Type::BasedInteger);
30-
Integer integer = static_cast<BasedInteger &>(m_expression).integer();
31-
for (int index = 0; index < k_indexOfFactorExpression; ++index) {
32-
m_layouts[index] = integer.createLayout(baseAtIndex(index));
31+
assert(!m_expression.isUninitialized() && m_expression.type() == ExpressionNode::Type::BasedInteger || (m_expression.type() == ExpressionNode::Type::Opposite && m_expression.childAtIndex(0).type() == ExpressionNode::Type::BasedInteger));
32+
assert(!m_expression.isUninitialized());
33+
34+
if (m_expression.type() == ExpressionNode::Type::BasedInteger) {
35+
Integer integer = static_cast<BasedInteger &>(m_expression).integer();
36+
for (int index = 0; index < k_indexOfFactorExpression; ++index) {
37+
m_layouts[index] = integer.createLayout(baseAtIndex(index));
38+
}
39+
}
40+
else
41+
{
42+
Opposite b = static_cast<Opposite &>(m_expression);
43+
Expression e = b.childAtIndex(0);
44+
Integer childInt = static_cast<BasedInteger &>(e).integer();
45+
childInt.setNegative(true);
46+
Integer num_bits = Integer::CeilingLog2(childInt);
47+
Integer integer = Integer::TwosComplementToBits(childInt, num_bits);
48+
for (int index = 0; index < k_indexOfFactorExpression; ++index) {
49+
if(baseAtIndex(index) == Integer::Base::Decimal) {
50+
m_layouts[index] = childInt.createLayout(baseAtIndex(index));
51+
} else {
52+
m_layouts[index] = integer.createLayout(baseAtIndex(index));
53+
}
54+
}
3355
}
3456
// Computing factorExpression
3557
Expression factor = Factor::Builder(m_expression.clone());

apps/calculation/calculation.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ friend CalculationStore;
9797
AdditionalInformationType additionalInformationType(Poincare::Context * context);
9898
private:
9999
static constexpr KDCoordinate k_heightComputationFailureHeight = 50;
100-
static constexpr const char * k_maximalIntegerWithAdditionalInformation = "10000000000000000";
100+
static constexpr const char * k_maximalIntegerWithAdditionalInformation = "18446744073709551617"; // 2^64 + 1
101101

102102
void setHeights(KDCoordinate height, KDCoordinate expandedHeight);
103103

apps/math_toolbox.cpp

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,34 @@ const ToolboxMessageTree matricesChildren[] = {
7979
const ToolboxMessageTree vectorsChildren[] = {
8080
ToolboxMessageTree::Leaf(I18n::Message::DotCommandWithArg, I18n::Message::Dot),
8181
ToolboxMessageTree::Leaf(I18n::Message::CrossCommandWithArg, I18n::Message::Cross),
82-
ToolboxMessageTree::Leaf(I18n::Message::NormVectorCommandWithArg, I18n::Message::NormVector),
82+
ToolboxMessageTree::Leaf(I18n::Message::NormVectorCommandWithArg, I18n::Message::NormVector)
83+
};
84+
85+
const ToolboxMessageTree logicExplicitChildren[] = {
86+
ToolboxMessageTree::Leaf(I18n::Message::LogicalNotExplicitCommandWithArg, I18n::Message::LogicalNot),
87+
ToolboxMessageTree::Leaf(I18n::Message::LogicalShiftRightArithmeticExplicitCommandWithArg, I18n::Message::LogicalShiftRightArithmetic),
88+
ToolboxMessageTree::Leaf(I18n::Message::LogicalRotateLeftExplicitCommandWithArg, I18n::Message::LogicalRotateLeft),
89+
ToolboxMessageTree::Leaf(I18n::Message::LogicalRotateRightExplicitCommandWithArg, I18n::Message::LogicalRotateRight),
90+
ToolboxMessageTree::Leaf(I18n::Message::LogicalBitsClearExplicitCommandWithArg, I18n::Message::LogicalBitsClear)};
91+
92+
const ToolboxMessageTree logicChildren[] = {
93+
ToolboxMessageTree::Node(I18n::Message::ExplicitNumberOfBits, logicExplicitChildren),
94+
ToolboxMessageTree::Leaf(I18n::Message::LogicalAndCommandWithArg, I18n::Message::LogicalAnd),
95+
ToolboxMessageTree::Leaf(I18n::Message::LogicalOrCommandWithArg, I18n::Message::LogicalOr),
96+
ToolboxMessageTree::Leaf(I18n::Message::LogicalXorCommandWithArg, I18n::Message::LogicalXor),
97+
ToolboxMessageTree::Leaf(I18n::Message::LogicalNotCommandWithArg, I18n::Message::LogicalNot),
98+
ToolboxMessageTree::Leaf(I18n::Message::LogicalShiftLeftCommandWithArg, I18n::Message::LogicalShiftLeft),
99+
ToolboxMessageTree::Leaf(I18n::Message::LogicalShiftRightCommandWithArg, I18n::Message::LogicalShiftRight),
100+
ToolboxMessageTree::Leaf(I18n::Message::LogicalShiftRightArithmeticCommandWithArg, I18n::Message::LogicalShiftRightArithmetic),
101+
ToolboxMessageTree::Leaf(I18n::Message::LogicalRotateLeftCommandWithArg, I18n::Message::LogicalRotateLeft),
102+
ToolboxMessageTree::Leaf(I18n::Message::LogicalRotateRightCommandWithArg, I18n::Message::LogicalRotateRight),
103+
ToolboxMessageTree::Leaf(I18n::Message::LogicalBitGetCommandWithArg, I18n::Message::LogicalBitGet),
104+
ToolboxMessageTree::Leaf(I18n::Message::LogicalBitSetCommandWithArg, I18n::Message::LogicalBitSet),
105+
ToolboxMessageTree::Leaf(I18n::Message::LogicalBitClearCommandWithArg, I18n::Message::LogicalBitClear),
106+
ToolboxMessageTree::Leaf(I18n::Message::LogicalBitFlipCommandWithArg, I18n::Message::LogicalBitFlip),
107+
ToolboxMessageTree::Leaf(I18n::Message::LogicalBitsClearCommandWithArg, I18n::Message::LogicalBitsClear),
108+
ToolboxMessageTree::Leaf(I18n::Message::TwosComplementToBitsCommandWithArg, I18n::Message::TwosComplementToBits),
109+
ToolboxMessageTree::Leaf(I18n::Message::CeilingLog2CommandWithArg, I18n::Message::CeilingLog2)
83110
};
84111

85112
const ToolboxMessageTree matricesAndVectorsChildren[] = {
@@ -879,7 +906,8 @@ const ToolboxMessageTree menu[] = {
879906
ToolboxMessageTree::Node(I18n::Message::HyperbolicTrigonometry, trigonometryChildren),
880907
ToolboxMessageTree::Node(I18n::Message::Fluctuation, predictionChildren),
881908
ToolboxMessageTree::Node(I18n::Message::Chemistry, chemistry),
882-
ToolboxMessageTree::Node(I18n::Message::Physics, Physics)
909+
ToolboxMessageTree::Node(I18n::Message::Physics, Physics),
910+
ToolboxMessageTree::Node(I18n::Message::Logic, logicChildren),
883911
};
884912

885913
const ToolboxMessageTree toolboxModel = ToolboxMessageTree::Node(I18n::Message::Toolbox, menu);

apps/shared.universal.i18n

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -489,3 +489,28 @@ Rstvt_Water = "1.01·10^3_Ω_m"
489489
Rstvt_Air = "1.00·10^9_Ω_m"
490490
Rstvt_Glass = "5.00·10^14_Ω_m"
491491
Rstvt_Wood = "1.00·10^3_Ω_m"
492+
LogicalAnd = "a AND b"
493+
LogicalAndCommandWithArg = "and(a,b)"
494+
LogicalBitClearCommandWithArg = "bclr(a,b)"
495+
LogicalBitFlipCommandWithArg = "bflp(a,b)"
496+
LogicalBitGetCommandWithArg = "bit(a,b)"
497+
LogicalBitSetCommandWithArg = "bset(a,b)"
498+
LogicalBitsClearCommandWithArg = "bic(a,b)"
499+
LogicalBitsClearExplicitCommandWithArg = "bic(a,b,n)"
500+
LogicalNot = "NOT a"
501+
LogicalNotCommandWithArg = "not(a)"
502+
LogicalNotExplicitCommandWithArg = "not(a,n)"
503+
LogicalOr = "a OR b"
504+
LogicalOrCommandWithArg = "or(a,b)"
505+
LogicalShiftLeftCommandWithArg = "sll(a,s)"
506+
LogicalShiftRightArithmeticCommandWithArg = "sra(a,s)"
507+
LogicalShiftRightArithmeticExplicitCommandWithArg = "sra(a,s,n)"
508+
LogicalShiftRightCommandWithArg = "srl(a,s)"
509+
LogicalRotateLeftCommandWithArg = "rol(a,r)"
510+
LogicalRotateLeftExplicitCommandWithArg = "rol(a,r,n)"
511+
LogicalRotateRightCommandWithArg = "ror(a,r)"
512+
LogicalRotateRightExplicitCommandWithArg = "ror(a,r,n)"
513+
LogicalXor = "a XOR b"
514+
LogicalXorCommandWithArg = "xor(a,r)"
515+
TwosComplementToBitsCommandWithArg = "tc(a,n)"
516+
CeilingLog2CommandWithArg = "clog2(a)"

apps/toolbox.de.i18n

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -512,5 +512,19 @@ HartreeConstantTag = "Hartbaum-Konstante"
512512
MagneticFluxQuantumTag = "Magnetisches Fluss-Quantum"
513513
ConductanceQuantumTag = "Leitwertquantum"
514514
CirculationQuantumTag = "Auflage-Quantum"
515+
Logic = "Logik"
516+
LogicalBitClear = "Bit b in a löschen"
517+
LogicalBitFlip = "Bit b in a umkehren"
518+
LogicalBitGet = "Bit b aus a lesen"
519+
LogicalBitSet = "Bit b in a setzen"
520+
LogicalBitsClear = "a AND NOT b"
521+
LogicalShiftLeft = "Bitverschiebung links von a um s"
522+
LogicalShiftRightArithmetic = "Arithm. Versch. rechts von a um s"
523+
LogicalShiftRight = "Bitverschiebung rechts von a um s"
524+
LogicalRotateLeft = "Rotieren von a um r Bit n. links"
525+
LogicalRotateRight= "Rotieren von a um r Bit n. rechts"
526+
TwosComplementToBits = "Äquivalent im Zweierkomplement"
527+
CeilingLog2 = "Anzahl der Bits, die zum Speichern von a benötigt werden"
528+
ExplicitNumberOfBits = "Explizite Bitbreite"
515529
MatricesAndVectors = "Matrizen und Vektoren"
516530
Factorial = "Fakultät"

apps/toolbox.en.i18n

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -512,5 +512,19 @@ HartreeConstantTag = "Hartree Constant"
512512
MagneticFluxQuantumTag = "Magnetic Flux Quantum"
513513
ConductanceQuantumTag = "Conductance Quantum"
514514
CirculationQuantumTag = "Circulation Quantum"
515+
Logic = "Logic"
516+
LogicalBitClear = "Clear bit b in a"
517+
LogicalBitFlip = "Flip bit b in a"
518+
LogicalBitGet = "Get bit b in a"
519+
LogicalBitSet = "Set bit b in a"
520+
LogicalBitsClear = "Clear a with b [a AND NOT b]"
521+
LogicalShiftLeft = "Logical shift left [a << s]"
522+
LogicalShiftRightArithmetic = "Arithmetic shift right [a >>> s]"
523+
LogicalShiftRight = "Logical shift right [a >> s]"
524+
LogicalRotateLeft = "Rotate r bits of a to the left"
525+
LogicalRotateRight= "Rotate r bits of a to the right"
526+
TwosComplementToBits = "Two's complement equivalent"
527+
CeilingLog2 = "Number of bits needed to store a"
528+
ExplicitNumberOfBits = "Explicit number of bits"
515529
MatricesAndVectors = "Matrices and vectors"
516530
Factorial = "Factorial"

apps/toolbox.es.i18n

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -512,5 +512,19 @@ HartreeConstantTag = "Constante de Hartree"
512512
MagneticFluxQuantumTag = "Flujo Magnético Cuántico"
513513
ConductanceQuantumTag = "Conductancia Quantum"
514514
CirculationQuantumTag = "Circulación Quantum"
515+
Logic = "Lógico"
516+
LogicalBitClear = "Borrar bit número b en a"
517+
LogicalBitFlip = "Voltear el bit número b en a"
518+
LogicalBitGet = "Obtener el bit número b en a"
519+
LogicalBitSet = "Establecer el número de bit b en a"
520+
LogicalBitsClear = "Borrar a con bits en b"
521+
LogicalShiftLeft = "Desplazamiento lógico izquierda"
522+
LogicalShiftRightArithmetic = "Desplazamiento aritmético derecha"
523+
LogicalShiftRight = "Desplazamiento lógico derecha"
524+
LogicalRotateLeft = "Gire r bits de a hacia izquierda"
525+
LogicalRotateRight= "Gire r bits de a hacia derecha"
526+
TwosComplementToBits = "Equivalente en complemento a dos"
527+
CeilingLog2 = "Número de bits necesarios para almacenar a"
528+
ExplicitNumberOfBits = "Número explícito de bits"
515529
MatricesAndVectors = "Matrices y vectores"
516530
Factorial = "Factorial"

apps/toolbox.fr.i18n

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -512,5 +512,19 @@ HartreeConstantTag = "Constante de Hartree"
512512
MagneticFluxQuantumTag = "Quantum de Flux Magnétique"
513513
ConductanceQuantumTag = "Quantum de Conductance"
514514
CirculationQuantumTag = "Quantum de Circulation"
515+
Logic = "Logique"
516+
LogicalBitClear = "Effacer le bit numéro b dans a"
517+
LogicalBitFlip = "Inverser le bit numéro b dans a"
518+
LogicalBitGet = "Obtenir le bit numéro b dans a"
519+
LogicalBitSet = "Mettre le bit numéro b dans a"
520+
LogicalBitsClear = "Effacer bits b ds a [a AND NOT b]"
521+
LogicalShiftLeft = "Décalage logique gauche [a << s]"
522+
LogicalShiftRightArithmetic = "Décalage arith. droite [a >>> s]"
523+
LogicalShiftRight = "Décalage logique droite [a >> s]"
524+
LogicalRotateLeft = "Rotation gauche de a par r bits"
525+
LogicalRotateRight= "Rotation droite de a par r bits"
526+
TwosComplementToBits = "Equivalent en complément à deux"
527+
CeilingLog2 = "Nb de bits nécessaires pour stocker a"
528+
ExplicitNumberOfBits = "Nombre indiqué de bits"
515529
MatricesAndVectors = "Matrices et vecteurs"
516530
Factorial = "Factorielle"

apps/toolbox.hu.i18n

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -512,4 +512,18 @@ HartreeConstantTag = "Hartree Állandó"
512512
MagneticFluxQuantumTag = "Mágneses Fluxuskvantum"
513513
ConductanceQuantumTag = "Vezetőképesség Kvantum"
514514
CirculationQuantumTag = "Keringési Kvantum"
515+
Logic = "Logika"
516+
LogicalBitClear = "Tiszta bit b ban ben a"
517+
LogicalBitFlip = "Flip bit b ban ben a"
518+
LogicalBitGet = "Kap bit b ban ben a"
519+
LogicalBitSet = "Készlet bit b ban ben a"
520+
LogicalBitsClear = "Tiszta a val vel b [a AND NOT b]"
521+
LogicalShiftLeft = "Logikai eltolás balra [a << s]"
522+
LogicalShiftRightArithmetic = "Aritmetikai eltolás jobbra [a >>> s]"
523+
LogicalShiftRight = "Logikai eltolás jobbra [a >> s]"
524+
LogicalRotateLeft = "Forog r bitek nak a balra"
525+
LogicalRotateRight= "Forog r bitek nak a jobbra"
526+
TwosComplementToBits = "Kettő komplementere egyenértékű"
527+
CeilingLog2 = "Az a tárolásához szükséges bitek száma"
528+
ExplicitNumberOfBits = "Explicit bitszám"
515529
MatricesAndVectors = "Mátrixok és vektorok"

apps/toolbox.it.i18n

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -512,4 +512,18 @@ HartreeConstantTag = "Costante di Hartree"
512512
MagneticFluxQuantumTag = "Flusso magnetico quantico"
513513
ConductanceQuantumTag = "Conduttanza quantistica"
514514
CirculationQuantumTag = "Circolazione quantistica"
515+
Logic = "Logica"
516+
LogicalBitClear = "Cancella il numero di bit b in a"
517+
LogicalBitFlip = "Capovolgere il bit numero b in a"
518+
LogicalBitGet = "Ottieni il bit numero b in a"
519+
LogicalBitSet = "Impostare il numero di bit b in a"
520+
LogicalBitsClear = "Cancella a con b [a AND NOT b]"
521+
LogicalShiftLeft = "Spostamento logico a sinistra"
522+
LogicalShiftRightArithmetic = "Spostamento aritmetico a destra"
523+
LogicalShiftRight = "Spostamento logico a destra"
524+
LogicalRotateLeft = "Ruota r bit di a verso sinistra"
525+
LogicalRotateRight= "Ruota r bit di a verso destra"
526+
TwosComplementToBits = "Equivalente in complemento di due"
527+
CeilingLog2 = "Numero di bit necessari per memorizzare a"
528+
ExplicitNumberOfBits = "Numero esplicito di bit"
515529
MatricesAndVectors = "Matrici e vettori"

0 commit comments

Comments
 (0)