Module tornado.api

Class HalfFloat

java.lang.Object
uk.ac.manchester.tornado.api.types.HalfFloat

public class HalfFloat extends Object
This class represents a float-16 instance (half float). The data is stored in a short field, to be compliant with the representation for float-16 used in the Float class. The class encapsulates methods for getting the data in float-16 and float-32 format, and for basic arithmetic operations (i.e. addition, subtraction, multiplication and division).
  • Constructor Summary

    Constructors
    Constructor
    Description
    HalfFloat(float halfFloat)
    Constructs a new instance of the HalfFloat out of a float value.
    HalfFloat(short halfFloat)
    Constructs a new instance of the HalfFloat with a given short value.
  • Method Summary

    Modifier and Type
    Method
    Description
    static HalfFloat
    Takes two HalfFloat objects and returns a new instance that contains the results of the addition.
    static HalfFloat
    Takes two HalfFloat objects and returns a new instance that contains the results of the division.
    float
    Gets the half-float stored in the class in a 32-bit representation.
    short
    Gets the half-float stored in the class.
    static HalfFloat
    Takes two HalfFloat objects and returns a new instance that contains the results of the multiplication.
    static HalfFloat
    Takes two HalfFloat objects and returns a new instance that contains the results of the subtraction.
     

    Methods inherited from class java.lang.Object

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

    • HalfFloat

      public HalfFloat(float halfFloat)
      Constructs a new instance of the HalfFloat out of a float value. To convert the float to a float-16, the floatToFloat16 function of the Float class is used.
      Parameters:
      halfFloat - The float value that will be stored in a half-float format.
    • HalfFloat

      public HalfFloat(short halfFloat)
      Constructs a new instance of the HalfFloat with a given short value.
      Parameters:
      halfFloat - The short value that represents the half float.
  • Method Details

    • add

      public static HalfFloat add(HalfFloat a, HalfFloat b)
      Takes two HalfFloat objects and returns a new instance that contains the results of the addition.
      Parameters:
      a - The first HalfFloat input for the addition.
      b - The second HalfFloat input for the addition.
      Returns:
      A new containing the results of the addition.
    • sub

      public static HalfFloat sub(HalfFloat a, HalfFloat b)
      Takes two HalfFloat objects and returns a new instance that contains the results of the subtraction.
      Parameters:
      a - The first HalfFloat input for the subtraction.
      b - The second HalfFloat input for the subtraction.
      Returns:
      A new containing the results of the subtraction.
    • mult

      public static HalfFloat mult(HalfFloat a, HalfFloat b)
      Takes two HalfFloat objects and returns a new instance that contains the results of the multiplication.
      Parameters:
      a - The first HalfFloat input for the multiplication.
      b - The second HalfFloat input for the multiplication.
      Returns:
      A new containing the results of the multiplication.
    • div

      public static HalfFloat div(HalfFloat a, HalfFloat b)
      Takes two HalfFloat objects and returns a new instance that contains the results of the division.
      Parameters:
      a - The first HalfFloat input for the division.
      b - The second HalfFloat input for the division.
      Returns:
      A new containing the results of the division.
    • getHalfFloatValue

      public short getHalfFloatValue()
      Gets the half-float stored in the class.
      Returns:
      The half float value stored in the HalfFloat object.
    • getFloat32

      public float getFloat32()
      Gets the half-float stored in the class in a 32-bit representation.
      Returns:
      The float-32 equivalent value the half float stored in the HalfFloat object.
    • toString

      public String toString()
      Overrides:
      toString in class Object