java.lang.Object
uk.ac.manchester.tornado.api.types.HalfFloat
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 -
Method Summary
Modifier and TypeMethodDescriptionstatic HalfFloatTakes twoHalfFloatobjects and returns a new instance that contains the results of the addition.static HalfFloatTakes twoHalfFloatobjects and returns a new instance that contains the results of the division.floatGets the half-float stored in the class in a 32-bit representation.shortGets the half-float stored in the class.static HalfFloatTakes twoHalfFloatobjects and returns a new instance that contains the results of the multiplication.static HalfFloatTakes twoHalfFloatobjects and returns a new instance that contains the results of the subtraction.toString()
-
Constructor Details
-
HalfFloat
public HalfFloat(float halfFloat) Constructs a new instance of theHalfFloatout of a float value. To convert the float to a float-16, the floatToFloat16 function of theFloatclass 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 theHalfFloatwith a given short value.- Parameters:
halfFloat- The short value that represents the half float.
-
-
Method Details
-
add
Takes twoHalfFloatobjects and returns a new instance that contains the results of the addition.- Parameters:
a- The firstHalfFloatinput for the addition.b- The secondHalfFloatinput for the addition.- Returns:
- A new containing the results of the addition.
-
sub
Takes twoHalfFloatobjects and returns a new instance that contains the results of the subtraction.- Parameters:
a- The firstHalfFloatinput for the subtraction.b- The secondHalfFloatinput for the subtraction.- Returns:
- A new containing the results of the subtraction.
-
mult
Takes twoHalfFloatobjects and returns a new instance that contains the results of the multiplication.- Parameters:
a- The firstHalfFloatinput for the multiplication.b- The secondHalfFloatinput for the multiplication.- Returns:
- A new containing the results of the multiplication.
-
div
Takes twoHalfFloatobjects and returns a new instance that contains the results of the division.- Parameters:
a- The firstHalfFloatinput for the division.b- The secondHalfFloatinput 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
HalfFloatobject.
-
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
HalfFloatobject.
-
toString
-