Class MathUtil

java.lang.Object
jj2000.j2k.util.MathUtil

public class MathUtil extends Object
This class contains a collection of utility methods fro mathematical operations. All methods are static.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static final int
    gcd(int[] x)
    Method that calculates the Greatest Common Divisor (GCD) of several positive integer numbers.
    static final int
    gcd(int x1, int x2)
    Method that calculates the Greatest Common Divisor (GCD) of two positive integer numbers.
    static final int
    lcm(int[] x)
    Method that calculates the Least Common Multiple (LCM) of several positive integer numbers.
    static final int
    lcm(int x1, int x2)
    Method that calculates the Least Common Multiple (LCM) of two strictly positive integer numbers.
    static int
    log2(int x)
    Method that calculates the floor of the log, base 2, of 'x'.

    Methods inherited from class java.lang.Object

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

    • MathUtil

      public MathUtil()
  • Method Details

    • log2

      public static int log2(int x)
      Method that calculates the floor of the log, base 2, of 'x'. The calculation is performed in integer arithmetic, therefore, it is exact.
      Parameters:
      x - The value to calculate log2 on.
      Returns:
      floor(log(x)/log(2)), calculated in an exact way.
    • lcm

      public static final int lcm(int x1, int x2)
      Method that calculates the Least Common Multiple (LCM) of two strictly positive integer numbers.
      Parameters:
      x1 - First number
      x2 - Second number
    • lcm

      public static final int lcm(int[] x)
      Method that calculates the Least Common Multiple (LCM) of several positive integer numbers.
      Parameters:
      x - Array containing the numbers.
    • gcd

      public static final int gcd(int x1, int x2)
      Method that calculates the Greatest Common Divisor (GCD) of two positive integer numbers.
    • gcd

      public static final int gcd(int[] x)
      Method that calculates the Greatest Common Divisor (GCD) of several positive integer numbers.
      Parameters:
      x - Array containing the numbers.