mirror of
https://github.com/hneemann/Digital.git
synced 2025-09-27 06:51:37 -04:00
refactored the add-sub dependency
This commit is contained in:
parent
a4789afc8c
commit
31cd0d1b4b
@ -29,10 +29,10 @@ public class Add extends Node implements Element {
|
||||
private final ObservableValue sum;
|
||||
private final ObservableValue cOut;
|
||||
private final long mask;
|
||||
protected ObservableValue a;
|
||||
protected ObservableValue b;
|
||||
protected ObservableValue cIn;
|
||||
protected long value;
|
||||
private ObservableValue a;
|
||||
private ObservableValue b;
|
||||
private ObservableValue cIn;
|
||||
private long value;
|
||||
|
||||
/**
|
||||
* Create a new instance
|
||||
@ -49,7 +49,19 @@ public class Add extends Node implements Element {
|
||||
|
||||
@Override
|
||||
public void readInputs() throws NodeException {
|
||||
value = a.getValue() + b.getValue() + cIn.getValue();
|
||||
value = calc(a.getValue(), b.getValue(), cIn.getValue());
|
||||
}
|
||||
|
||||
/**
|
||||
* Performs the add operation
|
||||
*
|
||||
* @param a a
|
||||
* @param b b
|
||||
* @param c carry
|
||||
* @return the result
|
||||
*/
|
||||
protected long calc(long a, long b, long c) {
|
||||
return a + b + c;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1,6 +1,5 @@
|
||||
package de.neemann.digital.core.arithmetic;
|
||||
|
||||
import de.neemann.digital.core.NodeException;
|
||||
import de.neemann.digital.core.element.ElementAttributes;
|
||||
import de.neemann.digital.core.element.ElementTypeDescription;
|
||||
import de.neemann.digital.core.element.Keys;
|
||||
@ -31,7 +30,7 @@ public class Sub extends Add {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readInputs() throws NodeException {
|
||||
value = a.getValue() - b.getValue() - cIn.getValue();
|
||||
protected long calc(long a, long b, long c) {
|
||||
return a - b - c;
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user