APIdia Launch Partner
Top Description Inners Fields Constructors Methods
jdk.incubator.vector

public final Class Float16

extends Number
implements Comparable<Float16>
Class Inheritance
All Implemented Interfaces
java.lang.Comparable
Annotations
@ValueBased
Imports
java.io.IOException, java.math.BigDecimal, .BigInteger, jdk.internal.vm.annotation.ForceInline, jdk.internal.vm.vector.Float16Math

The Float16 is a class holding 16-bit data in IEEE 754 binary16 format.

Binary16 Format:
S EEEEE MMMMMMMMMM
Sign - 1 bit
Exponent - 5 bits
Significand - 10 bits (does not include the implicit bit inferred from the exponent, see PRECISION)

Unless otherwise specified, the methods in this class use a rounding policy (JLS 15.4) of round to nearest.

This is a value-based class; programmers should treat instances that are equal as interchangeable and should not use instances for synchronization, or unpredictable behavior may occur. For example, in a future release, synchronization may fail.

Floating-point Equality, Equivalence, and Comparison

The class java.lang.Double has a discussion of equality, equivalence, and comparison of floating-point values that is equally applicable to Float16 values.

Decimal ↔ Binary Conversion Issues

The discussion of binary to decimal conversion issues in java.lang.Double is also applicable to Float16 values.

API Note

The methods in this class generally have analogous methods in either Float/Double or Math/StrictMath. Unless otherwise specified, the handling of special floating-point values such as NaN values, infinities, and signed zeros of methods in this class is wholly analogous to the handling of equivalent cases by methods in Float, Double, Math, etc.

Since
24
See Also
IEEE Standard for Floating-Point Arithmetic

Nested and Inner Type Summary

Modifier and TypeClass and Description
private class
private static class
private static class
Float16.MathUtils

This class exposes package private utilities for other classes.

Field Summary

Modifier and TypeField and Description
public static final int
BYTES

The number of bytes used to represent a Float16 value, .

public static final int
MAX_EXPONENT

Maximum exponent a finite Float16 variable may have, .

public static final Float16
MAX_VALUE

A constant holding the largest positive finite value of type Float16, (2-2-10)·215, numerically equal to 65504.0.

public static final int
MIN_EXPONENT

Minimum exponent a normalized Float16 variable may have, .

public static final Float16
MIN_NORMAL

A constant holding the smallest positive normal value of type Float16, 2-14.

public static final Float16
MIN_VALUE

A constant holding the smallest positive nonzero value of type Float16, 2-24.

public static final Float16
NaN

A constant holding a Not-a-Number (NaN) value of type Float16.

public static final Float16
NEGATIVE_INFINITY

A constant holding the negative infinity of type Float16.

private static final Float16
ONE

A constant holding a one (1.0) of type Float16.

private static final double
OVERFLOW_THRESH

The overflow threshold (for round to nearest) is MAX_VALUE + 1/2 ulp.

public static final Float16
POSITIVE_INFINITY

A constant holding the positive infinity of type Float16.

public static final int
PRECISION

The number of bits in the significand of a Float16 value, .

private static final long
public static final int
SIZE

The number of bits used to represent a Float16 value, .

private static final double
UNDERFLOW_THRESH

The underflow threshold (for round to nearest) is MIN_VALUE * 0.5.

private final short
value

Primitive short field to hold the bits of the Float16.

private static final Float16
ZERO

A constant holding a zero (0.0) of type Float16.

Constructor Summary

AccessConstructor and Description
private
Float16(short
a short value.
bits
)

Returns a Float16 instance wrapping IEEE 754 binary16 encoded short value.

Method Summary

Modifier and TypeMethod and Description
public static Float16

Returns:

the absolute value of the argument
abs
(Float16
the argument whose absolute value is to be determined
f16
)

Returns the absolute value of the argument.

public static Float16

Returns:

the sum of the operands
add
(Float16
the first operand
addend
,
Float16
the second operand
augend
)

Adds two Float16 values together as per the + operator semantics using the round to nearest rounding policy.

public byte

Returns:

the value of this Float16 as a byte after a narrowing primitive conversion
byteValue
()

Overrides java.lang.Number.byteValue.

Returns the value of this Float16 as a byte after a narrowing primitive conversion.

public static int

Returns:

