java.lang.Object
at.syntaxerror.ieee754.FloatingCodec<T>
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 FloatingFactory<T> factory) Creates a new binary codec -
Method Summary
Modifier and TypeMethodDescriptiondecode(BigInteger value) Decodes the floating point's binary representationEncodes the floating point into its binary 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 processors)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 representationMethods inherited from class at.syntaxerror.ieee754.FloatingCodec
initialize
-
Constructor Details
-
BinaryCodec
public BinaryCodec(int exponent, int significand, boolean implicit, @NonNull @NonNull FloatingFactory<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 binary representation- Specified by:
encodein classFloatingCodec<T extends Binary<T>>- Parameters:
value- the floating point number- Returns:
- the encoded binary representation
-
decode
Decodes the floating point's binary representation- Specified by:
decodein classFloatingCodec<T extends Binary<T>>- Parameters:
value- the binary 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- Specified by:
isPositivein classFloatingCodec<T extends Binary<T>>- Parameters:
value- the value- Returns:
- whether the value is positive
-
isNegative
Checks if the value is negative- Specified by:
isNegativein classFloatingCodec<T extends Binary<T>>- Parameters:
value- the value- Returns:
- whether the value is negative
-
isInfinity
Checks if the value isInfinity's binary representation- Specified by:
isInfinityin classFloatingCodec<T extends Binary<T>>- Parameters:
value- the value- Returns:
- whether the value is
Infinity
-
isPositiveInfinity
Checks if the value is+Infinity's binary representation- Specified by:
isPositiveInfinityin classFloatingCodec<T extends Binary<T>>- Parameters:
value- the value- Returns:
- whether the value is
+Infinity
-
isNegativeInfinity
Checks if the value is-Infinity's binary representation- Specified by:
isNegativeInfinityin classFloatingCodec<T extends Binary<T>>- Parameters:
value- the value- Returns:
- whether the value is
-Infinity
-
getPositiveInfinity
Returns+Infinity's (likeDouble.POSITIVE_INFINITY) binary representation- Specified by:
getPositiveInfinityin classFloatingCodec<T extends Binary<T>>- Returns:
+Infinity
-
getNegativeInfinity
Returns-Infinity's (likeDouble.NEGATIVE_INFINITY) binary representation- Specified by:
getNegativeInfinityin classFloatingCodec<T extends Binary<T>>- Returns:
-Infinity
-
isNaN
Checks if the value isNaN's binary representation- Specified by:
isNaNin classFloatingCodec<T extends Binary<T>>- Parameters:
value- the value- Returns:
- whether the value is
NaN
-
isQuietNaN
Checks if the value isqNaN's binary representation- Specified by:
isQuietNaNin classFloatingCodec<T extends Binary<T>>- Parameters:
value- the value- Returns:
- whether the value is
qNaN
-
isSignalingNaN
Checks if the value issNaN's binary representation- Specified by:
isSignalingNaNin classFloatingCodec<T extends Binary<T>>- Parameters:
value- the value- Returns:
- whether the value is
sNaN
-
getQuietNaN
ReturnsqNaNbinary representation (on most processors)- Specified by:
getQuietNaNin classFloatingCodec<T extends Binary<T>>- Parameters:
signum- the signum- Returns:
qNaN
-
getSignalingNaN
ReturnssNaN's binary representation (on most processors)- Specified by:
getSignalingNaNin classFloatingCodec<T extends Binary<T>>- Parameters:
signum- the signum- Returns:
sNaN
-
getNaN
ReturnsNaN(qNaNon most processors)- Specified by:
getNaNin classFloatingCodec<T extends Binary<T>>- Returns:
NaN
-
getZero
Returns (possibly negative) zero's binary representation- Specified by:
getZeroin classFloatingCodec<T extends Binary<T>>- Returns:
- zero
-
getMinSubnormalValue
Returns the smallest postive (> 0) subnormal value- Specified by:
getMinSubnormalValuein classFloatingCodec<T extends Binary<T>>- Returns:
- the smallest postive value
-
getMinValue
Returns the smallest postive (> 0) normalized value.- Specified by:
getMinValuein classFloatingCodec<T extends Binary<T>>- Returns:
- the smallest postive value
-
getMaxValue
Returns the largest possible value- Specified by:
getMaxValuein classFloatingCodec<T extends Binary<T>>- Returns:
- the largest value
-
getEpsilon
Returns the difference between 1 and the smallest number greater than 1- Specified by:
getEpsilonin classFloatingCodec<T extends Binary<T>>- Returns:
- the difference
-
getExponentRange
Returns the smallest and largest possible exponent- Specified by:
getExponentRangein classFloatingCodec<T extends Binary<T>>- 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
-