Package ghidra.util

Class MathUtilities


  • public class MathUtilities
    extends java.lang.Object
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static int clamp​(int value, int min, int max)
      Ensures that the given value is within the given range.
      static void main​(java.lang.String[] args)  
      static long unsignedDivide​(long numerator, long denominator)
      Perform unsigned division.
      static int unsignedMax​(int a, int b)
      Compute the maximum, treating the inputs as unsigned
      static long unsignedMax​(int a, long b)
      Compute the maximum, treating the inputs as unsigned
      static long unsignedMax​(long a, int b)
      Compute the maximum, treating the inputs as unsigned
      static long unsignedMax​(long a, long b)
      Compute the maximum, treating the inputs as unsigned
      static int unsignedMin​(int a, int b)
      Compute the minimum, treating the inputs as unsigned
      static int unsignedMin​(int a, long b)
      Compute the minimum, treating the inputs as unsigned
      static int unsignedMin​(long a, int b)
      Compute the minimum, treating the inputs as unsigned
      static long unsignedMin​(long a, long b)
      Compute the minimum, treating the inputs as unsigned
      static long unsignedModulo​(long numerator, long denominator)
      Perform unsigned modulo.
      • Methods inherited from class java.lang.Object

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

      • unsignedDivide

        public static long unsignedDivide​(long numerator,
                                          long denominator)
        Perform unsigned division. Provides proper handling of all 64-bit unsigned values.
        Parameters:
        numerator - unsigned numerator
        denominator - positive divisor
        Returns:
        result of unsigned division
        Throws:
        java.lang.IllegalArgumentException - if negative denominator is specified
      • unsignedModulo

        public static long unsignedModulo​(long numerator,
                                          long denominator)
        Perform unsigned modulo. Provides proper handling of all 64-bit unsigned values.
        Parameters:
        numerator - unsigned numerator
        denominator - positive divisor
        Returns:
        result of unsigned modulo (i.e., remainder)
        Throws:
        java.lang.IllegalArgumentException - if negative denominator is specified
      • clamp

        public static int clamp​(int value,
                                int min,
                                int max)
        Ensures that the given value is within the given range.
        Parameters:
        value - the value to check
        min - the minimum value allowed
        max - the maximum value allowed
        Returns:
        the clamped value
      • main

        public static void main​(java.lang.String[] args)
      • unsignedMin

        public static long unsignedMin​(long a,
                                       long b)
        Compute the minimum, treating the inputs as unsigned
        Parameters:
        a - the first value to consider
        b - the second value to consider
        Returns:
        the minimum
      • unsignedMin

        public static int unsignedMin​(int a,
                                      int b)
        Compute the minimum, treating the inputs as unsigned
        Parameters:
        a - the first value to consider
        b - the second value to consider
        Returns:
        the minimum
      • unsignedMin

        public static int unsignedMin​(int a,
                                      long b)
        Compute the minimum, treating the inputs as unsigned

        This method is overloaded to prevent accidental signed-extension on one of the inputs. This method will correctly zero-extend the int parameter before performing any comparison. Also note the return type is int, since b would never be selected if it overflows an int.

        Parameters:
        a - the first value to consider
        b - the second value to consider
        Returns:
        the minimum
      • unsignedMin

        public static int unsignedMin​(long a,
                                      int b)
        Compute the minimum, treating the inputs as unsigned

        This method is overloaded to prevent accidental signed-extension on one of the inputs. This method will correctly zero-extend the int parameter before performing any comparison. Also note the return type is int, since b would never be selected if it overflows an int.

        Parameters:
        a - the first value to consider
        b - the second value to consider
        Returns:
        the minimum
      • unsignedMax

        public static long unsignedMax​(long a,
                                       long b)
        Compute the maximum, treating the inputs as unsigned
        Parameters:
        a - the first value to consider
        b - the second value to consider
        Returns:
        the maximum
      • unsignedMax

        public static int unsignedMax​(int a,
                                      int b)
        Compute the maximum, treating the inputs as unsigned
        Parameters:
        a - the first value to consider
        b - the second value to consider
        Returns:
        the maximum
      • unsignedMax

        public static long unsignedMax​(int a,
                                       long b)
        Compute the maximum, treating the inputs as unsigned

        This method is overloaded to prevent accidental signed-extension on one of the inputs. This method will correctly zero-extend the int parameter before performing any comparison.

        Parameters:
        a - the first value to consider
        b - the second value to consider
        Returns:
        the maximum
      • unsignedMax

        public static long unsignedMax​(long a,
                                       int b)
        Compute the maximum, treating the inputs as unsigned

        This method is overloaded to prevent accidental signed-extension on one of the inputs. This method will correctly zero-extend the int parameter before performing any comparison.

        Parameters:
        a - the first value to consider
        b - the second value to consider
        Returns:
        the maximum