mirror of
https://github.com/hneemann/Digital.git
synced 2025-09-14 07:17:13 -04:00
adds an option to the div component, to select if the remainder of a signed division should always be positive or not, closes #525
This commit is contained in:
parent
b48bd4cb8a
commit
d7557aae31
@ -30,12 +30,14 @@ public class Div extends Node implements Element, Countable {
|
||||
.addAttribute(Keys.ROTATE)
|
||||
.addAttribute(Keys.LABEL)
|
||||
.addAttribute(Keys.BITS)
|
||||
.addAttribute(Keys.SIGNED);
|
||||
.addAttribute(Keys.SIGNED)
|
||||
.addAttribute(Keys.REMAINDER_POSITIVE);
|
||||
|
||||
private final ObservableValue quotient;
|
||||
private final ObservableValue remainder;
|
||||
private final int bits;
|
||||
private final boolean signed;
|
||||
private final boolean remainderPositive;
|
||||
private ObservableValue a;
|
||||
private ObservableValue b;
|
||||
private long q;
|
||||
@ -51,6 +53,7 @@ public class Div extends Node implements Element, Countable {
|
||||
bits = attributes.get(Keys.BITS);
|
||||
this.quotient = new ObservableValue("q", bits).setPinDescription(DESCRIPTION);
|
||||
this.remainder = new ObservableValue("r", bits).setPinDescription(DESCRIPTION);
|
||||
remainderPositive = attributes.get(Keys.REMAINDER_POSITIVE);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -64,7 +67,7 @@ public class Div extends Node implements Element, Countable {
|
||||
r = av % bv;
|
||||
|
||||
// make the remainder positive
|
||||
if (r < 0) {
|
||||
if (remainderPositive && r < 0) {
|
||||
if (bv >= 0) {
|
||||
r += bv;
|
||||
q--;
|
||||
|
@ -274,6 +274,12 @@ public final class Keys {
|
||||
public static final Key<Boolean> SIGNED
|
||||
= new Key<>("Signed", false).allowGroupEdit();
|
||||
|
||||
/**
|
||||
* Selects if the reminder of the division is always positive
|
||||
*/
|
||||
public static final Key<Boolean> REMAINDER_POSITIVE
|
||||
= new Key<>("remainderPositive", true).setDependsOn(SIGNED);
|
||||
|
||||
/**
|
||||
* the data key for memory
|
||||
*/
|
||||
|
@ -1172,16 +1172,22 @@ Sind evtl. die Namen der Variablen nicht eindeutig?</string>
|
||||
Die Eingangsbits müssen vollständig und eindeutig angegeben werden.</string>
|
||||
<string name="key_OutputSplitting">Ausgangsaufteilung</string><!-- Splitter -->
|
||||
<string name="key_OutputSplitting_tt">Sollen z.B. je vier Bits, zwei Bits und noch einmal zwei Bits als Ausgänge
|
||||
verwendet werden, kann das mit der Eingabe "4,2,2" konfiguriert werden. Die Zahl gibt dabei jeweils die Bitanzahl an.
|
||||
verwendet werden, kann das mit der Eingabe "4,2,2" konfiguriert werden. Die Zahl gibt dabei jeweils die
|
||||
Bitanzahl an.
|
||||
Als Vereinfachung kann das *-Zeichen verwendet werden: Mit "[Bits]*[Anzahl]" wie "1*16" können 16 einzelne Bits
|
||||
konfiguriert werden.
|
||||
Es können auch die zu verwendenden Bits direkt und in beliebiger Reihenfolge angegeben werden. So werden mit der
|
||||
Eingabe"4-7,0-3" die Bits 4-7 und 0-3 konfiguriert. Diese Notation erlaubt eine beliebige Bit-Anordnung.
|
||||
Ausgangsbits können auch mehrfach ausgegeben werden: "0-7,1-6,4-7"</string>
|
||||
Ausgangsbits können auch mehrfach ausgegeben werden: "0-7,1-6,4-7"
|
||||
</string>
|
||||
<string name="key_SelectorBits">Anzahl der Auswahlbits</string><!-- Multiplexer, Demultiplexer, Decoder -->
|
||||
<string name="key_SelectorBits_tt">Anzahl der Bits, die in der Auswahlleitung vorhanden sind.</string>
|
||||
<string name="key_Signed">Operation mit Vorzeichen</string><!-- Comparator, Div -->
|
||||
<string name="key_Signed_tt">Wenn gesetzt, findet die Operation vorzeichenrichtig (2-er Komplement) statt.</string>
|
||||
<string name="key_remainderPositive">Rest immer positiv</string>
|
||||
<string name="key_remainderPositive_tt">Wenn gesetzt, ist der Rest einer vorzeichenbehafteten Division immer
|
||||
positiv.
|
||||
</string>
|
||||
<string name="key_Closed">Geschlossen</string><!-- Switch -->
|
||||
<string name="key_Closed_tt">Gibt an, ob der Schalter bei Modelstart offen oder geschlossen ist.</string>
|
||||
<string name="key_Value">Wert</string><!-- Const -->
|
||||
|
@ -1150,11 +1150,14 @@
|
||||
can be used: 16 bits can be configured with "[Bits]*[Number]" as "1*16".
|
||||
It is also possible to specify the bits to be used directly and in any order.
|
||||
For example, "4-7,0-3" configures bits 4-7 and 0-3. This notation allows any bit arrangement.
|
||||
Output bits can also be output several times: "0-7,1-6,4-7"</string>
|
||||
Output bits can also be output several times: "0-7,1-6,4-7"
|
||||
</string>
|
||||
<string name="key_SelectorBits">Number of Selector Bits</string><!-- Multiplexer, Demultiplexer, Decoder -->
|
||||
<string name="key_SelectorBits_tt">Number of bits used for the selector input.</string>
|
||||
<string name="key_Signed">Signed Operation</string><!-- Comparator, Div -->
|
||||
<string name="key_Signed_tt">If selected the operation is performed with signed (2th complement) values.</string>
|
||||
<string name="key_remainderPositive">Remainder always positive</string>
|
||||
<string name="key_remainderPositive_tt">If set, the remainder of a signed division is always positive.</string>
|
||||
<string name="key_Closed">Closed</string><!-- Switch -->
|
||||
<string name="key_Closed_tt">Sets the initial state of the switch.</string>
|
||||
<string name="key_Value">Value</string><!-- Const -->
|
||||
|
Loading…
x
Reference in New Issue
Block a user