Package de.florianmichael.rclasses.math
Class Arithmetics
java.lang.Object
de.florianmichael.rclasses.math.Arithmetics
Implementation of a math utility.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic doubleclamp(double value, double minimum, double maximum) static floatclamp(float value, float minimum, float maximum) static intclamp(int value, int minimum, int maximum) static longclamp(long value, long minimum, long maximum) static shortclamp(short value, short minimum, short maximum) static doubleconjugate(double value) static floatconjugate(float value) static intconjugate(int value) static longconjugate(long value) static shortconjugate(short value) static doubleinterpolate(double start, double end, double progress) Interpolates between two values with the given progress.static floatinterpolate(float start, float end, float progress) Interpolates between two values with the given progress.static booleanisDecimal(double value) static booleanisDecimal(float value) static doubleroundAvoid(double value, int places) static floatroundAvoid(float value, int places) static doubleroundAwayFromZero(double x) static doublesum(double... values) static floatsum(float... values) static intsum(int... values) static longsum(long... values) static shortsum(short... values)
-
Constructor Details
-
Arithmetics
public Arithmetics()
-
-
Method Details
-
interpolate
public static float interpolate(float start, float end, float progress) Interpolates between two values with the given progress.- Parameters:
start- The start value.end- The end value.progress- The progress.- Returns:
- The interpolated value.
-
interpolate
public static double interpolate(double start, double end, double progress) Interpolates between two values with the given progress.- Parameters:
start- The start value.end- The end value.progress- The progress.- Returns:
- The interpolated value.
-
conjugate
public static short conjugate(short value) - Parameters:
value- The value to be conjugated.- Returns:
- the reciprocal value of the given value.
-
conjugate
public static int conjugate(int value) - Parameters:
value- The value to be conjugated.- Returns:
- the reciprocal value of the given value.
-
conjugate
public static long conjugate(long value) - Parameters:
value- The value to be conjugated.- Returns:
- the reciprocal value of the given value.
-
conjugate
public static float conjugate(float value) - Parameters:
value- The value to be conjugated.- Returns:
- the reciprocal value of the given value.
-
conjugate
public static double conjugate(double value) - Parameters:
value- The value to be conjugated.- Returns:
- the reciprocal value of the given value.
-
sum
public static short sum(short... values) - Parameters:
values- The values to sum.- Returns:
- The sum of the given values.
-
sum
public static int sum(int... values) - Parameters:
values- The values to sum.- Returns:
- The sum of the given values.
-
sum
public static long sum(long... values) - Parameters:
values- The values to sum.- Returns:
- The sum of the given values.
-
sum
public static float sum(float... values) - Parameters:
values- The values to sum.- Returns:
- The sum of the given values.
-
sum
public static double sum(double... values) - Parameters:
values- The values to sum.- Returns:
- The sum of the given values.
-
clamp
public static short clamp(short value, short minimum, short maximum) - Parameters:
value- The value to clamp.minimum- The minimum value.maximum- The maximum value.- Returns:
- The clamped value. If the value is smaller than the minimum, the minimum is returned. If the value is greater than the maximum, the maximum is returned. Otherwise, the value is returned.
-
clamp
public static int clamp(int value, int minimum, int maximum) - Parameters:
value- The value to clamp.minimum- The minimum value.maximum- The maximum value.- Returns:
- The clamped value. If the value is smaller than the minimum, the minimum is returned. If the value is greater than the maximum, the maximum is returned. Otherwise, the value is returned.
-
clamp
public static long clamp(long value, long minimum, long maximum) - Parameters:
value- The value to clamp.minimum- The minimum value.maximum- The maximum value.- Returns:
- The clamped value. If the value is smaller than the minimum, the minimum is returned. If the value is greater than the maximum, the maximum is returned. Otherwise, the value is returned.
-
clamp
public static float clamp(float value, float minimum, float maximum) - Parameters:
value- The value to clamp.minimum- The minimum value.maximum- The maximum value.- Returns:
- The clamped value. If the value is smaller than the minimum, the minimum is returned. If the value is greater than the maximum, the maximum is returned. Otherwise, the value is returned.
-
clamp
public static double clamp(double value, double minimum, double maximum) - Parameters:
value- The value to clamp.minimum- The minimum value.maximum- The maximum value.- Returns:
- The clamped value. If the value is smaller than the minimum, the minimum is returned. If the value is greater than the maximum, the maximum is returned. Otherwise, the value is returned.
-
roundAwayFromZero
public static double roundAwayFromZero(double x) - Parameters:
x- The number to round.- Returns:
- The rounded number. If the number is negative, it will be rounded down. If the number is positive, it will be rounded up.
-
roundAvoid
public static double roundAvoid(double value, int places) - Parameters:
value- The value to round.places- The number of places to round to.- Returns:
- The given value rounded to the given number of places.
-
roundAvoid
public static float roundAvoid(float value, int places) - Parameters:
value- The value to round.places- The number of places to round to.- Returns:
- The given value rounded to the given number of places.
-
isDecimal
public static boolean isDecimal(float value) - Parameters:
value- The value to check.- Returns:
- Whether the given value is a decimal.
-
isDecimal
public static boolean isDecimal(double value) - Parameters:
value- The value to check.- Returns:
- Whether the given value is a decimal.
-