the value 0 if f1 is numerically equal to f2; a value less than 0 if f1 is numerically less than f2; and a value greater than 0 if f1 is numerically greater than f2.
compare
(Float16
the first Float16 to compare
f1
,
Float16
the second Float16 to compare
f2
)

Compares the two specified Float16 values.

public int

Returns:

the value 0 if anotherFloat16 is numerically equal to this Float16; a value less than 0 if this Float16 is numerically less than anotherFloat16; and a value greater than 0 if this Float16 is numerically greater than anotherFloat16.
compareTo
(Float16
the Float16 to be compared.
anotherFloat16
)

Implements java.lang.Comparable.compareTo.

Compares two Float16 objects numerically.

public static Float16

Returns:

a value with the magnitude of magnitude and the sign of sign.
copySign
(Float16
the parameter providing the magnitude of the result
magnitude
,
Float16
the parameter providing the sign of the result
sign
)

Returns the first floating-point argument with the sign of the second floating-point argument.

public static Float16

Returns:

the quotient of the operands
divide
(Float16
the first operand
dividend
,
Float16
the second operand
divisor
)

Divides two Float16 values as per the / operator semantics using the round to nearest rounding policy.

public double

Returns:

the value of this Float16 as a double after a widening primitive conversion
doubleValue
()

Implements abstract java.lang.Number.doubleValue.

Returns the value of this Float16 as a double after a widening primitive conversion.

public boolean
equals(Object obj)

Overrides java.lang.Object.equals.

Compares this object against the specified object.

private static int
public static short

Returns:

the bits that represent the floating-point number.
float16ToRawShortBits
(Float16
a Float16 floating-point number.
f16
)

Returns a representation of the specified floating-point value according to the IEEE 754 floating-point binary16 bit layout.

public static short

Returns:

the bits that represent the floating-point number.
float16ToShortBits
(Float16
a Float16 floating-point number.
f16
)

Returns a representation of the specified floating-point value according to the IEEE 754 floating-point binary16 bit layout.

public float

Returns:

the value of this Float16 as a float after a widening primitive conversion
floatValue
()

Implements abstract java.lang.Number.floatValue.

Returns the value of this Float16 as a float after a widening primitive conversion.

public static Float16

Returns:

(a × b + c) computed, as if with unlimited range and precision, and rounded once to the nearest Float16 value
fma
(Float16
a value
a
,
Float16
a value
b
,
Float16
a value
c
)

Returns the fused multiply add of the three arguments; that is, returns the exact product of the first two arguments summed with the third argument and then rounded once to the nearest Float16.

public static int

Returns:

the unbiased exponent of the argument
getExponent
(Float16
a Float16 value
f16
)

Returns the unbiased exponent used in the representation of a Float16.

pack-priv static int
getExponent0(short bits)

From the bitwise representation of a float16, mask out exponent bits, shift to the right and then subtract out float16's bias adjust, 15, to get true exponent value.

public int

Returns:

a hash code for this Float16 object
hashCode
()

Overrides java.lang.Object.hashCode.

Returns a hash code for this Float16 object.

public static int

Returns:

a hash code value for a Float16 value.
hashCode
(Float16
the value to hash
value
)

Returns a hash code for a Float16 value; compatible with Float16.hashCode().

public int

Returns:

the value of this Float16 as an int after a narrowing primitive conversion
intValue
()

Implements abstract java.lang.Number.intValue.

Returns the value of this Float16 as an int after a narrowing primitive conversion.

public static boolean

Returns:

true if the argument is a finite floating-point value, false otherwise.
isFinite
(Float16
the Float16 value to be tested
f16
)

Returns true if the argument is a finite floating-point value; returns false otherwise (for NaN and infinity arguments).

public static boolean

Returns:

true if the argument is positive infinity or negative infinity; false otherwise.
isInfinite
(Float16
the value to be tested.
f16
)

Returns true if the specified number is infinitely large in magnitude, false otherwise.

public static boolean

Returns:

true if the argument is NaN; false otherwise.
isNaN
(Float16
the value to be tested.
f16
)

Returns true if the specified number is a Not-a-Number (NaN) value, false otherwise.

private static boolean
isX(int character)

public long

Returns:

value of this Float16 as a long after a narrowing primitive conversion
longValue
()

