Skip to content

Commit

Permalink
All numbers should be either Integer or Float
Browse files Browse the repository at this point in the history
  • Loading branch information
JaroslavTulach committed Jan 10, 2024
1 parent 28fc63e commit 7925be6
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,8 @@ Type doPolyglotNumber(
return builtins.number().getInteger();
} else if (interop.fitsInDouble(value)) {
return builtins.number().getFloat();
} else if (interop.fitsInBigInteger(value)) {
return builtins.number().getInteger();
} else {
return EnsoContext.get(this).getBuiltins().number().getNumber();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,29 @@ public void typesOfConstructors() throws Exception {
}
}

@Test
public void numbersAreEitherIntegerOrFloat() throws Exception {
var g = generator();
var sn =
ctx.eval(
"enso",
"""
from Standard.Base import Meta
sn v = Meta.get_simple_type_name v
""")
.invokeMember(MethodNames.Module.EVAL_EXPRESSION, "sn");
for (var v : g.numbers()) {
var simpleName = sn.execute(v).asString();
var ok =
switch (simpleName) {
case "Integer", "Float" -> true;
default -> false;
};
assertTrue("Unexpected simple name for number: " + v + " is " + simpleName, ok);
}
}

@Test
public void compareQualifiedAndSimpleTypeName() throws Exception {
var g = generator();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import static org.junit.Assert.assertTrue;

import java.lang.reflect.Method;
import java.math.BigInteger;
import java.time.Duration;
import java.time.LocalDate;
import java.time.LocalDateTime;
Expand Down Expand Up @@ -394,6 +395,9 @@ public List<Value> numbers() {
collect.add(ctx.asValue((float) Math.PI));
collect.add(ctx.asValue((double) Math.E));
collect.add(ctx.asValue(Double.NaN));
collect.add(ctx.asValue(BigInteger.valueOf(10).pow(40)));
collect.add(ctx.asValue(BigInteger.valueOf(10).pow(40).doubleValue()));
collect.add(ctx.asValue(BigInteger.valueOf(10).pow(40).doubleValue() + 1.0));
}

for (var v : collect) {
Expand Down

0 comments on commit 7925be6

Please sign in to comment.