public class Float16 extends Object
The format is laid out as follows:
1 11111 1111111111 ^ --^-- -----^---- sign | |_______ significand | -- exponentHalf-precision floating points can be useful to save memory and/or bandwidth at the expense of range and precision when compared to single-precision floating points (float32). Ref: https://android.googlesource.com/platform/libcore/+/master/luni/src/main/java/libcore/util/FP16.java
Modifier and Type | Field and Description |
---|---|
static short |
NaN |
static short |
POSITIVE_INFINITY |
Constructor and Description |
---|
Float16() |
Modifier and Type | Method and Description |
---|---|
static int |
compare(short x,
short y)
Compares the two specified half-precision float values.
|
static boolean |
isNaN(short h)
Returns true if the specified half-precision float value represents
a Not-a-Number, false otherwise.
|
static float |
toFloat(short b)
Converts the specified half-precision float value into a
single-precision float value.
|
static short |
toFloat16(float f)
Converts the specified single-precision float value into a
half-precision float value.
|
static String |
toFloatString(short h)
Returns a string representation of the specified half-precision
float value.
|
public static final short POSITIVE_INFINITY
public static final short NaN
public static boolean isNaN(short h)
h
- A half-precision float valuepublic static int compare(short x, short y)
Compares the two specified half-precision float values. The following conditions apply during the comparison:
#POSITIVE_INFINITY
)x
- The first half-precision float value to compare.y
- The second half-precision float value to compare0
if x
is numerically equal to y
, a
value less than 0
if x
is numerically less than y
,
and a value greater than 0
if x
is numerically greater
than y
public static float toFloat(short b)
b
- The half-precision float value to convert to single-precisionpublic static short toFloat16(float f)
f
- The single-precision float value to convert to half-precisionpublic static String toFloatString(short h)
Float.toString(toFloat(h))
. See Float.toString(float)
for more information on the format of the string representation.h
- A half-precision float value in binary little-endian formatCopyright © 2024 The Apache Software Foundation. All rights reserved.