Class MathUtils

java.lang.Object
com.sk89q.worldedit.math.MathUtils

public final class MathUtils extends Object
Various math utility methods.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final double
    Safe minimum, such that 1 / SAFE_MIN does not overflow.
  • Method Summary

    Modifier and Type
    Method
    Description
    static double
    dCos(double degrees)
    Returns the cosine of an angle given in degrees.
    static int
    divisorMod(int a, int n)
    Modulus, divisor-style.
    static double
    dSin(double degrees)
    Returns the sine of an angle given in degrees.
    static double
    roundHalfUp(double value)
    Returns the rounded double of the given value, rounding to the nearest integer value away from zero on ties.

    Methods inherited from class java.lang.Object

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

    • SAFE_MIN

      public static final double SAFE_MIN
      Safe minimum, such that 1 / SAFE_MIN does not overflow.

      In IEEE 754 arithmetic, this is also the smallest normalized number 2-1022. The value of this constant is from Apache Commons Math 2.2.

      See Also:
  • Method Details

    • divisorMod

      public static int divisorMod(int a, int n)
      Modulus, divisor-style.
      Parameters:
      a - a
      n - n
      Returns:
      the modulus
    • dCos

      public static double dCos(double degrees)
      Returns the cosine of an angle given in degrees. This is better than just Math.cos(Math.toRadians(degrees)) because it provides a more accurate result for angles divisible by 90 degrees.
      Parameters:
      degrees - the angle
      Returns:
      the cosine of the given angle
    • dSin

      public static double dSin(double degrees)
      Returns the sine of an angle given in degrees. This is better than just Math.sin(Math.toRadians(degrees)) because it provides a more accurate result for angles divisible by 90 degrees.
      Parameters:
      degrees - the angle
      Returns:
      the sine of the given angle
    • roundHalfUp

      public static double roundHalfUp(double value)
      Returns the rounded double of the given value, rounding to the nearest integer value away from zero on ties.

      This behavior is the same as RoundingMode.HALF_UP.

      Parameters:
      value - the value
      Returns:
      the rounded value