public final class Binary16 extends Object
Functions to convert values to/from the binary16 format
specified in IEEE 754 2008.
| Modifier and Type | Field and Description |
|---|---|
static int |
BIAS
The bias value used to offset the encoded exponent.
|
static char |
NEGATIVE_INFINITY
The encoded form of negative infinity
-∞. |
static char |
NEGATIVE_ZERO
The encoded form of negative zero
-0. |
static char |
POSITIVE_INFINITY
The encoded form of positive infinity
∞. |
static char |
POSITIVE_ZERO
The encoded form of positive zero
0. |
| Modifier and Type | Method and Description |
|---|---|
static char |
exampleNaN() |
static boolean |
isInfinite(char k) |
static boolean |
isNaN(char k) |
static char |
packDouble(double k)
Convert a double precision floating point value to a packed
binary16 value. |
static char |
packFloat(float k)
Convert a single precision floating point value to a packed
binary16 value. |
static char |
packSetExponentUnbiasedUnchecked(int e)
Encode the unbiased exponent
e. |
static char |
packSetSignificandUnchecked(int s)
Encode the significand
s. |
static char |
packSetSignUnchecked(int s)
Encode the sign bit
s. |
static String |
toRawBinaryString(char k)
Show the given raw packed
binary16 value as a string of
binary digits. |
static double |
unpackDouble(char k)
Convert a packed
binary16 value k to a
double-precision floating point value. |
static float |
unpackFloat(char k)
Convert a packed
binary16 value k to a
single-precision floating point value. |
static int |
unpackGetExponentUnbiased(char k)
Extract and unbias the exponent of the given packed
binary16
value. |
static int |
unpackGetSign(char k)
Retrieve the sign bit of the given packed
binary16 value, as
an integer in the range [0, 1]. |
static int |
unpackGetSignificand(char k)
Return the significand of the given packed
binary16 value as
an integer in the range [0, 1023]. |
public static final char NEGATIVE_INFINITY
-∞.public static final char POSITIVE_INFINITY
∞.public static final char POSITIVE_ZERO
0.public static final char NEGATIVE_ZERO
-0.public static final int BIAS
e is encoded as BIAS + e.public static char exampleNaN()
public static boolean isInfinite(char k)
k - A packed binary16 valuetrue if the given packed binary16 value is
infinite.public static boolean isNaN(char k)
k - A packed binary16 valuetrue if the given packed binary16 value is not a
number (NaN).public static char packDouble(double k)
Convert a double precision floating point value to a packed
binary16 value.
For the following specific cases, the function returns:
NaN iff isNaN(k)POSITIVE_INFINITY iff
k == Double.POSITIVE_INFINITYNEGATIVE_INFINITY iff
k == Double.NEGATIVE_INFINITYNEGATIVE_ZERO iff k == -0.0POSITIVE_ZERO iff k == 0.0
Otherwise, the binary16 value that most closely represents
k is returned. This may obviously be an infinite value as
the interval of double precision values is far larger than that of the
binary16 type.
k - A floating point valuebinary16 valueunpackDouble(char)public static double unpackDouble(char k)
Convert a packed binary16 value k to a
double-precision floating point value.
The function returns:
NaN iff isNaN(k)Double.POSITIVE_INFINITY iff
k == POSITIVE_INFINITYDouble.NEGATIVE_INFINITY iff
k == NEGATIVE_INFINITY-0.0 iff k == NEGATIVE_ZERO0.0 iff k == POSITIVE_ZERO(-1.0 * n) * (2 ^ e) * 1.s, for the decoded sign
n of k, the decoded exponent e of
k, and the decoded significand s of
k.k - A packed binary16 valuepackDouble(double)public static float unpackFloat(char k)
Convert a packed binary16 value k to a
single-precision floating point value.
The function returns:
NaN iff isNaN(k)Double.POSITIVE_INFINITY iff
k == POSITIVE_INFINITYDouble.NEGATIVE_INFINITY iff
k == NEGATIVE_INFINITY-0.0 iff k == NEGATIVE_ZERO0.0 iff k == POSITIVE_ZERO(-1.0 * n) * (2 ^ e) * 1.s, for the decoded sign
n of k, the decoded exponent e of
k, and the decoded significand s of
k.k - A packed binary16 valuepackDouble(double)public static char packFloat(float k)
Convert a single precision floating point value to a packed
binary16 value.
For the following specific cases, the function returns:
NaN iff isNaN(k)POSITIVE_INFINITY iff
k == Float.POSITIVE_INFINITYNEGATIVE_INFINITY iff
k == Float.NEGATIVE_INFINITYNEGATIVE_ZERO iff k == -0.0POSITIVE_ZERO iff k == 0.0
Otherwise, the binary16 value that most closely represents
k is returned. This may obviously be an infinite value as
the interval of single precision values is far larger than that of the
binary16 type.
k - A floating point valuebinary16 valueunpackFloat(char)public static char packSetExponentUnbiasedUnchecked(int e)
Encode the unbiased exponent e. Values should be in the
range [-15, 16] - values outside of this range will be
truncated.
e - An exponentunpackGetExponentUnbiased(char)public static char packSetSignificandUnchecked(int s)
Encode the significand s. Values should be in the range
[0, 1023]. Values outside of this range will be truncated.
s - A significandunpackGetSignificand(char)public static char packSetSignUnchecked(int s)
Encode the sign bit s. Values should be in the range
[0, 1], with 0 ironically denoting a positive
value. Values outside of this range will be truncated.
s - A sign bitunpackGetSign(char)public static String toRawBinaryString(char k)
binary16 value as a string of
binary digits.k - A packed binary16 valuepublic static int unpackGetExponentUnbiased(char k)
Extract and unbias the exponent of the given packed binary16
value.
The exponent is encoded biased as a number in the range
[0, 31], with 0 indicating that the number is
subnormal and [1, 30] denoting the actual exponent
plus BIAS. Infinite and NaN values always have an
exponent of 31.
This function will therefore return:
0 - BIAS = -15 iff the input is a subnormal
number.[1 - BIAS, 30 - BIAS] = [-14, 15] iff the
input is a normal number.16 iff the input is POSITIVE_INFINITY,
NEGATIVE_INFINITY, or NaN.k - A packed binary16 valuepackSetExponentUnbiasedUnchecked(int)public static int unpackGetSign(char k)
binary16 value, as
an integer in the range [0, 1].k - A packed binary16 valuepackSetSignUnchecked(int)public static int unpackGetSignificand(char k)
Return the significand of the given packed binary16 value as
an integer in the range [0, 1023].
k - A packed binary16 valuepackSetSignificandUnchecked(int)Copyright © 2017 <code@io7m.com> http://io7m.com