From 7b5040feb49da30c3a808265007ad3308ae511ee Mon Sep 17 00:00:00 2001 From: Shevek Date: Tue, 16 Jun 2015 10:34:15 -0700 Subject: NumericValue: Overflow a bit later on overlong integers. --- src/main/java/org/anarres/cpp/NumericValue.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/main/java/org/anarres/cpp/NumericValue.java b/src/main/java/org/anarres/cpp/NumericValue.java index 496b6f1..b51ca59 100644 --- a/src/main/java/org/anarres/cpp/NumericValue.java +++ b/src/main/java/org/anarres/cpp/NumericValue.java @@ -110,6 +110,10 @@ public class NumericValue extends Number { return new BigDecimal(unscaled, scale); } + // We could construct a heuristic for when an 'int' is large enough. + // private static final int S_MAXLEN_LONG = String.valueOf(Long.MAX_VALUE).length(); + // private static final int S_MAXLEN_INT = String.valueOf(Integer.MAX_VALUE).length(); + @Nonnull public Number toJavaLangNumber() { int flags = getFlags(); @@ -126,6 +130,9 @@ public class NumericValue extends Number { else if (getExponent() != null) return doubleValue(); else { + // This is an attempt to avoid overflowing on over-long integers. + // However, now we just overflow on over-long longs. + // We should really use BigInteger. long value = longValue(); if (value <= Integer.MAX_VALUE && value >= Integer.MIN_VALUE) return (int) value; -- cgit v1.2.3