Class Arithmetics

java.lang.Object
de.florianmichael.rclasses.math.Arithmetics

public class Arithmetics extends Object
Implementation of a math utility.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static double
    clamp(double value, double minimum, double maximum)
     
    static float
    clamp(float value, float minimum, float maximum)
     
    static int
    clamp(int value, int minimum, int maximum)
     
    static long
    clamp(long value, long minimum, long maximum)
     
    static short
    clamp(short value, short minimum, short maximum)
     
    static double
    conjugate(double value)
     
    static float
    conjugate(float value)
     
    static int
    conjugate(int value)
     
    static long
    conjugate(long value)
     
    static short
    conjugate(short value)
     
    static double
    interpolate(double start, double end, double progress)
    Interpolates between two values with the given progress.
    static float
    interpolate(float start, float end, float progress)
    Interpolates between two values with the given progress.
    static boolean
    isDecimal(double value)
     
    static boolean
    isDecimal(float value)
     
    static double
    roundAvoid(double value, int places)
     
    static float
    roundAvoid(float value, int places)
     
    static double
     
    static double
    sum(double... values)
     
    static float
    sum(float... values)
     
    static int
    sum(int... values)
     
    static long
    sum(long... values)
     
    static short
    sum(short... values)
     

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • 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.