diff --git a/prism/src/explicit/StateValues.java b/prism/src/explicit/StateValues.java index 7fe52326..6be220c4 100644 --- a/prism/src/explicit/StateValues.java +++ b/prism/src/explicit/StateValues.java @@ -707,6 +707,46 @@ public class StateValues } } + /** + * Modify the vector by applying 'plus' with a constant. + */ + public void plusConstant(int val) throws PrismException + { + if (type instanceof TypeInt) { + for (int i = 0; i < size; i++) { + valuesI[i] += val; + } + } else if (type instanceof TypeDouble) { + for (int i = 0; i < size; i++) { + valuesD[i] += val; + } + } else { + throw new PrismException("Operator + can not be applied to Boolean vectors"); + } + } + + /** + * Modify the vector by applying 'plus' with a constant. + */ + public void plusConstant(double val) throws PrismException + { + if (type instanceof TypeInt) { + // Change type + valuesD = new double[size]; + type = TypeDouble.getInstance(); + for (int i = 0; i < size; i++) { + valuesD[i] = valuesI[i] + val; + } + valuesI = null; + } else if (type instanceof TypeDouble) { + for (int i = 0; i < size; i++) { + valuesD[i] += val; + } + } else { + throw new PrismException("Operator + can not be applied to Boolean vectors"); + } + } + /** * Modify the vector by applying 'minus' with operand {@code sv}. */ @@ -781,6 +821,46 @@ public class StateValues } } + /** + * Modify the vector by applying 'times' with a constant. + */ + public void timesConstant(int val) throws PrismException + { + if (type instanceof TypeInt) { + for (int i = 0; i < size; i++) { + valuesI[i] *= val; + } + } else if (type instanceof TypeDouble) { + for (int i = 0; i < size; i++) { + valuesD[i] *= val; + } + } else { + throw new PrismException("Operator + can not be applied to Boolean vectors"); + } + } + + /** + * Modify the vector by applying 'times' with a constant. + */ + public void timesConstant(double val) throws PrismException + { + if (type instanceof TypeInt) { + // Change type + valuesD = new double[size]; + type = TypeDouble.getInstance(); + for (int i = 0; i < size; i++) { + valuesD[i] = valuesI[i] * val; + } + valuesI = null; + } else if (type instanceof TypeDouble) { + for (int i = 0; i < size; i++) { + valuesD[i] *= val; + } + } else { + throw new PrismException("Operator + can not be applied to Boolean vectors"); + } + } + /** * Modify the vector by applying 'divide' with operand {@code sv}. */