Class Floats

java.lang.Object
com.pnfsoftware.jeb.util.primitives.Floats

public class Floats extends Object
Utility methods for float values and IEEE-754 binary32/16 bit patterns.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static float
    fromBF16Bits(int bits)
    Convert raw bfloat16 bits to a Java float.
    static float
    fromFP16Bits(int bits)
    Convert raw IEEE-754 binary16 bits to a Java float.
    static int
    getNaNType(float f)
    Determine the NaN type of a float.
    static int
    getNaNType(int bits)
    Determine the NaN type of a raw fp32 bit pattern.
    static int
    getSpecialType(float f)
    Determine whether a float is finite, infinite, or a NaN.
    static int
    getSpecialType(int bits)
    Determine whether a raw fp32 bit pattern is finite, infinite, or a NaN.
    static boolean
    isQuietNaN(float f)
    Determine whether a float is a quiet NaN.
    static boolean
    isQuietNaN(int bits)
    Determine whether a raw fp32 bit pattern represents a quiet NaN.
    static boolean
    isSignalingNaN(float f)
    Determine whether a float is a signaling NaN.
    static boolean
    isSignalingNaN(int bits)
    Determine whether a raw fp32 bit pattern represents a signaling NaN.

    Methods inherited from class java.lang.Object

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

    • Floats

      public Floats()
  • Method Details

    • getSpecialType

      public static int getSpecialType(float f)
      Determine whether a float is finite, infinite, or a NaN.
      Parameters:
      f - an fp32 float
      Returns:
      0=not a NaN; 1=quiet NaN; 2=signaling NaN, 3=infinite
    • getSpecialType

      public static int getSpecialType(int bits)
      Determine whether a raw fp32 bit pattern is finite, infinite, or a NaN.
      Parameters:
      bits - raw bits of an fp32 primitive
      Returns:
      0=not a NaN; 1=quiet NaN; 2=signaling NaN, 3=infinite
    • getNaNType

      public static int getNaNType(float f)
      Determine the NaN type of a float.
      Parameters:
      f - an fp32 float
      Returns:
      0=not a NaN; 1=quiet NaN; 2=signaling NaN
    • getNaNType

      public static int getNaNType(int bits)
      Determine the NaN type of a raw fp32 bit pattern.
      Parameters:
      bits - raw bits of an fp32 primitive
      Returns:
      0=not a NaN; 1=quiet NaN; 2=signaling NaN
    • isQuietNaN

      public static boolean isQuietNaN(float f)
      Determine whether a float is a quiet NaN.
      Parameters:
      f - an fp32 float
      Returns:
      true if the value is a quiet NaN
    • isQuietNaN

      public static boolean isQuietNaN(int bits)
      Determine whether a raw fp32 bit pattern represents a quiet NaN.
      Parameters:
      bits - raw bits of an fp32 primitive
      Returns:
      true if the bit pattern represents a quiet NaN
    • isSignalingNaN

      public static boolean isSignalingNaN(float f)
      Determine whether a float is a signaling NaN.
      Parameters:
      f - an fp32 float
      Returns:
      true if the value is a signaling NaN
    • isSignalingNaN

      public static boolean isSignalingNaN(int bits)
      Determine whether a raw fp32 bit pattern represents a signaling NaN.
      Parameters:
      bits - raw bits of an fp32 primitive
      Returns:
      true if the bit pattern represents a signaling NaN
    • fromFP16Bits

      public static float fromFP16Bits(int bits)
      Convert raw IEEE-754 binary16 bits to a Java float.
      Parameters:
      bits - raw bits of a FP16 (half-precision fp)
      Returns:
      a float representing the input
    • fromBF16Bits

      public static float fromBF16Bits(int bits)
      Convert raw bfloat16 bits to a Java float.
      Parameters:
      bits - raw bits of a BF16 (also named bfloat16, or E8M7 fp)
      Returns:
      a float representing the input