Class Binary16
Functions to convert values to/from the binary16 format
specified in IEEE 754 2008.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intThe bias value used to offset the encoded exponent.static final charThe encoded form of negative infinity-∞.static final charThe encoded form of negative zero-0.static final charThe encoded form of positive infinity∞.static final charThe encoded form of positive zero0. -
Method Summary
Modifier and TypeMethodDescriptionstatic charOne possible not-a-number value.static booleanisInfinite(char k) Returntrueif the given packedbinary16value is infinite.static booleanisNaN(char k) Returntrueif the given packedbinary16value is not a number (NaN).static charpackDouble(double k) Convert a double precision floating point value to a packedbinary16value.static charpackFloat(float k) Convert a single precision floating point value to a packedbinary16value.static charEncode the unbiased exponente.static charpackSetSignificandUnchecked(int s) Encode the significands.static charpackSetSignUnchecked(int s) Encode the sign bits.static StringtoRawBinaryString(char k) Show the given raw packedbinary16value as a string of binary digits.static doubleunpackDouble(char k) Convert a packedbinary16valuekto a double-precision floating point value.static floatunpackFloat(char k) Convert a packedbinary16valuekto a single-precision floating point value.static intunpackGetExponentUnbiased(char k) Extract and unbias the exponent of the given packedbinary16value.static intunpackGetSign(char k) Retrieve the sign bit of the given packedbinary16value, as an integer in the range[0, 1].static intunpackGetSignificand(char k) Return the significand of the given packedbinary16value as an integer in the range[0, 1023].
-
Field Details
-
NEGATIVE_INFINITY
public static final char NEGATIVE_INFINITYThe encoded form of negative infinity-∞. -
POSITIVE_INFINITY
public static final char POSITIVE_INFINITYThe encoded form of positive infinity∞. -
POSITIVE_ZERO
public static final char POSITIVE_ZEROThe encoded form of positive zero0. -
NEGATIVE_ZERO
public static final char NEGATIVE_ZEROThe encoded form of negative zero-0. -
BIAS
public static final int BIASThe bias value used to offset the encoded exponent. A given exponenteis encoded as.BIAS+ e
-
-
Method Details
-
exampleNaN
public static char exampleNaN()One possible not-a-number value. -
isInfinite
public static boolean isInfinite(char k) Returntrueif the given packedbinary16value is infinite. -
isNaN
public static boolean isNaN(char k) Returntrueif the given packedbinary16value is not a number (NaN). -
packDouble
public static char packDouble(double k) Convert a double precision floating point value to a packed
binary16value.For the following specific cases, the function returns:
NaNiffisNaN(k)POSITIVE_INFINITYiffk ==Double.POSITIVE_INFINITYNEGATIVE_INFINITYiffk ==Double.NEGATIVE_INFINITYNEGATIVE_ZEROiffk == -0.0POSITIVE_ZEROiffk == 0.0
Otherwise, the
binary16value that most closely representskis returned. This may obviously be an infinite value as the interval of double precision values is far larger than that of thebinary16type.- See Also:
-
packFloat
public static char packFloat(float k) Convert a single precision floating point value to a packed
binary16value.For the following specific cases, the function returns:
NaNiffisNaN(k)POSITIVE_INFINITYiffk ==Float.POSITIVE_INFINITYNEGATIVE_INFINITYiffk ==Float.NEGATIVE_INFINITYNEGATIVE_ZEROiffk == -0.0POSITIVE_ZEROiffk == 0.0
Otherwise, the
binary16value that most closely representskis returned. This may obviously be an infinite value as the interval of single precision values is far larger than that of thebinary16type.- See Also:
-
packSetExponentUnbiasedUnchecked
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.- See Also:
-
packSetSignificandUnchecked
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.- See Also:
-
packSetSignUnchecked
public static char packSetSignUnchecked(int s) Encode the sign bit
s. Values should be in the range[0, 1], with0ironically denoting a positive value. Values outside of this range will be truncated.- See Also:
-
toRawBinaryString
Show the given raw packedbinary16value as a string of binary digits. -
unpackDouble
public static double unpackDouble(char k) Convert a packed
binary16valuekto a double-precision floating point value.The function returns:
NaNiffisNaN(k)Double.POSITIVE_INFINITYiffk ==POSITIVE_INFINITYDouble.NEGATIVE_INFINITYiffk ==NEGATIVE_INFINITY-0.0iffk ==NEGATIVE_ZERO0.0iffk ==POSITIVE_ZERO(-1.0 * n) * (2 ^ e) * 1.s, for the decoded signnofk, the decoded exponenteofk, and the decoded significandsofk.
- See Also:
-
unpackFloat
public static float unpackFloat(char k) Convert a packed
binary16valuekto a single-precision floating point value.The function returns:
NaNiffisNaN(k)Float.POSITIVE_INFINITYiffk ==POSITIVE_INFINITYFloat.NEGATIVE_INFINITYiffk ==NEGATIVE_INFINITY-0.0iffk ==NEGATIVE_ZERO0.0iffk ==POSITIVE_ZERO(-1.0 * n) * (2 ^ e) * 1.s, for the decoded signnofk, the decoded exponenteofk, and the decoded significandsofk.
- See Also:
-
unpackGetExponentUnbiased
public static int unpackGetExponentUnbiased(char k) Extract and unbias the exponent of the given packed
binary16value.The exponent is encoded biased as a number in the range
[0, 31], with0indicating that the number is subnormal and[1, 30]denoting the actual exponent plusBIAS. Infinite andNaNvalues always have an exponent of31.This function will therefore return:
-
0 -iff the input is a subnormal number.BIAS= -15 - An integer in the range
[1 -iff the input is a normal number.BIAS, 30 -BIAS] = [-14, 15] -
16iff the input isPOSITIVE_INFINITY,NEGATIVE_INFINITY, orNaN.
- See Also:
-
-
unpackGetSign
public static int unpackGetSign(char k) Retrieve the sign bit of the given packedbinary16value, as an integer in the range[0, 1].- See Also:
-
unpackGetSignificand
public static int unpackGetSignificand(char k) Return the significand of the given packed
binary16value as an integer in the range[0, 1023].- See Also:
-