|
|
@ -38,7 +38,7 @@ public abstract class Num implements NumBound { |
|
|
|
@FactoryMethod |
|
|
|
@FactoryMethod |
|
|
|
public static NumVar makeVar(Num copied) |
|
|
|
public static NumVar makeVar(Num copied) |
|
|
|
{ |
|
|
|
{ |
|
|
|
return new NumVar(eval(copied)); |
|
|
|
return new NumVar(copied.value()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private Num p_ceil; |
|
|
|
private Num p_ceil; |
|
|
@ -59,33 +59,20 @@ public abstract class Num implements NumBound { |
|
|
|
private Num p_abs; |
|
|
|
private Num p_abs; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
public NumConst freeze() |
|
|
|
* Convert to double, turning null into zero. |
|
|
|
|
|
|
|
* |
|
|
|
|
|
|
|
* @param a num |
|
|
|
|
|
|
|
* @return double |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
protected static double eval(final NumBound a) |
|
|
|
|
|
|
|
{ |
|
|
|
{ |
|
|
|
return toNum(a).value(); |
|
|
|
return new NumConst(value()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Convert {@link NumBound} to {@link Num}, turning null to Num.ZERO. |
|
|
|
* Get a snapshot of the current state, to be used for processing. |
|
|
|
* |
|
|
|
* |
|
|
|
* @param a numeric bound |
|
|
|
* @return digest |
|
|
|
* @return num |
|
|
|
|
|
|
|
*/ |
|
|
|
*/ |
|
|
|
protected static Num toNum(final NumBound a) |
|
|
|
public NumDigest digest() |
|
|
|
{ |
|
|
|
{ |
|
|
|
return (a == null) ? Num.ZERO : (a.getNum() == null ? Num.ZERO : a.getNum()); |
|
|
|
return new NumDigest(this); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public NumConst freeze() |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
return new NumConst(value()); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -102,27 +89,25 @@ public abstract class Num implements NumBound { |
|
|
|
public abstract double value(); |
|
|
|
public abstract double value(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public Num abs() |
|
|
|
public Num add(final double addend) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (p_abs == null) p_abs = new Num() { |
|
|
|
return new Num() { |
|
|
|
|
|
|
|
|
|
|
|
final Num t = Num.this; |
|
|
|
private final Num t = Num.this; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public double value() |
|
|
|
public double value() |
|
|
|
{ |
|
|
|
{ |
|
|
|
return Math.abs(t.value()); |
|
|
|
return t.value() + addend; |
|
|
|
} |
|
|
|
} |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
return p_abs; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public Num acos() |
|
|
|
public Num add(final Num addend) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (p_acos == null) p_acos = new Num() { |
|
|
|
return new Num() { |
|
|
|
|
|
|
|
|
|
|
|
final Num t = Num.this; |
|
|
|
final Num t = Num.this; |
|
|
|
|
|
|
|
|
|
|
@ -130,31 +115,37 @@ public abstract class Num implements NumBound { |
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public double value() |
|
|
|
public double value() |
|
|
|
{ |
|
|
|
{ |
|
|
|
return Math.acos(t.value()); |
|
|
|
return t.value() + addend.value(); |
|
|
|
} |
|
|
|
} |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return p_acos; |
|
|
|
|
|
|
|
|
|
|
|
public Num sub(final double subtrahend) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
return add(-subtrahend); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public Num add(final double addend) |
|
|
|
public Num abs() |
|
|
|
{ |
|
|
|
{ |
|
|
|
return new Num() { |
|
|
|
if (p_abs == null) p_abs = new Num() { |
|
|
|
|
|
|
|
|
|
|
|
private final Num t = Num.this; |
|
|
|
final Num t = Num.this; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public double value() |
|
|
|
public double value() |
|
|
|
{ |
|
|
|
{ |
|
|
|
return t.value() + addend; |
|
|
|
return Math.abs(t.value()); |
|
|
|
} |
|
|
|
} |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return p_abs; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public Num add(final Num addend) |
|
|
|
public Num sub(final Num subtrahend) |
|
|
|
{ |
|
|
|
{ |
|
|
|
return new Num() { |
|
|
|
return new Num() { |
|
|
|
|
|
|
|
|
|
|
@ -164,15 +155,22 @@ public abstract class Num implements NumBound { |
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public double value() |
|
|
|
public double value() |
|
|
|
{ |
|
|
|
{ |
|
|
|
return t.value() + eval(addend); |
|
|
|
return t.value() - subtrahend.value(); |
|
|
|
} |
|
|
|
} |
|
|
|
}; |
|
|
|
}; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public Num asin() |
|
|
|
public Num div(final double factor) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (p_asin == null) p_asin = new Num() { |
|
|
|
return mul(1 / factor); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public Num div(final Num factor) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return new Num() { |
|
|
|
|
|
|
|
|
|
|
|
final Num t = Num.this; |
|
|
|
final Num t = Num.this; |
|
|
|
|
|
|
|
|
|
|
@ -180,34 +178,31 @@ public abstract class Num implements NumBound { |
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public double value() |
|
|
|
public double value() |
|
|
|
{ |
|
|
|
{ |
|
|
|
return Math.asin(t.value()); |
|
|
|
return t.value() / factor.value(); |
|
|
|
} |
|
|
|
} |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
return p_asin; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public Num atan() |
|
|
|
public Num mul(final double factor) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (p_atan == null) p_atan = new Num() { |
|
|
|
return new Num() { |
|
|
|
|
|
|
|
|
|
|
|
final Num t = Num.this; |
|
|
|
private final Num t = Num.this; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public double value() |
|
|
|
public double value() |
|
|
|
{ |
|
|
|
{ |
|
|
|
return Math.atan(t.value()); |
|
|
|
return t.value() * factor; |
|
|
|
} |
|
|
|
} |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
return p_atan; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public Num average(final double other) |
|
|
|
public Num mul(final Num factor) |
|
|
|
{ |
|
|
|
{ |
|
|
|
|
|
|
|
|
|
|
|
return new Num() { |
|
|
|
return new Num() { |
|
|
|
|
|
|
|
|
|
|
|
final Num t = Num.this; |
|
|
|
final Num t = Num.this; |
|
|
@ -216,13 +211,13 @@ public abstract class Num implements NumBound { |
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public double value() |
|
|
|
public double value() |
|
|
|
{ |
|
|
|
{ |
|
|
|
return (t.value() + other) / 2; |
|
|
|
return t.value() * factor.value(); |
|
|
|
} |
|
|
|
} |
|
|
|
}; |
|
|
|
}; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public Num average(final Num other) |
|
|
|
public Num average(final double other) |
|
|
|
{ |
|
|
|
{ |
|
|
|
return new Num() { |
|
|
|
return new Num() { |
|
|
|
|
|
|
|
|
|
|
@ -232,15 +227,15 @@ public abstract class Num implements NumBound { |
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public double value() |
|
|
|
public double value() |
|
|
|
{ |
|
|
|
{ |
|
|
|
return (t.value() + eval(other)) / 2; |
|
|
|
return (t.value() + other) / 2; |
|
|
|
} |
|
|
|
} |
|
|
|
}; |
|
|
|
}; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public Num cbrt() |
|
|
|
public Num average(final Num other) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (p_cbrt == null) p_cbrt = new Num() { |
|
|
|
return new Num() { |
|
|
|
|
|
|
|
|
|
|
|
final Num t = Num.this; |
|
|
|
final Num t = Num.this; |
|
|
|
|
|
|
|
|
|
|
@ -248,17 +243,21 @@ public abstract class Num implements NumBound { |
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public double value() |
|
|
|
public double value() |
|
|
|
{ |
|
|
|
{ |
|
|
|
return Math.cbrt(t.value()); |
|
|
|
return (t.value() + other.value()) / 2; |
|
|
|
} |
|
|
|
} |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return p_cbrt; |
|
|
|
|
|
|
|
|
|
|
|
public Num perc(final double percent) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
return mul(percent / 100); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public Num ceil() |
|
|
|
public Num perc(final Num percent) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (p_ceil == null) p_ceil = new Num() { |
|
|
|
return new Num() { |
|
|
|
|
|
|
|
|
|
|
|
final Num t = Num.this; |
|
|
|
final Num t = Num.this; |
|
|
|
|
|
|
|
|
|
|
@ -266,11 +265,9 @@ public abstract class Num implements NumBound { |
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public double value() |
|
|
|
public double value() |
|
|
|
{ |
|
|
|
{ |
|
|
|
return Math.round(t.value()); |
|
|
|
return t.value() * (percent.value() / 100); |
|
|
|
} |
|
|
|
} |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
return p_ceil; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -292,9 +289,9 @@ public abstract class Num implements NumBound { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public Num cube() |
|
|
|
public Num acos() |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (p_cube == null) p_cube = new Num() { |
|
|
|
if (p_acos == null) p_acos = new Num() { |
|
|
|
|
|
|
|
|
|
|
|
final Num t = Num.this; |
|
|
|
final Num t = Num.this; |
|
|
|
|
|
|
|
|
|
|
@ -302,25 +299,17 @@ public abstract class Num implements NumBound { |
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public double value() |
|
|
|
public double value() |
|
|
|
{ |
|
|
|
{ |
|
|
|
final double v = t.value(); |
|
|
|
return Math.acos(t.value()); |
|
|
|
return v * v * v; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
return p_cube; |
|
|
|
return p_acos; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public Num div(final double factor) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
return mul(1 / factor); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public Num div(final Num factor) |
|
|
|
public Num sin() |
|
|
|
{ |
|
|
|
{ |
|
|
|
|
|
|
|
if (p_sin == null) p_sin = new Num() { |
|
|
|
return new Num() { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
final Num t = Num.this; |
|
|
|
final Num t = Num.this; |
|
|
|
|
|
|
|
|
|
|
@ -328,27 +317,17 @@ public abstract class Num implements NumBound { |
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public double value() |
|
|
|
public double value() |
|
|
|
{ |
|
|
|
{ |
|
|
|
return t.value() / eval(factor); |
|
|
|
return Math.sin(t.value()); |
|
|
|
} |
|
|
|
} |
|
|
|
}; |
|
|
|
}; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return p_sin; |
|
|
|
public boolean eq(double other) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
return value() == other; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public boolean eq(final Num a) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
return eq(eval(a)); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public Num floor() |
|
|
|
public Num asin() |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (p_floor == null) p_floor = new Num() { |
|
|
|
if (p_asin == null) p_asin = new Num() { |
|
|
|
|
|
|
|
|
|
|
|
final Num t = Num.this; |
|
|
|
final Num t = Num.this; |
|
|
|
|
|
|
|
|
|
|
@ -356,89 +335,17 @@ public abstract class Num implements NumBound { |
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public double value() |
|
|
|
public double value() |
|
|
|
{ |
|
|
|
{ |
|
|
|
return Math.floor(t.value()); |
|
|
|
return Math.asin(t.value()); |
|
|
|
} |
|
|
|
} |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
return p_floor; |
|
|
|
return p_asin; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public boolean gt(double other) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
return Math.signum(value() - other) >= 0; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public boolean gt(final Num other) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
return gt(eval(other)); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public boolean gte(double other) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
return Math.signum(value() - other) >= 0; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public boolean gte(final Num other) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
return gte(eval(other)); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public Num half() |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
return mul(0.5); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public boolean isNegative() |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
return value() < 0; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public boolean isPositive() |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
return value() > 0; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public boolean isZero() |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
return value() == 0; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public boolean lt(double other) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
return !gte(other); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public boolean lt(final Num other) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
return !gte(other); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public boolean lte(double other) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
return !gt(other); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public boolean lte(final Num other) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
return !gt(other); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public Num max(final double other) |
|
|
|
public Num tan() |
|
|
|
{ |
|
|
|
{ |
|
|
|
return new Num() { |
|
|
|
if (p_tan == null) p_tan = new Num() { |
|
|
|
|
|
|
|
|
|
|
|
final Num t = Num.this; |
|
|
|
final Num t = Num.this; |
|
|
|
|
|
|
|
|
|
|
@ -446,15 +353,17 @@ public abstract class Num implements NumBound { |
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public double value() |
|
|
|
public double value() |
|
|
|
{ |
|
|
|
{ |
|
|
|
return Math.max(t.value(), other); |
|
|
|
return Math.tan(t.value()); |
|
|
|
} |
|
|
|
} |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return p_tan; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public Num max(final Num other) |
|
|
|
public Num atan() |
|
|
|
{ |
|
|
|
{ |
|
|
|
return new Num() { |
|
|
|
if (p_atan == null) p_atan = new Num() { |
|
|
|
|
|
|
|
|
|
|
|
final Num t = Num.this; |
|
|
|
final Num t = Num.this; |
|
|
|
|
|
|
|
|
|
|
@ -462,15 +371,17 @@ public abstract class Num implements NumBound { |
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public double value() |
|
|
|
public double value() |
|
|
|
{ |
|
|
|
{ |
|
|
|
return Math.max(t.value(), eval(other)); |
|
|
|
return Math.atan(t.value()); |
|
|
|
} |
|
|
|
} |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return p_atan; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public Num min(final double other) |
|
|
|
public Num cbrt() |
|
|
|
{ |
|
|
|
{ |
|
|
|
return new Num() { |
|
|
|
if (p_cbrt == null) p_cbrt = new Num() { |
|
|
|
|
|
|
|
|
|
|
|
final Num t = Num.this; |
|
|
|
final Num t = Num.this; |
|
|
|
|
|
|
|
|
|
|
@ -478,15 +389,17 @@ public abstract class Num implements NumBound { |
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public double value() |
|
|
|
public double value() |
|
|
|
{ |
|
|
|
{ |
|
|
|
return Math.min(t.value(), other); |
|
|
|
return Math.cbrt(t.value()); |
|
|
|
} |
|
|
|
} |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return p_cbrt; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public Num min(final Num other) |
|
|
|
public Num sqrt() |
|
|
|
{ |
|
|
|
{ |
|
|
|
return new Num() { |
|
|
|
if (p_sqrt == null) p_sqrt = new Num() { |
|
|
|
|
|
|
|
|
|
|
|
final Num t = Num.this; |
|
|
|
final Num t = Num.this; |
|
|
|
|
|
|
|
|
|
|
@ -494,32 +407,35 @@ public abstract class Num implements NumBound { |
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public double value() |
|
|
|
public double value() |
|
|
|
{ |
|
|
|
{ |
|
|
|
return Math.min(t.value(), eval(other)); |
|
|
|
return Math.sqrt(t.value()); |
|
|
|
} |
|
|
|
} |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return p_sqrt; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public Num mul(final double factor) |
|
|
|
public Num neg() |
|
|
|
{ |
|
|
|
{ |
|
|
|
return new Num() { |
|
|
|
if (p_neg == null) p_neg = new Num() { |
|
|
|
|
|
|
|
|
|
|
|
private final Num t = Num.this; |
|
|
|
final Num t = Num.this; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public double value() |
|
|
|
public double value() |
|
|
|
{ |
|
|
|
{ |
|
|
|
return t.value() * factor; |
|
|
|
return -1 * t.value(); |
|
|
|
} |
|
|
|
} |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return p_neg; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public Num mul(final Num factor) |
|
|
|
public Num round() |
|
|
|
{ |
|
|
|
{ |
|
|
|
|
|
|
|
if (p_round == null) p_round = new Num() { |
|
|
|
return new Num() { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
final Num t = Num.this; |
|
|
|
final Num t = Num.this; |
|
|
|
|
|
|
|
|
|
|
@ -527,15 +443,17 @@ public abstract class Num implements NumBound { |
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public double value() |
|
|
|
public double value() |
|
|
|
{ |
|
|
|
{ |
|
|
|
return t.value() * eval(factor); |
|
|
|
return Math.round(t.value()); |
|
|
|
} |
|
|
|
} |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return p_round; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public Num neg() |
|
|
|
public Num floor() |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (p_neg == null) p_neg = new Num() { |
|
|
|
if (p_floor == null) p_floor = new Num() { |
|
|
|
|
|
|
|
|
|
|
|
final Num t = Num.this; |
|
|
|
final Num t = Num.this; |
|
|
|
|
|
|
|
|
|
|
@ -543,23 +461,17 @@ public abstract class Num implements NumBound { |
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public double value() |
|
|
|
public double value() |
|
|
|
{ |
|
|
|
{ |
|
|
|
return -1 * t.value(); |
|
|
|
return Math.floor(t.value()); |
|
|
|
} |
|
|
|
} |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
return p_neg; |
|
|
|
return p_floor; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public Num perc(final double percent) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
return mul(percent / 100); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public Num perc(final Num percent) |
|
|
|
public Num ceil() |
|
|
|
{ |
|
|
|
{ |
|
|
|
return new Num() { |
|
|
|
if (p_ceil == null) p_ceil = new Num() { |
|
|
|
|
|
|
|
|
|
|
|
final Num t = Num.this; |
|
|
|
final Num t = Num.this; |
|
|
|
|
|
|
|
|
|
|
@ -567,9 +479,11 @@ public abstract class Num implements NumBound { |
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public double value() |
|
|
|
public double value() |
|
|
|
{ |
|
|
|
{ |
|
|
|
return t.value() * (eval(percent) / 100); |
|
|
|
return Math.round(t.value()); |
|
|
|
} |
|
|
|
} |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return p_ceil; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -599,15 +513,15 @@ public abstract class Num implements NumBound { |
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public double value() |
|
|
|
public double value() |
|
|
|
{ |
|
|
|
{ |
|
|
|
return Math.pow(t.value(), eval(power)); |
|
|
|
return Math.pow(t.value(), power.value()); |
|
|
|
} |
|
|
|
} |
|
|
|
}; |
|
|
|
}; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public Num round() |
|
|
|
public Num cube() |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (p_round == null) p_round = new Num() { |
|
|
|
if (p_cube == null) p_cube = new Num() { |
|
|
|
|
|
|
|
|
|
|
|
final Num t = Num.this; |
|
|
|
final Num t = Num.this; |
|
|
|
|
|
|
|
|
|
|
@ -615,17 +529,18 @@ public abstract class Num implements NumBound { |
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public double value() |
|
|
|
public double value() |
|
|
|
{ |
|
|
|
{ |
|
|
|
return Math.round(t.value()); |
|
|
|
final double v = t.value(); |
|
|
|
|
|
|
|
return v * v * v; |
|
|
|
} |
|
|
|
} |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
return p_round; |
|
|
|
return p_cube; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public Num signum() |
|
|
|
public Num square() |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (p_sgn == null) p_sgn = new Num() { |
|
|
|
if (p_square == null) p_square = new Num() { |
|
|
|
|
|
|
|
|
|
|
|
final Num t = Num.this; |
|
|
|
final Num t = Num.this; |
|
|
|
|
|
|
|
|
|
|
@ -633,17 +548,24 @@ public abstract class Num implements NumBound { |
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public double value() |
|
|
|
public double value() |
|
|
|
{ |
|
|
|
{ |
|
|
|
return Math.signum(t.value()); |
|
|
|
final double v = t.value(); |
|
|
|
|
|
|
|
return v * v; |
|
|
|
} |
|
|
|
} |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
return p_sgn; |
|
|
|
return p_square; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public Num sin() |
|
|
|
public Num half() |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (p_sin == null) p_sin = new Num() { |
|
|
|
return mul(0.5); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public Num max(final double other) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
return new Num() { |
|
|
|
|
|
|
|
|
|
|
|
final Num t = Num.this; |
|
|
|
final Num t = Num.this; |
|
|
|
|
|
|
|
|
|
|
@ -651,17 +573,15 @@ public abstract class Num implements NumBound { |
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public double value() |
|
|
|
public double value() |
|
|
|
{ |
|
|
|
{ |
|
|
|
return Math.sin(t.value()); |
|
|
|
return Math.max(t.value(), other); |
|
|
|
} |
|
|
|
} |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
return p_sin; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public Num sqrt() |
|
|
|
public Num max(final Num other) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (p_sqrt == null) p_sqrt = new Num() { |
|
|
|
return new Num() { |
|
|
|
|
|
|
|
|
|
|
|
final Num t = Num.this; |
|
|
|
final Num t = Num.this; |
|
|
|
|
|
|
|
|
|
|
@ -669,17 +589,15 @@ public abstract class Num implements NumBound { |
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public double value() |
|
|
|
public double value() |
|
|
|
{ |
|
|
|
{ |
|
|
|
return Math.sqrt(t.value()); |
|
|
|
return Math.max(t.value(), other.value()); |
|
|
|
} |
|
|
|
} |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
return p_sqrt; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public Num square() |
|
|
|
public Num min(final Num other) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (p_square == null) p_square = new Num() { |
|
|
|
return new Num() { |
|
|
|
|
|
|
|
|
|
|
|
final Num t = Num.this; |
|
|
|
final Num t = Num.this; |
|
|
|
|
|
|
|
|
|
|
@ -687,22 +605,13 @@ public abstract class Num implements NumBound { |
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public double value() |
|
|
|
public double value() |
|
|
|
{ |
|
|
|
{ |
|
|
|
final double v = t.value(); |
|
|
|
return Math.min(t.value(), other.value()); |
|
|
|
return v * v; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
return p_square; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public Num sub(final double subtrahend) |
|
|
|
public Num min(final double other) |
|
|
|
{ |
|
|
|
|
|
|
|
return add(-subtrahend); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public Num sub(final Num subtrahend) |
|
|
|
|
|
|
|
{ |
|
|
|
{ |
|
|
|
return new Num() { |
|
|
|
return new Num() { |
|
|
|
|
|
|
|
|
|
|
@ -712,15 +621,15 @@ public abstract class Num implements NumBound { |
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public double value() |
|
|
|
public double value() |
|
|
|
{ |
|
|
|
{ |
|
|
|
return t.value() - eval(subtrahend); |
|
|
|
return Math.min(t.value(), other); |
|
|
|
} |
|
|
|
} |
|
|
|
}; |
|
|
|
}; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public Num tan() |
|
|
|
public Num signum() |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (p_tan == null) p_tan = new Num() { |
|
|
|
if (p_sgn == null) p_sgn = new Num() { |
|
|
|
|
|
|
|
|
|
|
|
final Num t = Num.this; |
|
|
|
final Num t = Num.this; |
|
|
|
|
|
|
|
|
|
|
@ -728,11 +637,29 @@ public abstract class Num implements NumBound { |
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public double value() |
|
|
|
public double value() |
|
|
|
{ |
|
|
|
{ |
|
|
|
return Math.tan(t.value()); |
|
|
|
return Math.signum(t.value()); |
|
|
|
} |
|
|
|
} |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
return p_tan; |
|
|
|
return p_sgn; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public boolean isNegative() |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
return value() < 0; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public boolean isPositive() |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
return value() > 0; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public boolean isZero() |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
return value() == 0; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -756,7 +683,7 @@ public abstract class Num implements NumBound { |
|
|
|
if (!(obj instanceof Num)) return false; |
|
|
|
if (!(obj instanceof Num)) return false; |
|
|
|
final Num other = (Num) obj; |
|
|
|
final Num other = (Num) obj; |
|
|
|
|
|
|
|
|
|
|
|
return eq(other); |
|
|
|
return value() == other.value(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|