[Minor] round to 8 decimals in FloatParameter and FloatValue
This commit is contained in:
parent
4de72bfe8b
commit
00e41fdc4a
|
@ -18,10 +18,10 @@ package li.strolch.model.parameter;
|
||||||
import li.strolch.model.StrolchValueType;
|
import li.strolch.model.StrolchValueType;
|
||||||
import li.strolch.model.visitor.ParameterVisitor;
|
import li.strolch.model.visitor.ParameterVisitor;
|
||||||
import li.strolch.utils.dbc.DBC;
|
import li.strolch.utils.dbc.DBC;
|
||||||
|
import li.strolch.utils.helper.MathHelper;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Robert von Burg <eitch@eitchnet.ch>
|
* @author Robert von Burg <eitch@eitchnet.ch>
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
public class FloatParameter extends AbstractParameter<Double> {
|
public class FloatParameter extends AbstractParameter<Double> {
|
||||||
|
|
||||||
|
@ -63,7 +63,7 @@ public class FloatParameter extends AbstractParameter<Double> {
|
||||||
@Override
|
@Override
|
||||||
public void setValue(Double value) {
|
public void setValue(Double value) {
|
||||||
validateValue(value);
|
validateValue(value);
|
||||||
this.value = value;
|
this.value = MathHelper.toPrecision(value, 8);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -20,6 +20,7 @@ import java.io.Serializable;
|
||||||
import li.strolch.model.StrolchValueType;
|
import li.strolch.model.StrolchValueType;
|
||||||
import li.strolch.model.timevalue.ITimeValue;
|
import li.strolch.model.timevalue.ITimeValue;
|
||||||
import li.strolch.model.timevalue.IValue;
|
import li.strolch.model.timevalue.IValue;
|
||||||
|
import li.strolch.utils.helper.MathHelper;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@link IValue} implementation to work with Double valued {@link ITimeValue} objects
|
* {@link IValue} implementation to work with Double valued {@link ITimeValue} objects
|
||||||
|
@ -61,7 +62,7 @@ public class FloatValue implements IValue<Double>, Serializable {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public FloatValue add(Double o) {
|
public FloatValue add(Double o) {
|
||||||
this.value += o;
|
this.value = MathHelper.toPrecision(this.value + o, 8);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -36,10 +36,10 @@ public class MathHelper {
|
||||||
* the first value to compare
|
* the first value to compare
|
||||||
* @param secondValue
|
* @param secondValue
|
||||||
* the second value to compare to
|
* the second value to compare to
|
||||||
|
*
|
||||||
* @return boolean True, if the two values are equal under the set precision. Fales, otherwise.
|
* @return boolean True, if the two values are equal under the set precision. Fales, otherwise.
|
||||||
*/
|
*/
|
||||||
public static boolean isEqualPrecision(double firstValue, double secondValue) {
|
public static boolean isEqualPrecision(double firstValue, double secondValue) {
|
||||||
|
|
||||||
return (java.lang.Math.abs(firstValue - secondValue) < (1.0d / PRECISION));
|
return (java.lang.Math.abs(firstValue - secondValue) < (1.0d / PRECISION));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -54,12 +54,11 @@ public class MathHelper {
|
||||||
* The value to check
|
* The value to check
|
||||||
* @param bound
|
* @param bound
|
||||||
* The bound given
|
* The bound given
|
||||||
|
*
|
||||||
* @return true, if value < bound under the given precision. False, otherwise.
|
* @return true, if value < bound under the given precision. False, otherwise.
|
||||||
*/
|
*/
|
||||||
public static boolean isSmallerEqualPrecision(double value, double bound) {
|
public static boolean isSmallerEqualPrecision(double value, double bound) {
|
||||||
if (value < bound)
|
return value < bound || isEqualPrecision(value, bound);
|
||||||
return true;
|
|
||||||
return isEqualPrecision(value, bound);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -73,6 +72,7 @@ public class MathHelper {
|
||||||
* The value to check
|
* The value to check
|
||||||
* @param bound
|
* @param bound
|
||||||
* The bound given.
|
* The bound given.
|
||||||
|
*
|
||||||
* @return true, if value > bound and the values do not test equal under precision. False, otherwise.
|
* @return true, if value > bound and the values do not test equal under precision. False, otherwise.
|
||||||
*/
|
*/
|
||||||
public static boolean isGreaterPrecision(double value, double bound) {
|
public static boolean isGreaterPrecision(double value, double bound) {
|
||||||
|
|
Loading…
Reference in New Issue