aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorShevek <[email protected]>2015-06-15 16:42:23 -0700
committerShevek <[email protected]>2015-06-15 16:42:23 -0700
commit391fbe5ac9a6b5cdb64965a90cbeecb680dfe2be (patch)
treeaaff37b45414d97c56a8498f51ea4536313249a0
parent0ff16b1540429b3fda0649a4d9ee7509ec5007eb (diff)
NumericValue: Deal slightly more elegantly with unadorned longs.
-rw-r--r--src/main/java/org/anarres/cpp/NumericValue.java14
1 files changed, 9 insertions, 5 deletions
diff --git a/src/main/java/org/anarres/cpp/NumericValue.java b/src/main/java/org/anarres/cpp/NumericValue.java
index 7feb758..65544e9 100644
--- a/src/main/java/org/anarres/cpp/NumericValue.java
+++ b/src/main/java/org/anarres/cpp/NumericValue.java
@@ -41,7 +41,7 @@ public class NumericValue extends Number {
private String exponent;
private int flags;
- public NumericValue(int base, String integer) {
+ public NumericValue(@Nonnegative int base, @Nonnull String integer) {
this.base = base;
this.integer = integer;
}
@@ -61,7 +61,7 @@ public class NumericValue extends Number {
return fraction;
}
- /* pp */ void setFractionalPart(String fraction) {
+ /* pp */ void setFractionalPart(@Nonnull String fraction) {
this.fraction = fraction;
}
@@ -75,7 +75,7 @@ public class NumericValue extends Number {
return exponent;
}
- /* pp */ void setExponent(int expbase, String exponent) {
+ /* pp */ void setExponent(@Nonnegative int expbase, @Nonnull String exponent) {
this.expbase = expbase;
this.exponent = exponent;
}
@@ -125,8 +125,12 @@ public class NumericValue extends Number {
return doubleValue(); // .1 is a double in Java.
else if (getExponent() != null)
return doubleValue();
- else
- return intValue();
+ else {
+ long value = longValue();
+ if (value <= Integer.MAX_VALUE && value >= Integer.MIN_VALUE)
+ return (int) value;
+ return value;
+ }
}
private int exponentValue() {