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 numberint
getBias()
Returns the exponent biasint
Computes 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 partint
Returns 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
(qNaN
on most processors)Returns-Infinity
's (likeDouble.NEGATIVE_INFINITY
) binary representationReturns+Infinity
's (likeDouble.POSITIVE_INFINITY
) binary representationgetQuietNaN
(int signum) ReturnsqNaN
binary representation (on most processors)getSignalingNaN
(int signum) ReturnssNaN
's binary representation (on most processors)getSignificand
(BigInteger value) Returns the value's significand part.int
Returns 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 representationboolean
Returns whether there is an implicit bit used for the binary representationboolean
isInfinity
(BigInteger value) Checks if the value isInfinity
's binary representationboolean
isNaN
(BigInteger value) Checks if the value isNaN
's binary representationboolean
isNegative
(BigInteger value) Checks if the value is negativeboolean
isNegativeInfinity
(BigInteger value) Checks if the value is-Infinity
's binary representationboolean
isPositive
(BigInteger value) Checks if the value is positiveboolean
isPositiveInfinity
(BigInteger value) Checks if the value is+Infinity
's binary representationboolean
isQuietNaN
(BigInteger value) Checks if the value isqNaN
's binary representationboolean
isSignalingNaN
(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 creatingBinary
objects
-
-
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:
encode
in 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:
decode
in 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:
isPositive
in classFloatingCodec<T extends Binary<T>>
- Parameters:
value
- the value- Returns:
- whether the value is positive
-
isNegative
Checks if the value is negative- Specified by:
isNegative
in 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:
isInfinity
in 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:
isPositiveInfinity
in 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:
isNegativeInfinity
in 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:
getPositiveInfinity
in classFloatingCodec<T extends Binary<T>>
- Returns:
+Infinity
-
getNegativeInfinity
Returns-Infinity
's (likeDouble.NEGATIVE_INFINITY
) binary representation- Specified by:
getNegativeInfinity
in classFloatingCodec<T extends Binary<T>>
- Returns:
-Infinity
-
isNaN
Checks if the value isNaN
's binary representation- Specified by:
isNaN
in 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:
isQuietNaN
in 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:
isSignalingNaN
in classFloatingCodec<T extends Binary<T>>
- Parameters:
value
- the value- Returns:
- whether the value is
sNaN
-
getQuietNaN
ReturnsqNaN
binary representation (on most processors)- Specified by:
getQuietNaN
in classFloatingCodec<T extends Binary<T>>
- Parameters:
signum
- the signum- Returns:
qNaN
-
getSignalingNaN
ReturnssNaN
's binary representation (on most processors)- Specified by:
getSignalingNaN
in classFloatingCodec<T extends Binary<T>>
- Parameters:
signum
- the signum- Returns:
sNaN
-
getNaN
ReturnsNaN
(qNaN
on most processors)- Specified by:
getNaN
in classFloatingCodec<T extends Binary<T>>
- Returns:
NaN
-
getZero
Returns (possibly negative) zero's binary representation- Specified by:
getZero
in classFloatingCodec<T extends Binary<T>>
- Returns:
- zero
-
getMinSubnormalValue
Returns the smallest postive (> 0
) subnormal value- Specified by:
getMinSubnormalValue
in classFloatingCodec<T extends Binary<T>>
- Returns:
- the smallest postive value
-
getMinValue
Returns the smallest postive (> 0
) normalized value.- Specified by:
getMinValue
in classFloatingCodec<T extends Binary<T>>
- Returns:
- the smallest postive value
-
getMaxValue
Returns the largest possible value- Specified by:
getMaxValue
in classFloatingCodec<T extends Binary<T>>
- Returns:
- the largest value
-
getEpsilon
Returns the difference between 1 and the smallest number greater than 1- Specified by:
getEpsilon
in classFloatingCodec<T extends Binary<T>>
- Returns:
- the difference
-
getExponentRange
Returns the smallest and largest possible exponent- Specified by:
getExponentRange
in 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
-