Class Floats
java.lang.Object
com.pnfsoftware.jeb.util.primitives.Floats
Utility methods for
float values and IEEE-754 binary32/16 bit patterns.-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic floatfromBF16Bits(int bits) Convert raw bfloat16 bits to a Java float.static floatfromFP16Bits(int bits) Convert raw IEEE-754 binary16 bits to a Java float.static intgetNaNType(float f) Determine the NaN type of a float.static intgetNaNType(int bits) Determine the NaN type of a raw fp32 bit pattern.static intgetSpecialType(float f) Determine whether a float is finite, infinite, or a NaN.static intgetSpecialType(int bits) Determine whether a raw fp32 bit pattern is finite, infinite, or a NaN.static booleanisQuietNaN(float f) Determine whether a float is a quiet NaN.static booleanisQuietNaN(int bits) Determine whether a raw fp32 bit pattern represents a quiet NaN.static booleanisSignalingNaN(float f) Determine whether a float is a signaling NaN.static booleanisSignalingNaN(int bits) Determine whether a raw fp32 bit pattern represents a signaling NaN.
-
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
-