Open
Description
@ltratt found the following issue:
(1.1 + (4611686018427387904 * 2)) println.
barfs with the following for SOM-java:
Exception in thread "main" java.lang.ClassCastException: Cannot coerce to Double!
at som.vmobjects.SDouble.coerceToDouble(SDouble.java:55)
at som.vmobjects.SDouble.primAdd(SDouble.java:74)
at som.primitives.DoublePrimitives$4.invoke(DoublePrimitives.java:73)
at som.interpreter.Interpreter.send(Interpreter.java:386)
at som.interpreter.Interpreter.doSend(Interpreter.java:216)
at som.interpreter.Interpreter.start(Interpreter.java:302)
at som.vm.Universe.interpretMethod(Universe.java:328)
at som.vm.Universe.initialize(Universe.java:299)
at som.vm.Universe.interpret(Universe.java:78)
at som.vm.Universe.main(Universe.java:64)
Given that:
private double coerceToDouble(final SNumber o, final Universe universe) {
if (o instanceof SDouble) {
return ((SDouble) o).embeddedDouble;
}
if (o instanceof SInteger) {
return ((SInteger) o).getEmbeddedInteger();
}
throw new ClassCastException("Cannot coerce to Double!");
}
I would assume this is simply laziness of the implementers and the case for a BigInteger has just not been implemented.
It should be noted that I unified the perviously distinct Smalltalk class Integer and BitInteger.
So, I think there is no reason to not implement it. Double conversion is lossy and as such, the result should be made to fit, I’d think.
Todo
- add tests
- add to spec