Class ExactMath

java.lang.Object
com.oracle.truffle.api.ExactMath

public final class ExactMath extends Object
This class contains exact math related methods that are generally useful for dynamic language implementations.
Since:
0.8 or earlier
  • Method Details

    • multiplyHigh

      public static int multiplyHigh(int x, int y)
      Since:
      0.8 or earlier
    • multiplyHighUnsigned

      public static int multiplyHighUnsigned(int x, int y)
      Since:
      0.8 or earlier
    • multiplyHigh

      public static long multiplyHigh(long x, long y)
      Since:
      0.8 or earlier
    • multiplyHighUnsigned

      public static long multiplyHighUnsigned(long x, long y)
      Since:
      0.8 or earlier
    • truncate

      public static float truncate(float x)
      Removes the decimal part (aka truncation or rounds towards zero) of the given float.

      This corresponds to the IEEE 754 roundToIntegralTowardZero operation (IEEE Std 754-2008, section 5.9, page 41).

      Since:
      21.1
    • truncate

      public static double truncate(double x)
      Removes the decimal part (aka truncation or rounds towards zero) of the given double.

      This corresponds to the IEEE 754 roundToIntegralTowardZero operation (IEEE Std 754-2008, section 5.9, page 41).

      Since:
      21.1
    • truncateToUnsignedLong

      public static long truncateToUnsignedLong(double x)
      Converts the double value to unsigned long with truncation (i.e. rounding towards zero) and saturation of NaN and x <= -1 to 0, and x >= 264 to 263-1 (-1).

      Non-saturating (e.g. trapping) behavior can be implemented by checking the input for NaN, underflow (x <= -1) and overflow (x >= 0x1p64) first.

      Parameters:
      x - input value
      Returns:
      the unsigned integer result, wrapped in a signed integer
      Since:
      25.0
    • truncateToUnsignedLong

      public static long truncateToUnsignedLong(float x)
      Converts the float value to unsigned long with truncation (i.e. rounding towards zero) and saturation of NaN and x <= -1 to 0, and x >= 264 to 263-1 (-1).

      Non-saturating (e.g. trapping) behavior can be implemented by checking the input for NaN, underflow (x <= -1f) and overflow (x >= 0x1p64f) first.

      Parameters:
      x - input value
      Returns:
      the unsigned integer result, wrapped in a signed integer
      Since:
      25.0
    • truncateToUnsignedInt

      public static int truncateToUnsignedInt(double x)
      Converts the double value to unsigned long with truncation (i.e. rounding towards zero) and saturation of NaN and x <= -1 to 0, and x >= 232 to 231-1 (-1).

      Non-saturating (e.g. trapping) behavior can be implemented by checking the input for NaN, underflow (x <= -1) and overflow (x >= 0x1p32) first.

      Parameters:
      x - input value
      Returns:
      the unsigned integer result, wrapped in a signed integer
      Since:
      25.0
    • truncateToUnsignedInt

      public static int truncateToUnsignedInt(float x)
      Converts the float value to unsigned int with truncation (i.e. rounding towards zero) and saturation of NaN and x <= -1 to 0, and x >= 232 to 231-1 (-1).

      Non-saturating (e.g. trapping) behavior can be implemented by checking the input for NaN, underflow (x <= -1) and overflow (x >= 0x1p64) first.

      Parameters:
      x - input value
      Returns:
      the unsigned integer result, wrapped in a signed integer
      Since:
      25.0
    • unsignedToDouble

      public static double unsignedToDouble(long x)
      Converts the given unsigned long to the closest double value.
      Parameters:
      x - unsigned integer input, wrapped in a signed integer
      Returns:
      the double result
      Since:
      25.0
    • unsignedToFloat

      public static float unsignedToFloat(long x)
      Converts the given unsigned long to the closest float value.
      Parameters:
      x - unsigned integer input, wrapped in a signed integer
      Returns:
      the float result
      Since:
      25.0