Serializable, Comparable<Float16>public final class Float16 extends Number implements Comparable<Float16>
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.
java.lang.Double has a discussion of equality, equivalence, and comparison of floating-point values that is equally applicable to Float16 values. java.lang.Double is also applicable to Float16 values.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.| Modifier and Type | Field | Description |
|---|---|---|
static final int |
BYTES |
The number of bytes used to represent a Float16 value, 2. |
static final int |
MAX_EXPONENT |
Maximum exponent a finite Float16 variable may have, 15. |
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. |
static final int |
MIN_EXPONENT |
Minimum exponent a normalized Float16 variable may have, -14. |
static final Float16 |
MIN_NORMAL |
A constant holding the smallest positive normal value of type Float16, 2-14. |
static final Float16 |
MIN_VALUE |
A constant holding the smallest positive nonzero value of type Float16, 2-24. |
static final Float16 |
NaN |
A constant holding a Not-a-Number (NaN) value of type
Float16. |
static final Float16 |
NEGATIVE_INFINITY |
A constant holding the negative infinity of type
Float16. |
static final Float16 |
POSITIVE_INFINITY |
A constant holding the positive infinity of type
Float16. |
static final int |
PRECISION |
The number of bits in the significand of a Float16 value, 11. |
static final int |
SIZE |
The number of bits used to represent a Float16 value, 16. |
| Modifier and Type | Method | Description |
|---|---|---|
static Float16 |
abs |
Returns the absolute value of the argument. |
static Float16 |
add |
Adds two Float16 values together as per the + operator semantics using the round to nearest rounding policy. |
byte |
byteValue() |
Returns the value of this Float16 as a byte after a narrowing primitive conversion. |
static int |
compare |
Compares the two specified Float16 values. |
int |
compareTo |
Compares two Float16 objects numerically. |
static Float16 |
copySign |
Returns the first floating-point argument with the sign of the second floating-point argument. |
static Float16 |
divide |
Divides two Float16 values as per the / operator semantics using the round to nearest rounding policy. |
double |
doubleValue() |
Returns the value of this Float16 as a double after a widening primitive conversion. |
boolean |
equals |
Compares this object against the specified object. |
static short |
float16ToRawShortBits |
Returns a representation of the specified floating-point value according to the IEEE 754 floating-point binary16 bit layout. |
static short |
float16ToShortBits |
Returns a representation of the specified floating-point value according to the IEEE 754 floating-point binary16 bit layout. |
float |
floatValue() |
Returns the value of this Float16 as a float after a widening primitive conversion. |
static Float16 |
fma |
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. |
static int |
getExponent |
Returns the unbiased exponent used in the representation of a Float16. |
int |
hashCode() |
Returns a hash code for this Float16 object. |
static int |
hashCode |
Returns a hash code for a Float16 value; compatible with Float16.hashCode(). |
int |
intValue() |
Returns the value of this Float16 as an int after a narrowing primitive conversion. |
static boolean |
isFinite |
Returns true if the argument is a finite floating-point value; returns false otherwise (for NaN and infinity arguments). |
static boolean |
isInfinite |
Returns true if the specified number is infinitely large in magnitude, false otherwise. |
static boolean |
isNaN |
Returns true if the specified number is a Not-a-Number (NaN) value, false otherwise. |
long |
longValue() |
Returns value of this Float16 as a long after a narrowing primitive conversion. |
static Float16 |
max |
Returns the larger of two Float16 values. |
static Float16 |
min |
Returns the smaller of two Float16 values. |
static Float16 |
multiply |
Multiplies two Float16 values as per the * operator semantics using the round to nearest rounding policy. |
static Float16 |
negate |
Returns the negation of the argument. |
static Float16 |
nextDown |
Returns the floating-point value adjacent to v in the direction of negative infinity. |
static Float16 |
nextUp |
Returns the floating-point value adjacent to v in the direction of positive infinity. |
static Float16 |
scalb |
Returns v × 2scaleFactor rounded as if performed by a single correctly rounded floating-point multiply. |
static Float16 |
shortBitsToFloat16 |
Returns the Float16 value corresponding to a given bit representation. |
short |
shortValue() |
Returns the value of this Float16 as a short after a narrowing primitive conversion. |
static Float16 |
signum |
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. |
static Float16 |
sqrt |
Returns the square root of the operand. |
static Float16 |
subtract |
Subtracts two Float16 values as per the - operator semantics using the round to nearest rounding policy. |
static String |
toHexString |
Returns a hexadecimal string representation of the
Float16 argument. |
String |
toString() |
Returns a string representation of this Float16. |
static String |
toString |
Returns a string representation of the Float16 argument. |
static Float16 |
ulp |
Returns the size of an ulp of the argument. |
static Float16 |
valueOf |
Returns a Float16 value rounded from the double argument using the round to nearest rounding policy. |
static Float16 |
valueOf |
Returns a Float16 value rounded from the float argument using the round to nearest rounding policy. |
static Float16 |
valueOf |
Returns the value of an int converted to
Float16. |
static Float16 |
valueOf |
Returns the value of a long converted to Float16. |
static Float16 |
valueOf |
Returns a Float16 holding the floating-point value represented by the argument string. |
static Float16 |
valueOf |
Returns a Float16 value rounded from the BigDecimal argument using the round to nearest rounding policy. |
public static final Float16 POSITIVE_INFINITY
Float16.public static final Float16 NEGATIVE_INFINITY
Float16.public static final Float16 NaN
Float16.public static final Float16 MAX_VALUE
Float16, (2-2-10)·215, numerically equal to 65504.0.public static final Float16 MIN_NORMAL
Float16, 2-14.public static final Float16 MIN_VALUE
Float16, 2-24.public static final int SIZE
Float16 value, 16.public static final int PRECISION
Float16 value, 11. This corresponds to parameter N in section 4.2.3 of The Java Language Specification.public static final int MAX_EXPONENT
Float16 variable may have, 15. It is equal to the value returned by
Float16.getExponent(Float16.MAX_VALUE).public static final int MIN_EXPONENT
Float16 variable may have, -14. It is equal to the value returned by
Float16.getExponent(Float16.MIN_NORMAL).public static final int BYTES
Float16 value, 2.public static String toString(Float16 f16)
Float16 argument. The behavior of this method is analogous to Float.toString(float) in the handling of special values (signed zeros, infinities, and NaN) and the generation of a decimal string that will convert back to the argument value.f16 - the Float16 to be converted.public static String toHexString(Float16 f16)
Float16 argument. The behavior of this class is analogous to Float.toHexString(float) except that an exponent value of "p-14" is used for subnormal Float16 values.f16 - the Float16 to be converted.public static Float16 valueOf(int value)
int converted to
Float16.value - an int value.int converted to
Float16
public static Float16 valueOf(long value)
long converted to Float16.value - a long value.long converted to Float16
public static Float16 valueOf(float f)
Float16 value rounded from the float argument using the round to nearest rounding policy.f - a float
Float16 value rounded from the float argument using the round to nearest rounding policypublic static Float16 valueOf(double d)
Float16 value rounded from the double argument using the round to nearest rounding policy.d - a double
Float16 value rounded from the double argument using the round to nearest rounding policypublic static Float16 valueOf(String s) throws NumberFormatException
Float16 holding the floating-point value represented by the argument string. The grammar of strings accepted by this method is the same as that accepted by Double.valueOf(String). The rounding policy is also analogous to the one used by that method, a valid input is regarded as an exact numerical value that is rounded once to the nearest representable Float16 value.s - the string to be parsed.Float16 value represented by the string argument.NullPointerException - if the string is nullNumberFormatException - if the string does not contain a parsable Float16.public static Float16 valueOf(BigDecimal v)
Float16 value rounded from the BigDecimal argument using the round to nearest rounding policy.v - a BigDecimal
Float16 value rounded from the BigDecimal argument using the round to nearest rounding policypublic static boolean isNaN(Float16 f16)
true if the specified number is a Not-a-Number (NaN) value, false otherwise.f16 - the value to be tested.true if the argument is NaN; false otherwise.public static boolean isInfinite(Float16 f16)
true if the specified number is infinitely large in magnitude, false otherwise.f16 - the value to be tested.true if the argument is positive infinity or negative infinity; false otherwise.public static boolean isFinite(Float16 f16)
true if the argument is a finite floating-point value; returns false otherwise (for NaN and infinity arguments).f16 - the Float16 value to be testedtrue if the argument is a finite floating-point value, false otherwise.public byte byteValue()
Float16 as a byte after a narrowing primitive conversion.byteValue in class Number
Float16 as a byte after a narrowing primitive conversionpublic short shortValue()
Float16 as a short after a narrowing primitive conversion.shortValue in class Number
Float16 as a short after a narrowing primitive conversionpublic int intValue()
Float16 as an int after a narrowing primitive conversion.intValue in class Number
Float16 as an int after a narrowing primitive conversionpublic long longValue()
Float16 as a long after a narrowing primitive conversion.longValue in class Number
Float16 as a long after a narrowing primitive conversionpublic float floatValue()
Float16 as a float after a widening primitive conversion.floatValue in class Number
Float16 as a float after a widening primitive conversionpublic double doubleValue()
Float16 as a double after a widening primitive conversion.doubleValue in class Number
Float16 as a double after a widening primitive conversionpublic int hashCode()
Float16 object. The general contract of Object#hashCode() is satisfied. All NaN values have the same hash code. Additionally, all distinct numerical values have unique hash codes; in particular, negative zero and positive zero have different hash codes from each other.public static int hashCode(Float16 value)
Float16 value; compatible with Float16.hashCode().value - the value to hashFloat16 value.public boolean equals(Object obj)
true if and only if the argument is not null and is a Float16 object that represents a Float16 that has the same value as the double represented by this object.equals in class Object
obj - the reference object with which to compare.true if this object is the same as the obj argument; false otherwise.public static short float16ToRawShortBits(Float16 f16)
f16 - a Float16 floating-point number.public static short float16ToShortBits(Float16 f16)
NaN.f16 - a Float16 floating-point number.public static Float16 shortBitsToFloat16(short bits)
Float16 value corresponding to a given bit representation.bits - any short integer.Float16 floating-point value with the same bit pattern.public int compareTo(Float16 anotherFloat16)
Float16 objects numerically. This method imposes a total order on Float16 objects with two differences compared to the incomplete order defined by the Java language numerical comparison operators (<, <=,
==, >=, >) on float and double values.
Float16.NaN to be equal to itself and greater than all other Float16 values (including
Float16.POSITIVE_INFINITY). compareTo in interface Comparable<Float16>
anotherFloat16 - the Float16 to be compared.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.<, <=, >, and >=public static int compare(Float16 f1, Float16 f2)
Float16 values.f1 - the first Float16 to comparef2 - the second Float16 to compare0 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.public static Float16 max(Float16 a, Float16 b)
Float16 values. The handling of signed zeros, NaNs, infinities, and other special cases by this method is analogous to the handling of those cases by the Math#max(double, double) method.a - the first operandb - the second operanda and b
public static Float16 min(Float16 a, Float16 b)
Float16 values. The handling of signed zeros, NaNs, infinities, and other special cases by this method is analogous to the handling of those cases by the Math#min(double, double) method.a - the first operandb - the second operanda and b
public static Float16 add(Float16 addend, Float16 augend)
Float16 values together as per the + operator semantics using the round to nearest rounding policy. The handling of signed zeros, NaNs, infinities, and other special cases by this method is the same as for the handling of those cases by the built-in + operator for floating-point addition (JLS 15.18.2).addend - the first operandaugend - the second operandpublic static Float16 subtract(Float16 minuend, Float16 subtrahend)
Float16 values as per the - operator semantics using the round to nearest rounding policy. The handling of signed zeros, NaNs, infinities, and other special cases by this method is the same as for the handling of those cases by the built-in - operator for floating-point subtraction (JLS 15.18.2).minuend - the first operandsubtrahend - the second operandpublic static Float16 multiply(Float16 multiplier, Float16 multiplicand)
Float16 values as per the * operator semantics using the round to nearest rounding policy. The handling of signed zeros, NaNs, and infinities, other special cases by this method is the same as for the handling of those cases by the built-in * operator for floating-point multiplication (JLS 15.17.1).multiplier - the first operandmultiplicand - the second operandpublic static Float16 divide(Float16 dividend, Float16 divisor)
Float16 values as per the / operator semantics using the round to nearest rounding policy. The handling of signed zeros, NaNs, and infinities, other special cases by this method is the same as for the handling of those cases by the built-in / operator for floating-point division (JLS 15.17.2).dividend - the first operanddivisor - the second operandpublic static Float16 sqrt(Float16 radicand)
Math.sqrt(double).radicand - the argument to have its square root takenpublic static Float16 fma(Float16 a, Float16 b, Float16 c)
Float16. The handling of zeros, NaN, infinities, and other special cases by this method is analogous to the handling of those cases by Math.fma(float, float, float).a - a valueb - a valuec - a valueFloat16 valuepublic static Float16 negate(Float16 f16)
f16 - the value to be negated-public static Float16 abs(Float16 f16)
Math.abs(float).f16 - the argument whose absolute value is to be determinedpublic static int getExponent(Float16 f16)
Float16. MAX_EXPONENT + 1. MIN_EXPONENT - 1. f16 - a Float16 valuepublic static Float16 ulp(Float16 f16)
Float16 value is the positive distance between this floating-point value and the
Float16 value next larger in magnitude. Note that for non-NaN x, ulp(-x) == ulp(x). Special Cases:
Float16.MIN_VALUE. Float16.MAX_VALUE, then the result is equal to 25, 32.0. f16 - the floating-point value whose ulp is to be returnedpublic static Float16 nextUp(Float16 v)
v in the direction of positive infinity. Special Cases:
MIN_VALUE v - starting floating-point valuepublic static Float16 nextDown(Float16 v)
v in the direction of negative infinity. Special Cases:
MIN_VALUE v - starting floating-point valuepublic static Float16 scalb(Float16 v, int scaleFactor)
v × 2scaleFactor rounded as if performed by a single correctly rounded floating-point multiply. If the exponent of the result is between MIN_EXPONENT and MAX_EXPONENT, the answer is calculated exactly. If the exponent of the result would be larger than
Float16.MAX_EXPONENT, an infinity is returned. Note that if the result is subnormal, precision may be lost; that is, when scalb(x, n) is subnormal, scalb(scalb(x, n),
-n) may not equal x. When the result is non-NaN, the result has the same sign as v. Special cases:
v - number to be scaled by a power of two.scaleFactor - power of 2 used to scale v
v × 2scaleFactor
public static Float16 copySign(Float16 magnitude, Float16 sign)
sign arguments to be treated as positive values; implementations are permitted to treat some NaN arguments as positive and other NaN arguments as negative to allow greater performance.magnitude - the parameter providing the magnitude of the resultsign - the parameter providing the sign of the resultmagnitude and the sign of sign.public static Float16 signum(Float16 f)
Special Cases:
f - the floating-point value whose signum is to be returned
© 1993, 2025, Oracle and/or its affiliates. All rights reserved.
Documentation extracted from Debian's OpenJDK Development Kit package.
Licensed under the GNU General Public License, version 2, with the Classpath Exception.
Various third party code in OpenJDK is licensed under different licenses (see Debian package).
Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
https://docs.oracle.com/en/java/javase/25/docs/api/jdk.incubator.vector/jdk/incubator/vector/Float16.html