Class Float16


  • public class Float16
    extends Object
    The class is a utility class to manipulate half-precision 16-bit IEEE 754 floating point data types (also called fp16 or binary16). A half-precision float can be created from or converted to single-precision floats, and is stored in a short data type. The IEEE 754 standard specifies an float16 as having the following format:
    • Sign bit: 1 bit
    • Exponent width: 5 bits
    • Significand: 10 bits

    The format is laid out as follows:

     1   11111   1111111111
     ^   --^--   -----^----
     sign  |          |_______ significand
           |
          -- exponent
     
    Half-precision floating points can be useful to save memory and/or bandwidth at the expense of range and precision when compared to single-precision floating points (float32). Ref: https://android.googlesource.com/platform/libcore/+/master/luni/src/main/java/libcore/util/FP16.java
    • Constructor Detail

      • Float16

        public Float16()
    • Method Detail

      • isNaN

        public static boolean isNaN​(short h)
        Returns true if the specified half-precision float value represents a Not-a-Number, false otherwise.
        Parameters:
        h - A half-precision float value
        Returns:
        True if the value is a NaN, false otherwise
      • compare

        public static int compare​(short x,
                                  short y)

        Compares the two specified half-precision float values. The following conditions apply during the comparison:

        • NaN is considered by this method to be equal to itself and greater than all other half-precision float values (including #POSITIVE_INFINITY)
        • POSITIVE_ZERO is considered by this method to be greater than NEGATIVE_ZERO.
        Parameters:
        x - The first half-precision float value to compare.
        y - The second half-precision float value to compare
        Returns:
        The value 0 if x is numerically equal to y, a value less than 0 if x is numerically less than y, and a value greater than 0 if x is numerically greater than y