Class MathUtil

java.lang.Object
io.deephaven.base.MathUtil

public class MathUtil extends Object
A handful of simple mathematical utilities.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static int
    base10digits(int n)
    Compute the number of base 10 digits in n's representation, for n >= 0.
    static int
    ceilLog2(int x)
    Compute ceil(log2(x)).
    static int
    ceilLog2(long x)
    Compute ceil(log2(x)).
    static int
    floorLog2(int x)
    Compute floor(log2(x)).
    static int
    floorLog2(long x)
    Compute floor(log2(x)).
    static int
    gcd(int a, int b)
    Compute the greatest common divisor of two integers using the Euclidean algorithm.
    static int
    pow10(int n)
    Compute 10^n as a int for 0 <= n <= 9.

    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

    • ceilLog2

      public static int ceilLog2(int x)
      Compute ceil(log2(x)). See Integer.numberOfLeadingZeros(int).
      Parameters:
      x - Input
      Returns:
      ceil(log2(x))
    • floorLog2

      public static int floorLog2(int x)
      Compute floor(log2(x)). See Integer.numberOfLeadingZeros(int).
      Parameters:
      x - Input
      Returns:
      floor(log2(x))
    • ceilLog2

      public static int ceilLog2(long x)
      Compute ceil(log2(x)). See Long.numberOfLeadingZeros(long).
      Parameters:
      x - Input
      Returns:
      ceil(log2(x))
    • floorLog2

      public static int floorLog2(long x)
      Compute floor(log2(x)). See Long.numberOfLeadingZeros(long).
      Parameters:
      x - Input
      Returns:
      floor(log2(x))
    • gcd

      public static int gcd(int a, int b)
      Compute the greatest common divisor of two integers using the Euclidean algorithm.
      Parameters:
      a - The first input
      b - The second input
      Returns:
      The GCD
      ImplNote:
      Always gives a non-negative result.
    • pow10

      public static int pow10(int n)
      Compute 10^n as a int for 0 <= n <= 9.
      Parameters:
      n - the exponent
      Returns:
      10^n
    • base10digits

      public static int base10digits(int n)
      Compute the number of base 10 digits in n's representation, for n >= 0.
      Parameters:
      n - an integer >= 0
      Returns:
      how many digits in n's base 10 representation.