mirror of
https://github.com/hneemann/Digital.git
synced 2025-09-15 15:58:41 -04:00
fixed 64 bit bugs in basic gates, closes #234
This commit is contained in:
parent
a03781c606
commit
0cea738d74
@ -33,8 +33,8 @@ public class And extends Function {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int calculate(ArrayList<ObservableValue> inputs) throws NodeException {
|
||||
int f = -1;
|
||||
protected long calculate(ArrayList<ObservableValue> inputs) throws NodeException {
|
||||
long f = -1;
|
||||
for (ObservableValue i : inputs) {
|
||||
f &= i.getValue();
|
||||
}
|
||||
|
@ -30,6 +30,6 @@ abstract class Function extends FanIn {
|
||||
getOutput().setValue(value);
|
||||
}
|
||||
|
||||
protected abstract int calculate(ArrayList<ObservableValue> inputs) throws NodeException;
|
||||
protected abstract long calculate(ArrayList<ObservableValue> inputs) throws NodeException;
|
||||
|
||||
}
|
||||
|
@ -33,7 +33,7 @@ public class NAnd extends And {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int calculate(ArrayList<ObservableValue> inputs) throws NodeException {
|
||||
protected long calculate(ArrayList<ObservableValue> inputs) throws NodeException {
|
||||
return ~super.calculate(inputs);
|
||||
}
|
||||
}
|
||||
|
@ -33,7 +33,7 @@ public class NOr extends Or {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int calculate(ArrayList<ObservableValue> inputs) throws NodeException {
|
||||
protected long calculate(ArrayList<ObservableValue> inputs) throws NodeException {
|
||||
return ~super.calculate(inputs);
|
||||
}
|
||||
}
|
||||
|
@ -33,8 +33,8 @@ public class Or extends Function {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int calculate(ArrayList<ObservableValue> inputs) throws NodeException {
|
||||
int f = 0;
|
||||
protected long calculate(ArrayList<ObservableValue> inputs) throws NodeException {
|
||||
long f = 0;
|
||||
for (ObservableValue i : inputs) {
|
||||
f |= i.getValue();
|
||||
}
|
||||
|
@ -33,7 +33,7 @@ public class XNOr extends XOr {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int calculate(ArrayList<ObservableValue> inputs) throws NodeException {
|
||||
protected long calculate(ArrayList<ObservableValue> inputs) throws NodeException {
|
||||
return ~super.calculate(inputs);
|
||||
}
|
||||
}
|
||||
|
@ -33,8 +33,8 @@ public class XOr extends Function {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int calculate(ArrayList<ObservableValue> inputs) throws NodeException {
|
||||
int f = 0;
|
||||
protected long calculate(ArrayList<ObservableValue> inputs) throws NodeException {
|
||||
long f = 0;
|
||||
for (ObservableValue i : inputs) {
|
||||
f ^= i.getValue();
|
||||
}
|
||||
|
@ -33,4 +33,16 @@ public class AndTest extends TestCase {
|
||||
sc.check(1, 0, 0);
|
||||
sc.check(0, 1, 0);
|
||||
}
|
||||
|
||||
public void testAnd64() throws Exception {
|
||||
ObservableValue a = new ObservableValue("a", 64);
|
||||
ObservableValue b = new ObservableValue("b", 64);
|
||||
|
||||
Model model = new Model();
|
||||
FanIn out = model.add(new And(new ElementAttributes().setBits(64)));
|
||||
out.setInputs(ovs(a, b));
|
||||
|
||||
TestExecuter sc = new TestExecuter(model).setInputs(a, b).setOutputs(out.getOutputs());
|
||||
sc.check(0xff00000000000000L, 0x2200000000000000L, 0x2200000000000000L);
|
||||
}
|
||||
}
|
||||
|
@ -17,7 +17,7 @@ import static de.neemann.digital.core.ObservableValues.ovs;
|
||||
*/
|
||||
public class NAndTest extends TestCase {
|
||||
|
||||
public void testAnd() throws Exception {
|
||||
public void testNAnd() throws Exception {
|
||||
ObservableValue a = new ObservableValue("a", 1);
|
||||
ObservableValue b = new ObservableValue("b", 1);
|
||||
|
||||
@ -34,4 +34,17 @@ public class NAndTest extends TestCase {
|
||||
sc.check(1, 0, 1);
|
||||
sc.check(0, 1, 1);
|
||||
}
|
||||
|
||||
public void testNAnd64() throws Exception {
|
||||
ObservableValue a = new ObservableValue("a", 64);
|
||||
ObservableValue b = new ObservableValue("b", 64);
|
||||
|
||||
Model model = new Model();
|
||||
FanIn out = model.add(new NAnd(new ElementAttributes().setBits(64)));
|
||||
out.setInputs(ovs(a, b));
|
||||
|
||||
|
||||
TestExecuter sc = new TestExecuter(model).setInputs(a, b).setOutputs(out.getOutputs());
|
||||
sc.check(0xff00000000000000L, 0x2200000000000000L, 0xddffffffffffffffL);
|
||||
}
|
||||
}
|
||||
|
@ -34,4 +34,17 @@ public class NOrTest extends TestCase {
|
||||
sc.check(0, 1, 0);
|
||||
sc.check(0, 0, 1);
|
||||
}
|
||||
|
||||
public void testNOr64() throws Exception {
|
||||
ObservableValue a = new ObservableValue("a", 64);
|
||||
ObservableValue b = new ObservableValue("b", 64);
|
||||
|
||||
Model model = new Model();
|
||||
FanIn and = model.add(new NOr(new ElementAttributes().setBits(64)));
|
||||
and.setInputs(ovs(a, b));
|
||||
|
||||
TestExecuter sc = new TestExecuter(model).setInputs(a, b).setOutputs(and.getOutput());
|
||||
sc.check(0xff00000000000000L, 0x2200000000000000L, 0x00ffffffffffffffL);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -28,4 +28,15 @@ public class NotTest extends TestCase {
|
||||
sc.check(2, 1);
|
||||
sc.check(3, 0);
|
||||
}
|
||||
|
||||
public void testNot64() throws Exception {
|
||||
ObservableValue a = new ObservableValue("a", 64);
|
||||
|
||||
Model model = new Model();
|
||||
Not out = model.add(new Not(new ElementAttributes().setBits(64)));
|
||||
out.setInputs(a.asList());
|
||||
|
||||
TestExecuter sc = new TestExecuter(model).setInputs(a).setOutputs(out.getOutputs());
|
||||
sc.check(0xff00000000000000L, 0x00ffffffffffffffL);
|
||||
}
|
||||
}
|
||||
|
@ -34,4 +34,17 @@ public class OrTest extends TestCase {
|
||||
sc.check(0, 1, 1);
|
||||
sc.check(0, 0, 0);
|
||||
}
|
||||
|
||||
|
||||
public void testOr64() throws Exception {
|
||||
ObservableValue a = new ObservableValue("a", 64);
|
||||
ObservableValue b = new ObservableValue("b", 64);
|
||||
|
||||
Model model = new Model();
|
||||
FanIn and = model.add(new Or(new ElementAttributes().setBits(64)));
|
||||
and.setInputs(ovs(a, b));
|
||||
|
||||
TestExecuter sc = new TestExecuter(model).setInputs(a, b).setOutputs(and.getOutput());
|
||||
sc.check(0xff00000000000000L, 0x2200000000000000L, 0xff00000000000000L);
|
||||
}
|
||||
}
|
||||
|
@ -17,7 +17,7 @@ import static de.neemann.digital.core.ObservableValues.ovs;
|
||||
*/
|
||||
public class XNOrTest extends TestCase {
|
||||
|
||||
public void testXor() throws Exception {
|
||||
public void testXNor() throws Exception {
|
||||
ObservableValue a = new ObservableValue("a", 1);
|
||||
ObservableValue b = new ObservableValue("b", 1);
|
||||
|
||||
@ -32,4 +32,18 @@ public class XNOrTest extends TestCase {
|
||||
sc.check(0, 1, 0);
|
||||
sc.check(1, 1, 1);
|
||||
}
|
||||
|
||||
public void testXNor64() throws Exception {
|
||||
ObservableValue a = new ObservableValue("a", 64);
|
||||
ObservableValue b = new ObservableValue("b", 64);
|
||||
|
||||
|
||||
Model model = new Model();
|
||||
XOr out = model.add(new XNOr(new ElementAttributes().setBits(64)));
|
||||
out.setInputs(ovs(a, b));
|
||||
|
||||
TestExecuter sc = new TestExecuter(model).setInputs(a, b).setOutputs(out.getOutputs());
|
||||
sc.check(0x7e00000000000000L, 0x2200000000000000L, ~0x5c00000000000000L);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -32,4 +32,17 @@ public class XOrTest extends TestCase {
|
||||
sc.check(0, 1, 1);
|
||||
sc.check(1, 1, 0);
|
||||
}
|
||||
|
||||
public void testXor64() throws Exception {
|
||||
ObservableValue a = new ObservableValue("a", 64);
|
||||
ObservableValue b = new ObservableValue("b", 64);
|
||||
|
||||
|
||||
Model model = new Model();
|
||||
XOr out = model.add(new XOr(new ElementAttributes().setBits(64)));
|
||||
out.setInputs(ovs(a, b));
|
||||
|
||||
TestExecuter sc = new TestExecuter(model).setInputs(a, b).setOutputs(out.getOutputs());
|
||||
sc.check(0x7e00000000000000L, 0x2200000000000000L, 0x5c00000000000000L);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user