Class Calculation
java.lang.Object
de.redstoneworld.redutilities.math.Calculation
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic longgetMillisFromServerTicks(long serverTicks) static longgetServerTicksFromMillis(long millis) static booleanisBetween(double value, double limitA, double limitB, boolean inclusiveLimitValues) This method checks whether a specific value is within a range of values.static doubleroundToX(double input, double step) This method rounds up the input to the desired accuracy.
-
Constructor Details
-
Calculation
public Calculation()
-
-
Method Details
-
getMillisFromServerTicks
public static long getMillisFromServerTicks(long serverTicks) -
getServerTicksFromMillis
public static long getServerTicksFromMillis(long millis) -
roundToX
public static double roundToX(double input, double step) This method rounds up the input to the desired accuracy. The accuracy value specifies the step sizes between which rounding takes place.- The value is always rounded to the nearest multiple of
step. - Ties (values exactly halfway between two multiples) are always rounded up,
following the behavior of
Math.round(double). - Smaller values of
stepresult in finer rounding granularity.
- step = 1.0 => 0.0; 1.0
- step = 0.5 => 0.0; 0.5; 1.0
- step = 0.25 => 0.0; 0.25; 0.5; 0.75; 1.0
- step = 0.1 => 0.0; 0.1; ... 0.9; 1.0
- step = 0.05 => 0.0; 0.05; ... 0.95; 1.0
- Parameters:
input- (double) the target value for the roundingstep- (double) rounding accuracy- Returns:
- (double) the rounded value
- The value is always rounded to the nearest multiple of
-
isBetween
public static boolean isBetween(double value, double limitA, double limitB, boolean inclusiveLimitValues) This method checks whether a specific value is within a range of values. Two limit values are used as interval limits, whose order (MIN, MAX) is irrelevant. The limit is included ("Closed Interval"), if 'inclusiveLimitValues' is 'true'. Otherwise, the limit is exclusive ("Open Interval").- Parameters:
value- (Double) the target value for the checklimitA- (Double) the first interval limitlimitB- (Double) the second interval limitinclusiveLimitValues- (Boolean) 'true', if the interval limits are included in the range- Returns:
- (Boolean) 'true', if the target values is a part of the specified interval
-