Skip to content

Commit

Permalink
(fix) long type promption error, #162
Browse files Browse the repository at this point in the history
  • Loading branch information
killme2008 committed Sep 10, 2019
1 parent e48caf5 commit 90bdb0c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ public Token<?> scan(final boolean analyse) {
boolean isBigDecimal = false;
boolean scientificNotation = false;
boolean negExp = false;
boolean isOverflow = false;
do {
sb.append(this.peek);
if (this.peek == '.') {
Expand Down Expand Up @@ -239,6 +240,11 @@ public Token<?> scan(final boolean analyse) {
}

}

if (lval < 0) {
isOverflow = true;
}

} while (Character.isDigit(this.peek) || this.peek == '.' || this.peek == 'E'
|| this.peek == 'e' || this.peek == 'M' || this.peek == 'N');
Number value;
Expand All @@ -262,7 +268,7 @@ public Token<?> scan(final boolean analyse) {
} else {
// if the long value is out of range,then it must be negative, so
// we make it as a big integer.
if (lval < 0) {
if (lval < 0 || isOverflow) {
value = new BigInteger(sb.toString());
} else {
value = lval;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
Expand Down Expand Up @@ -51,6 +52,18 @@ public void testIssue77() {
AviatorEvaluator.setOption(Options.ALWAYS_PARSE_FLOATING_POINT_NUMBER_INTO_DECIMAL, false);
}


@Test
public void testIssue162() {
Object val = AviatorEvaluator.execute("2017122615550747128008704");
assertTrue(val instanceof BigInteger);
assertEquals(new BigInteger("2017122615550747128008704"), val);

val = AviatorEvaluator.execute("-2017122615550747128008704");
assertTrue(val instanceof BigInteger);
assertEquals(new BigInteger("-2017122615550747128008704"), val);
}

@Test
public void testIssue87() {
AviatorEvaluator.setOption(Options.ALWAYS_PARSE_FLOATING_POINT_NUMBER_INTO_DECIMAL, true);
Expand Down

0 comments on commit 90bdb0c

Please sign in to comment.