Module ieee754java

Class DecimalCodec<T extends Decimal<T>>

java.lang.Object
at.syntaxerror.ieee754.FloatingCodec<T>
at.syntaxerror.ieee754.decimal.DecimalCodec<T>

public class DecimalCodec<T extends Decimal<T>> extends FloatingCodec<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 Details

    • DecimalCodec

      public DecimalCodec(int combination, int significand, @NonNull @NonNull FloatingFactory<T> factory)
      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 creating Binary 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

      public BigInteger encode(T value)
      Encodes the floating point into its binary representation using the representation method specified by Decimal.DEFAULT_CODING.
      Specified by:
      encode in class FloatingCodec<T extends Decimal<T>>
      Parameters:
      value - the floating point number
      Returns:
      the encoded binary representation
    • encodeBID

      public BigInteger encodeBID(T value)
      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

      public BigInteger encodeDPD(T value)
      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

      public T decode(BigInteger value)
      Decodes the floating point's binary representation using the representation method specified by Decimal.DEFAULT_CODING.
      Specified by:
      decode in class FloatingCodec<T extends Decimal<T>>
      Parameters:
      value - the binary representation
      Returns:
      the decoded floating point number
    • decodeBID

      public T decodeBID(BigInteger value)
      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

      public T decodeDPD(BigInteger value)
      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

      public BigInteger getCombination(BigInteger value)
      Returns the value's combination part
      Parameters:
      value - the value
      Returns:
      the combination
    • getSignificand

      public BigInteger getSignificand(BigInteger value)
      Returns the value's significand part.

      If there is an explicit bit, it is not included

      Parameters:
      value - the value
      Returns:
      the significand
    • isPositive

      public boolean isPositive(BigInteger value)
      Checks if the value is positive
      Specified by:
      isPositive in class FloatingCodec<T extends Decimal<T>>
      Parameters:
      value - the value
      Returns:
      whether the value is positive
    • isNegative

      public boolean isNegative(BigInteger value)
      Checks if the value is negative
      Specified by:
      isNegative in class FloatingCodec<T extends Decimal<T>>
      Parameters:
      value - the value
      Returns:
      whether the value is negative
    • isInfinity

      public boolean isInfinity(BigInteger value)
      Checks if the value is Infinity's binary representation
      Specified by:
      isInfinity in class FloatingCodec<T extends Decimal<T>>
      Parameters:
      value - the value
      Returns:
      whether the value is Infinity
    • isPositiveInfinity

      public boolean isPositiveInfinity(BigInteger value)
      Checks if the value is +Infinity's binary representation
      Specified by:
      isPositiveInfinity in class FloatingCodec<T extends Decimal<T>>
      Parameters:
      value - the value
      Returns:
      whether the value is +Infinity
    • isNegativeInfinity

      public boolean isNegativeInfinity(BigInteger value)
      Checks if the value is -Infinity's binary representation
      Specified by:
      isNegativeInfinity in class FloatingCodec<T extends Decimal<T>>
      Parameters:
      value - the value
      Returns:
      whether the value is -Infinity
    • getPositiveInfinity

      public BigInteger getPositiveInfinity()
      Returns +Infinity's (like Double.POSITIVE_INFINITY) binary representation
      Specified by:
      getPositiveInfinity in class FloatingCodec<T extends Decimal<T>>
      Returns:
      +Infinity
    • getNegativeInfinity

      public BigInteger getNegativeInfinity()
      Returns -Infinity's (like Double.NEGATIVE_INFINITY) binary representation
      Specified by:
      getNegativeInfinity in class FloatingCodec<T extends Decimal<T>>
      Returns:
      -Infinity
    • isNaN

      public boolean isNaN(BigInteger value)
      Checks if the value is NaN's binary representation
      Specified by:
      isNaN in class FloatingCodec<T extends Decimal<T>>
      Parameters:
      value - the value
      Returns:
      whether the value is NaN
    • isQuietNaN

      public boolean isQuietNaN(BigInteger value)
      Checks if the value is qNaN's binary representation
      Specified by:
      isQuietNaN in class FloatingCodec<T extends Decimal<T>>
      Parameters:
      value - the value
      Returns:
      whether the value is qNaN
    • isSignalingNaN

      public boolean isSignalingNaN(BigInteger value)
      Checks if the value is sNaN's binary representation
      Specified by:
      isSignalingNaN in class FloatingCodec<T extends Decimal<T>>
      Parameters:
      value - the value
      Returns:
      whether the value is sNaN
    • getQuietNaN

      public BigInteger getQuietNaN(int signum)
      Returns qNaN binary representation (on most processors)
      Specified by:
      getQuietNaN in class FloatingCodec<T extends Decimal<T>>
      Parameters:
      signum - the signum
      Returns:
      qNaN
    • getSignalingNaN

      public BigInteger getSignalingNaN(int signum)
      Returns sNaN's binary representation (on most processors)
      Specified by:
      getSignalingNaN in class FloatingCodec<T extends Decimal<T>>
      Parameters:
      signum - the signum
      Returns:
      sNaN
    • getNaN

      public BigInteger getNaN(int signum)
      Returns NaN (qNaN on most processors)
      Specified by:
      getNaN in class FloatingCodec<T extends Decimal<T>>
      Returns:
      NaN
    • getZero

      public BigInteger getZero(int signum)
      Returns (possibly negative) zero's binary representation
      Specified by:
      getZero in class FloatingCodec<T extends Decimal<T>>
      Returns:
      zero
    • getMinSubnormalValue

      public T getMinSubnormalValue()
      Returns the smallest postive (> 0) subnormal value
      Specified by:
      getMinSubnormalValue in class FloatingCodec<T extends Decimal<T>>
      Returns:
      the smallest postive value
    • getMinValue

      public T getMinValue()
      Returns the smallest postive (> 0) normalized value.
      Specified by:
      getMinValue in class FloatingCodec<T extends Decimal<T>>
      Returns:
      the smallest postive value
    • getMaxValue

      public T getMaxValue()
      Returns the largest possible value
      Specified by:
      getMaxValue in class FloatingCodec<T extends Decimal<T>>
      Returns:
      the largest value
    • getEpsilon

      public BigDecimal getEpsilon()
      Returns the difference between 1 and the smallest number greater than 1
      Specified by:
      getEpsilon in class FloatingCodec<T extends Decimal<T>>
      Returns:
      the difference
    • getExponentRange

      public Map.Entry<Integer,Integer> getExponentRange()
      Returns the smallest and largest possible exponent
      Specified by:
      getExponentRange in class FloatingCodec<T extends Decimal<T>>
      Returns:
      the smallest and largest exponent