java.lang.Object
at.syntaxerror.ieee754.binary.BinaryCodec<T>
This class represents a codec capable of encoding and decoding IEEE 754 binary floating point numbers
as well as computing common values (such as NaN, maximum value, ...)
- Author:
- Thomas Kasper
-
Constructor Summary
ConstructorsConstructorDescriptionBinaryCodec(int exponent, int significand, boolean implicit, @NonNull BinaryFactory<T> factory) Creates a new binary codec -
Method Summary
Modifier and TypeMethodDescriptiondecode(BigInteger value) Decodes the floating point's byte representationEncodes the floating point into its byte representationReturns the smallest and largest possible exponent so that 10 to the power of the exponent is a normalized numberintgetBias()Returns the exponent biasintComputes the number of decimal digits that can be converted back and forth without loss of precisionReturns the difference between 1 and the smallest number greater than 1getExponent(BigInteger value) Returns the value's exponent partintReturns the number of bits occupied by the exponentReturns the smallest and largest possible exponentgetFullSignificand(BigInteger value) Returns the value's significand part.Returns the largest possible valueReturns the smallest postive (> 0) subnormal valueReturns the smallest postive (> 0) normalized value.getNaN(int signum) ReturnsNaN(qNaNon most processor; with all significand bits set)Returns-Infinity's (likeDouble.NEGATIVE_INFINITY) binary representationReturns+Infinity's (likeDouble.POSITIVE_INFINITY) binary representationgetQuietNaN(int signum) ReturnsqNaNbinary representation (on most processors)getSignalingNaN(int signum) ReturnssNaN's binary representation (on most processors)getSignificand(BigInteger value) Returns the value's significand part.intReturns the number of bits occupied by the significandgetUnbiasedExponent(BigInteger value) Returns the value's unbiased exponent partgetZero(int signum) Returns (possibly negative) zero's binary representationbooleanReturns whether there is an implicit bit used for the binary representationbooleanisInfinity(BigInteger value) Checks if the value isInfinity's binary representationbooleanisNaN(BigInteger value) Checks if the value isNaN's binary representationbooleanisNegative(BigInteger value) Checks if the value is negativebooleanisNegativeInfinity(BigInteger value) Checks if the value is-Infinity's binary representationbooleanisPositive(BigInteger value) Checks if the value is positivebooleanisPositiveInfinity(BigInteger value) Checks if the value is+Infinity's binary representationbooleanisQuietNaN(BigInteger value) Checks if the value isqNaN's binary representationbooleanisSignalingNaN(BigInteger value) Checks if the value issNaN's binary representation
-
Constructor Details
-
BinaryCodec
public BinaryCodec(int exponent, int significand, boolean implicit, @NonNull @NonNull BinaryFactory<T> factory) Creates a new binary codec- Parameters:
exponent- the number of exponent bits (> 0,< 32)significand- the number of significand bits (> 0)implicit- whether there is an implicit significand bitfactory- the factory for creatingBinaryobjects
-
-
Method Details
-
getExponentBits
public int getExponentBits()Returns the number of bits occupied by the exponent- Returns:
- the number of exponent's bits
-
getSignificandBits
public int getSignificandBits()Returns the number of bits occupied by the significand- Returns:
- the number of significand's bits
-
isImplicit
public boolean isImplicit()Returns whether there is an implicit bit used for the binary representation- Returns:
- whether there is an implicit bit
-
encode
Encodes the floating point into its byte representation- Parameters:
value- the floating point number- Returns:
- the encoded byte representation
-
decode
Decodes the floating point's byte representation- Parameters:
value- the byte representation- Returns:
- the decoded floating point number
-
getBias
public int getBias()Returns the exponent bias- Returns:
- the bias
-
getUnbiasedExponent
Returns the value's unbiased exponent part- Parameters:
value- the value- Returns:
- the unbiased exponent
-
getExponent
Returns the value's exponent part- Parameters:
value- the value- Returns:
- the exponent
-
getSignificand
Returns the value's significand part.If there is an explicit bit, it is not included
- Parameters:
value- the value- Returns:
- the significand
-
getFullSignificand
Returns the value's significand part.If there is an explicit bit, it is included
- Parameters:
value- the value- Returns:
- the significand
-
isPositive
Checks if the value is positive- Parameters:
value- the value- Returns:
- whether the value is positive
-
isNegative
Checks if the value is negative- Parameters:
value- the value- Returns:
- whether the value is negative
-
isInfinity
Checks if the value isInfinity's binary representation- Parameters:
value- the value- Returns:
- whether the value is
Infinity
-
isPositiveInfinity
Checks if the value is+Infinity's binary representation- Parameters:
value- the value- Returns:
- whether the value is
+Infinity
-
isNegativeInfinity
Checks if the value is-Infinity's binary representation- Parameters:
value- the value- Returns:
- whether the value is
-Infinity
-
getPositiveInfinity
Returns+Infinity's (likeDouble.POSITIVE_INFINITY) binary representation- Returns:
+Infinity
-
getNegativeInfinity
Returns-Infinity's (likeDouble.NEGATIVE_INFINITY) binary representation- Returns:
-Infinity
-
isNaN
Checks if the value isNaN's binary representation- Parameters:
value- the value- Returns:
- whether the value is
NaN
-
isQuietNaN
Checks if the value isqNaN's binary representation- Parameters:
value- the value- Returns:
- whether the value is
qNaN
-
isSignalingNaN
Checks if the value issNaN's binary representation- Parameters:
value- the value- Returns:
- whether the value is
sNaN
-
getQuietNaN
ReturnsqNaNbinary representation (on most processors)- Parameters:
signum- the signum- Returns:
qNaN
-
getSignalingNaN
ReturnssNaN's binary representation (on most processors)- Parameters:
signum- the signum- Returns:
sNaN
-
getNaN
ReturnsNaN(qNaNon most processor; with all significand bits set)- Returns:
NaN
-
getZero
Returns (possibly negative) zero's binary representation- Returns:
- zero
-
getMinSubnormalValue
Returns the smallest postive (> 0) subnormal value- Returns:
- the smallest postive value
-
getMinValue
Returns the smallest postive (> 0) normalized value.- Returns:
- the smallest postive value
-
getMaxValue
Returns the largest possible value- Returns:
- the largest value
-
getEpsilon
Returns the difference between 1 and the smallest number greater than 1- Returns:
- the difference
-
getExponentRange
Returns the smallest and largest possible exponent- Returns:
- the smallest and largest exponent
-
get10ExponentRange
Returns the smallest and largest possible exponent so that 10 to the power of the exponent is a normalized number- Returns:
- the smallest and largest exponent
-
getDecimalDigits
public int getDecimalDigits()Computes the number of decimal digits that can be converted back and forth without loss of precision- Returns:
- the number of decimal digits
-