Merge branch 'master' into 1.17
This commit is contained in:
commit
e89f4444dc
15 files changed
+165
-23
No files matched your search
@@ -11,7 +11,7 @@ import java.util.Locale;
|
||||
|
||||
public abstract class LazyListValue extends AbstractListValue implements Iterator<Value>
|
||||
{
|
||||
public static LazyListValue range(long from, long to, long step)
|
||||
public static LazyListValue rangeDouble(double from, double to, double step)
|
||||
{
|
||||
return new LazyListValue()
|
||||
{
|
||||
@@ -23,10 +23,10 @@ public abstract class LazyListValue extends AbstractListValue implements Iterato
|
||||
this.limit = to;
|
||||
this.stepp = step;
|
||||
}
|
||||
private long start;
|
||||
private long current;
|
||||
private long limit;
|
||||
private long stepp;
|
||||
private final double start;
|
||||
private double current;
|
||||
private final double limit;
|
||||
private final double stepp;
|
||||
@Override
|
||||
public Value next()
|
||||
{
|
||||
@@ -50,7 +50,50 @@ public abstract class LazyListValue extends AbstractListValue implements Iterato
|
||||
@Override
|
||||
public String getString()
|
||||
{
|
||||
return String.format(Locale.ROOT, "[%d, %d, ..., %d)",start, start+stepp, limit);
|
||||
return String.format(Locale.ROOT, "[%s, %s, ..., %s)",NumericValue.of(start).getString(), NumericValue.of(start+stepp).getString(), NumericValue.of( limit).getString());
|
||||
}
|
||||
};
|
||||
}
|
||||
public static LazyListValue rangeLong(long from, long to, long step)
|
||||
{
|
||||
return new LazyListValue()
|
||||
{
|
||||
{
|
||||
if (step == 0)
|
||||
throw new InternalExpressionException("Range will never end with a zero step");
|
||||
this.start = from;
|
||||
this.current = this.start;
|
||||
this.limit = to;
|
||||
this.stepp = step;
|
||||
}
|
||||
private final long start;
|
||||
private long current;
|
||||
private final long limit;
|
||||
private final long stepp;
|
||||
@Override
|
||||
public Value next()
|
||||
{
|
||||
Value val = new NumericValue(current);
|
||||
current += stepp;
|
||||
return val;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reset()
|
||||
{
|
||||
current = start;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasNext()
|
||||
{
|
||||
return stepp > 0?(current < limit):(current > limit);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getString()
|
||||
{
|
||||
return String.format(Locale.ROOT, "[%s, %s, ..., %s)",NumericValue.of(start).getString(), NumericValue.of(start+stepp).getString(), NumericValue.of( limit).getString());
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -15,6 +15,7 @@ import java.math.RoundingMode;
|
||||
import java.util.Locale;
|
||||
|
||||
import static java.lang.Math.abs;
|
||||
import static java.lang.Math.signum;
|
||||
|
||||
public class NumericValue extends Value
|
||||
{
|
||||
@@ -57,6 +58,7 @@ public class NumericValue extends Value
|
||||
{
|
||||
if (value.isInfinite()) return "INFINITY";
|
||||
if (value.isNaN()) return "NaN";
|
||||
if (abs(value) < epsilon) return (signum(value) < 0)?"-0":"0"; //zero rounding fails with big decimals
|
||||
// dobules have 16 point precision, 12 is plenty to display
|
||||
return BigDecimal.valueOf(value).round(displayRounding).stripTrailingZeros().toPlainString();
|
||||
}
|
||||
@@ -306,4 +308,9 @@ public class NumericValue extends Value
|
||||
if (longValue != null) return new NumericValue(-longValue);
|
||||
return new NumericValue(-value);
|
||||
}
|
||||
|
||||
public boolean isInteger()
|
||||
{
|
||||
return longValue!= null || getDouble() == (double)getLong();
|
||||
}
|
||||
}
|
||||
@@ -13,10 +13,12 @@ import java.util.regex.PatternSyntaxException;
|
||||
|
||||
public abstract class Value implements Comparable<Value>, Cloneable
|
||||
{
|
||||
public static Value FALSE = new NumericValue(0);
|
||||
public static Value TRUE = new NumericValue(1);
|
||||
public static Value ZERO = FALSE;
|
||||
public static Value NULL = new NullValue();
|
||||
public static NumericValue FALSE = new NumericValue(0);
|
||||
public static NumericValue TRUE = new NumericValue(1);
|
||||
public static NumericValue ZERO = FALSE;
|
||||
public static NumericValue ONE = TRUE;
|
||||
|
||||
public static NullValue NULL = new NullValue();
|
||||
|
||||
public String boundVariable;
|
||||
|
||||
|
||||
Reference in new issue
Block a user