Class Half

  • All Implemented Interfaces:
    java.io.Serializable, java.lang.Comparable<Half>

    public final class Half
    extends java.lang.Number
    implements java.lang.Comparable<Half>
    IEEE 754 half-precision floating point data type.
    Version:
    $Id: Half.java,v 1.0 10/04/2021 haraldk Exp$
    Author:
    Harald Kuhr, last modified by $Author: haraldk$
    See Also:
    Stack Overflow answer by x4u, Wikipedia, Serialized Form
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static int SIZE  
    • Constructor Summary

      Constructors 
      Constructor Description
      Half​(short shortBits)  
    • Constructor Detail

      • Half

        public Half​(short shortBits)
    • Method Detail

      • intValue

        public int intValue()
        Specified by:
        intValue in class java.lang.Number
      • longValue

        public long longValue()
        Specified by:
        longValue in class java.lang.Number
      • floatValue

        public float floatValue()
        Specified by:
        floatValue in class java.lang.Number
      • doubleValue

        public double doubleValue()
        Specified by:
        doubleValue in class java.lang.Number
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object
      • equals

        public boolean equals​(java.lang.Object other)
        Overrides:
        equals in class java.lang.Object
      • compareTo

        public int compareTo​(Half other)
        Specified by:
        compareTo in interface java.lang.Comparable<Half>
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • valueOf

        public static Half valueOf​(java.lang.String value)
                            throws java.lang.NumberFormatException
        Throws:
        java.lang.NumberFormatException
      • parseHalf

        public static short parseHalf​(java.lang.String value)
                               throws java.lang.NumberFormatException
        Throws:
        java.lang.NumberFormatException
      • shortBitsToFloat

        public static float shortBitsToFloat​(short shortBits)
        Converts an IEEE 754 half-precision data type to single-precision.
        Parameters:
        shortBits - a 16 bit half precision value
        Returns:
        an IEE 754 single precision float
      • floatToShortBits

        public static short floatToShortBits​(float floatValue)
        Converts a float value to IEEE 754 half-precision bits.
        Parameters:
        floatValue - a float value
        Returns:
        the IEE 754 single precision 16 bits value