diff --git a/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/meta/EqualsNode.java b/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/meta/EqualsNode.java index bd18ad4bcd6..d7a40b1304a 100644 --- a/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/meta/EqualsNode.java +++ b/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/meta/EqualsNode.java @@ -141,7 +141,7 @@ public abstract class EqualsNode extends Node { @Specialization @TruffleBoundary boolean equalsDoubleBigInt(double self, EnsoBigInteger other) { - return self == other.asDouble(); + return self == other.getValue().doubleValue(); } @Specialization(guards="interop.fitsInDouble(other)") @@ -170,7 +170,7 @@ public abstract class EqualsNode extends Node { @Specialization @TruffleBoundary boolean equalsBitIntDouble(EnsoBigInteger self, double other) { - return self.asDouble() == other; + return self.getValue().doubleValue() == other; } @Specialization diff --git a/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/number/integer/AddNode.java b/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/number/integer/AddNode.java index 739576d4ccd..216e46d1706 100644 --- a/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/number/integer/AddNode.java +++ b/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/number/integer/AddNode.java @@ -52,8 +52,9 @@ public abstract class AddNode extends IntegerNode { } @Specialization + @TruffleBoundary double doBigIntDouble(EnsoBigInteger self, double that) { - return self.asDouble() + that; + return self.getValue().doubleValue() + that; } @Specialization(guards = "isForeignNumber(iop, that)") diff --git a/engine/runtime/src/main/java/org/enso/interpreter/runtime/number/EnsoBigInteger.java b/engine/runtime/src/main/java/org/enso/interpreter/runtime/number/EnsoBigInteger.java index 931390e592c..3c666c8dd31 100644 --- a/engine/runtime/src/main/java/org/enso/interpreter/runtime/number/EnsoBigInteger.java +++ b/engine/runtime/src/main/java/org/enso/interpreter/runtime/number/EnsoBigInteger.java @@ -89,39 +89,33 @@ public final class EnsoBigInteger implements EnsoObject { } @ExportMessage - @CompilerDirectives.TruffleBoundary final byte asByte() throws UnsupportedMessageException { - return value.byteValue(); + throw UnsupportedMessageException.create(); } @ExportMessage - @CompilerDirectives.TruffleBoundary final short asShort() throws UnsupportedMessageException { - return value.shortValue(); + throw UnsupportedMessageException.create(); } @ExportMessage - @CompilerDirectives.TruffleBoundary final int asInt() throws UnsupportedMessageException { - return value.intValue(); + throw UnsupportedMessageException.create(); } @ExportMessage - @CompilerDirectives.TruffleBoundary final long asLong() throws UnsupportedMessageException { - return value.longValue(); + throw UnsupportedMessageException.create(); } @ExportMessage - @CompilerDirectives.TruffleBoundary - final float asFloat() { - return value.floatValue(); + final float asFloat() throws UnsupportedMessageException { + throw UnsupportedMessageException.create(); } @ExportMessage - @CompilerDirectives.TruffleBoundary - public final double asDouble() { - return value.doubleValue(); + public final double asDouble() throws UnsupportedMessageException { + throw UnsupportedMessageException.create(); } @ExportMessage diff --git a/test/Tests/src/Data/Numbers_Spec.enso b/test/Tests/src/Data/Numbers_Spec.enso index 47934929e8f..e8ab6d7bc08 100644 --- a/test/Tests/src/Data/Numbers_Spec.enso +++ b/test/Tests/src/Data/Numbers_Spec.enso @@ -12,6 +12,7 @@ import Standard.Test.Extensions import project.Data.Round_Spec polyglot java import java.math.BigInteger +polyglot java import java.math.BigDecimal Integer.is_even self = self % 2 == 0 @@ -572,6 +573,14 @@ spec = v -> Test.fail "Expecting Integer, but got: "+(Meta.type_of v).to_text sum.div two_hundred.length . should_equal expected_value + Test.specify name+" BigInteger to BigDecimal test" <| + h = 2^70 + bd1 = BigDecimal.new h 0 + bd2 = BigDecimal.new h + bd1.to_text . should_equal bd2.to_text + bd1 . should_equal bd2 + bd1.toBigIntegerExact . should_equal h + to_java_bigint n = BigInteger.new n.to_text java_bigint_mul a b = big_a = to_java_bigint a