Fixed type priority handling for some methods in Scalar.
@@ -293,21 +293,13 @@ public class Scalar implements RandomVariable {
@Override
public RandomVariable cap(RandomVariable cap) {
- if(cap.isDeterministic()) {
- return new Scalar(Math.min(value, cap.get(0)));
- } else {
return cap.cap(value);
}
- }
@Override
public RandomVariable floor(RandomVariable floor) {
- if(floor.isDeterministic()) {
- return new Scalar(Math.max(value, floor.get(0)));
- } else {
return floor.floor(value);
}
- }
@Override
public RandomVariable accrue(RandomVariable rate, double periodLength) {
@@ -317,7 +309,7 @@ public class Scalar implements RandomVariable {
@Override
public RandomVariable discount(RandomVariable rate, double periodLength) {
if(value == 0) {
- return new Scalar(0.0);
+ return rate.mult(0.0);
}
else {
return rate.mult(periodLength/value).add(1.0/value).invert();
@@ -342,39 +334,23 @@ public class Scalar implements RandomVariable {
@Override
public RandomVariable addProduct(RandomVariable factor1, double factor2) {
- if(factor1.isDeterministic()) {
- return new Scalar(value + factor1.get(0) * factor2);
- } else {
return factor1.mult(factor2).add(value);
}
- }
@Override
public RandomVariable addProduct(RandomVariable factor1, RandomVariable factor2) {
- if(factor1.isDeterministic() && factor2.isDeterministic()) {
- return new Scalar(value + factor1.get(0) * factor2.get(0));
- } else {
return factor1.mult(factor2).add(value);
}
- }
@Override
public RandomVariable addRatio(RandomVariable numerator, RandomVariable denominator) {
- if(numerator.isDeterministic() && denominator.isDeterministic()) {
- return new Scalar(value + numerator.get(0) * denominator.get(0));
- } else {
return numerator.div(denominator).add(value);
}
- }
@Override
public RandomVariable subRatio(RandomVariable numerator, RandomVariable denominator) {
- if(numerator.isDeterministic() && denominator.isDeterministic()) {
- return new Scalar(value - numerator.get(0) * denominator.get(0));
- } else {
return numerator.div(denominator).sub(value).mult(-1.0);
}
- }
@Override
public RandomVariable isNaN() {
