Package ch.njol.util

Class Math2

java.lang.Object
ch.njol.util.Math2

@Internal public final class Math2 extends Object
This class is not to be used by addons. In the future methods may change signature, contract and/or get removed without warning.

Behaviour for an edge case like NaN or infinite is undefined.

  • Method Summary

    Modifier and Type
    Method
    Description
    static long
    addClamped(long x, long y)
     
    static long
    ceil(double value)
    Ceils the given double and returns the result as a long.
    static int
    ceil(float value)
    Ceils the given float and returns the result as an int.
    static int
    ceilI(double value)
    Deprecated.
    static double
    fit(double min, double value, double max)
    Fits a double into the given interval.
    static float
    fit(float min, float value, float max)
    Fits a float into the given interval.
    static int
    fit(int min, int value, int max)
    Fits an int into the given interval.
    static long
    fit(long min, long value, long max)
    Fits a long into the given interval.
    static long
    floor(double value)
    Floors the given double and returns the result as a long.
    static long
    floor(float value)
    Deprecated.
    static int
    floorI(double value)
    Deprecated.
    static double
    max(double... numbers)
    Deprecated.
    static double
    max(double a, double b, double c)
    Deprecated.
    static int
    max(int... numbers)
    Deprecated.
    static int
    max(int a, int b, int c)
    Deprecated.
    static double
    min(double... numbers)
    Deprecated.
    static double
    min(double a, double b, double c)
    Deprecated.
    static int
    min(int... numbers)
    Deprecated.
    static int
    min(int a, int b, int c)
    Deprecated.
    static double
    mod(double value, double mod)
    Modulo that returns positive values even for negative arguments.
    static float
    mod(float value, float mod)
    Modulo that returns positive values even for negative arguments.
    static int
    mod(int value, int mod)
    Modulo that returns positive values even for negative arguments.
    static long
    mod(long value, long mod)
    Modulo that returns positive values even for negative arguments.
    static long
    multiplyClamped(long x, long y)
     
    static long
    round(double value)
    Rounds the given double (where .5 is rounded up) and returns the result as a long.
    static int
    round(float value)
    Rounds the given float (where .5 is rounded up) and returns the result as an int.
    static float
    safe(float value)
    Guarantees a float is neither NaN nor infinite.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • fit

      public static int fit(int min, int value, int max)
      Fits an int into the given interval. The method's behaviour when min > max is unspecified.
      Returns:
      An int in between min and max
    • fit

      public static long fit(long min, long value, long max)
      Fits a long into the given interval. The method's behaviour when min > max is unspecified.
      Returns:
      A long in between min and max
    • fit

      public static float fit(float min, float value, float max)
      Fits a float into the given interval. The method's behaviour when min > max is unspecified.
      Returns:
      A float in between min and max
    • fit

      public static double fit(double min, double value, double max)
      Fits a double into the given interval. The method's behaviour when min > max is unspecified.
      Returns:
      A double in between min and max
    • mod

      public static int mod(int value, int mod)
      Modulo that returns positive values even for negative arguments.
      Returns:
      Int result of value modulo mod
    • mod

      public static long mod(long value, long mod)
      Modulo that returns positive values even for negative arguments.
      Returns:
      Long result of value modulo mod
    • mod

      public static float mod(float value, float mod)
      Modulo that returns positive values even for negative arguments.
      Returns:
      Float result of value modulo mod
    • mod

      public static double mod(double value, double mod)
      Modulo that returns positive values even for negative arguments.
      Returns:
      Double result of value modulo mod
    • ceil

      public static int ceil(float value)
      Ceils the given float and returns the result as an int.
    • round

      public static int round(float value)
      Rounds the given float (where .5 is rounded up) and returns the result as an int.
    • floor

      public static long floor(double value)
      Floors the given double and returns the result as a long.
    • ceil

      public static long ceil(double value)
      Ceils the given double and returns the result as a long.
    • round

      public static long round(double value)
      Rounds the given double (where .5 is rounded up) and returns the result as a long.
    • safe

      public static float safe(float value)
      Guarantees a float is neither NaN nor infinite. Useful for situations when safe floats are required.
      Returns:
      0 if value is NaN or infinite, otherwise value
    • addClamped

      public static long addClamped(long x, long y)
      Parameters:
      x - the first value
      y - the second value
      Returns:
      the sum of x and y, or Long.MAX_VALUE in case of an overflow
    • multiplyClamped

      public static long multiplyClamped(long x, long y)
    • floorI

      @Deprecated @ScheduledForRemoval public static int floorI(double value)
      Deprecated.
    • ceilI

      @Deprecated @ScheduledForRemoval public static int ceilI(double value)
      Deprecated.
    • floor

      @Deprecated @ScheduledForRemoval public static long floor(float value)
      Deprecated.
    • min

      @Deprecated @ScheduledForRemoval public static int min(int a, int b, int c)
      Deprecated.
    • min

      @Deprecated @ScheduledForRemoval public static int min(int... numbers)
      Deprecated.
    • max

      @Deprecated @ScheduledForRemoval public static int max(int a, int b, int c)
      Deprecated.
    • max

      @Deprecated @ScheduledForRemoval public static int max(int... numbers)
      Deprecated.
    • min

      @Deprecated @ScheduledForRemoval public static double min(double a, double b, double c)
      Deprecated.
    • min

      @Deprecated @ScheduledForRemoval public static double min(double... numbers)
      Deprecated.
    • max

      @Deprecated @ScheduledForRemoval public static double max(double a, double b, double c)
      Deprecated.
    • max

      @Deprecated @ScheduledForRemoval public static double max(double... numbers)
      Deprecated.