java.lang.Object
at.syntaxerror.ieee754.FloatingCodec<T>
at.syntaxerror.ieee754.decimal.DecimalCodec<T>
This class represents a codec capable of encoding and decoding IEEE 754 decimal floating point numbers
as well as computing common values (such as NaN, maximum value, ...)
- Author:
- Thomas Kasper
-
Constructor Summary
ConstructorsConstructorDescriptionDecimalCodec
(int combination, int significand, @NonNull FloatingFactory<T> factory) Creates a new decimal codec -
Method Summary
Modifier and TypeMethodDescriptiondecode
(BigInteger value) Decodes the floating point's binary representation using the representation method specified byDecimal.DEFAULT_CODING
.decodeBID
(BigInteger value) Decodes the floating point's binary representation using the binary integer decimal representation methoddecodeDPD
(BigInteger value) Decodes the floating point's binary representation using the densly packed decimal representation methodEncodes the floating point into its binary representation using the representation method specified byDecimal.DEFAULT_CODING
.Encodes the floating point into its binary representation using the binary integer decimal representation methodEncodes the floating point into its binary representation using the densly packed decimal representation methodint
getBias()
Returns the exponent biasgetCombination
(BigInteger value) Returns the value's combination partint
Returns the number of bits occupied by the combination fieldReturns the difference between 1 and the smallest number greater than 1Returns the smallest and largest possible exponentReturns 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 significandint
Returns the maximum number of decimal digits for the significandgetZero
(int signum) Returns (possibly negative) zero's 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
-
DecimalCodec
Creates a new decimal codec- Parameters:
combination
- the number of combination bits (> 0
,< 32
)significand
- the number of significand bits (> 0
)factory
- the factory for creatingBinary
objects
-
-
Method Details
-
getCombinationBits
public int getCombinationBits()Returns the number of bits occupied by the combination field- Returns:
- the number of combination field's bits
-
getSignificandBits
public int getSignificandBits()Returns the number of bits occupied by the significand- Returns:
- the number of significand's bits
-
encode
Encodes the floating point into its binary representation using the representation method specified byDecimal.DEFAULT_CODING
.- Specified by:
encode
in classFloatingCodec<T extends Decimal<T>>
- Parameters:
value
- the floating point number- Returns:
- the encoded binary representation
-
encodeBID
Encodes the floating point into its binary representation using the binary integer decimal representation method- Parameters:
value
- the floating point number- Returns:
- the encoded binary representation
-
encodeDPD
Encodes the floating point into its binary representation using the densly packed decimal representation method- Parameters:
value
- the floating point number- Returns:
- the encoded binary representation
-
decode
Decodes the floating point's binary representation using the representation method specified byDecimal.DEFAULT_CODING
.- Specified by:
decode
in classFloatingCodec<T extends Decimal<T>>
- Parameters:
value
- the binary representation- Returns:
- the decoded floating point number
-
decodeBID
Decodes the floating point's binary representation using the binary integer decimal representation method- Parameters:
value
- the binary representation- Returns:
- the decoded floating point number
-
decodeDPD
Decodes the floating point's binary representation using the densly packed decimal representation method- Parameters:
value
- the binary representation- Returns:
- the decoded floating point number
-
getBias
public int getBias()Returns the exponent bias- Returns:
- the bias
-
getSignificandDigits
public int getSignificandDigits()Returns the maximum number of decimal digits for the significand- Returns:
- the maximum number of decimal digits
-
getCombination
Returns the value's combination part- Parameters:
value
- the value- Returns:
- the combination
-
getSignificand
Returns the value's significand part.If there is an explicit bit, it is not included
- Parameters:
value
- the value- Returns:
- the significand
-
isPositive
Checks if the value is positive- Specified by:
isPositive
in classFloatingCodec<T extends Decimal<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 Decimal<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 Decimal<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 Decimal<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 Decimal<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 Decimal<T>>
- Returns:
+Infinity
-
getNegativeInfinity
Returns-Infinity
's (likeDouble.NEGATIVE_INFINITY
) binary representation- Specified by:
getNegativeInfinity
in classFloatingCodec<T extends Decimal<T>>
- Returns:
-Infinity
-
isNaN
Checks if the value isNaN
's binary representation- Specified by:
isNaN
in classFloatingCodec<T extends Decimal<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 Decimal<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 Decimal<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 Decimal<T>>
- Parameters:
signum
- the signum- Returns:
qNaN
-
getSignalingNaN
ReturnssNaN
's binary representation (on most processors)- Specified by:
getSignalingNaN
in classFloatingCodec<T extends Decimal<T>>
- Parameters:
signum
- the signum- Returns:
sNaN
-
getNaN
ReturnsNaN
(qNaN
on most processors)- Specified by:
getNaN
in classFloatingCodec<T extends Decimal<T>>
- Returns:
NaN
-
getZero
Returns (possibly negative) zero's binary representation- Specified by:
getZero
in classFloatingCodec<T extends Decimal<T>>
- Returns:
- zero
-
getMinSubnormalValue
Returns the smallest postive (> 0
) subnormal value- Specified by:
getMinSubnormalValue
in classFloatingCodec<T extends Decimal<T>>
- Returns:
- the smallest postive value
-
getMinValue
Returns the smallest postive (> 0
) normalized value.- Specified by:
getMinValue
in classFloatingCodec<T extends Decimal<T>>
- Returns:
- the smallest postive value
-
getMaxValue
Returns the largest possible value- Specified by:
getMaxValue
in classFloatingCodec<T extends Decimal<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 Decimal<T>>
- Returns:
- the difference
-
getExponentRange
Returns the smallest and largest possible exponent- Specified by:
getExponentRange
in classFloatingCodec<T extends Decimal<T>>
- Returns:
- the smallest and largest exponent
-