Implements abstract java.lang.Number.longValue.

Returns value of this Float16 as a long after a narrowing primitive conversion.

public static Float16

Returns:

the greater of a and b
max
(Float16
the first operand
a
,
Float16
the second operand
b
)

Returns the larger of two Float16 values.

public static Float16

Returns:

the smaller of a and b
min
(Float16
the first operand
a
,
Float16
the second operand
b
)

Returns the smaller of two Float16 values.

public static Float16

Returns:

the product of the operands
multiply
(Float16
the first operand
multiplier
,
Float16
the second operand
multiplicand
)

Multiplies two Float16 values as per the * operator semantics using the round to nearest rounding policy.

public static Float16

Returns:

the negation of the argument
negate
(Float16
the value to be negated
f16
)

Returns the negation of the argument.

public static Float16

Returns:

The adjacent floating-point value closer to negative infinity.
nextDown
(Float16
starting floating-point value
v
)

Returns the floating-point value adjacent to v in the direction of negative infinity.

public static Float16

Returns:

The adjacent floating-point value closer to positive infinity.
nextUp
(Float16
starting floating-point value
v
)

Returns the floating-point value adjacent to v in the direction of positive infinity.

private static boolean
public static Float16

Returns:

v × 2scaleFactor
scalb
(Float16
number to be scaled by a power of two.
v
,
int
power of 2 used to scale v
scaleFactor
)

Returns v × 2scaleFactor rounded as if performed by a single correctly rounded floating-point multiply.

public static Float16

Returns:

the Float16 floating-point value with the same bit pattern.
shortBitsToFloat16
(short
any short integer.
bits
)

Returns the Float16 value corresponding to a given bit representation.

public short

Returns:

the value of this Float16 as a short after a narrowing primitive conversion
shortValue
()

Overrides java.lang.Number.shortValue.

Returns the value of this Float16 as a short after a narrowing primitive conversion.

public static Float16

Returns:

the signum function of the argument
signum
(Float16
the floating-point value whose signum is to be returned
f
)

Returns the signum function of the argument; zero if the argument is zero, 1.0 if the argument is greater than zero, -1.0 if the argument is less than zero.

public static Float16

Returns:

the square root of the operand
sqrt
(Float16
the argument to have its square root taken
radicand
)

Returns the square root of the operand.

public static Float16

Returns:

the difference of the operands
subtract
(Float16
the first operand
minuend
,
Float16
the second operand
subtrahend
)

Subtracts two Float16 values as per the - operator semantics using the round to nearest rounding policy.

public static String

Returns:

a hex string representation of the argument.
toHexString
(Float16
the Float16 to be converted.
f16
)

Returns a hexadecimal string representation of the Float16 argument.

public static String

Returns:

a string representation of the argument.
toString
(Float16
the Float16 to be converted.
f16
)

Returns a string representation of the Float16 argument.

public String

Returns:

a string representation of this Float16
toString
()

Overrides java.lang.Object.toString.

Returns a string representation of this Float16.

public static Float16

Returns:

the size of an ulp of the argument
ulp
(Float16
the floating-point value whose ulp is to be returned
f16
)

Returns the size of an ulp of the argument.

public static Float16

Returns:

the value of an int converted to Float16
valueOf
(int
an int value.
value
)

Returns the value of an int converted to Float16.

public static Float16

Returns:

the value of a long converted to Float16
valueOf
(long
a long value.
value
)

Returns the value of a long converted to Float16.

public static Float16

Returns:

a Float16 value rounded from the float argument using the round to nearest rounding policy
valueOf
(float
a float
f
)

Returns a Float16 value rounded from the float argument using the round to nearest rounding policy.

public static Float16

Returns:

a Float16 value rounded from the double argument using the round to nearest rounding policy
valueOf
(double
a double
d
)

Returns a Float16 value rounded from the double argument using the round to nearest rounding policy.

public static Float16

Returns:

the Float16 value represented by the string argument.
valueOf
(String
the string to be parsed.
s
)

Returns a Float16 holding the floating-point value represented by the argument string.

public static Float16

Returns:

a Float16 value rounded from the BigDecimal argument using the round to nearest rounding policy
valueOf
(BigDecimal v)

Returns a Float16 value rounded from the BigDecimal argument using the round to nearest rounding policy.