diff options
author | Shevek <[email protected]> | 2015-06-16 10:34:15 -0700 |
---|---|---|
committer | Shevek <[email protected]> | 2015-06-16 10:34:15 -0700 |
commit | 7b5040feb49da30c3a808265007ad3308ae511ee (patch) | |
tree | 0e5adc43ca76b9d4cb23d23add534341da4e2c31 /src/main | |
parent | c5f21d5d4316b338590307801b49e72e0b2806a6 (diff) |
NumericValue: Overflow a bit later on overlong integers.
Diffstat (limited to 'src/main')
-rw-r--r-- | src/main/java/org/anarres/cpp/NumericValue.java | 7 |
1 files changed, 7 insertions, 0 deletions
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; |