Module ieee754java

Class FloatingCodec<T extends Floating<T>>

java.lang.Object
at.syntaxerror.ieee754.FloatingCodec<T>
Direct Known Subclasses:
BinaryCodec, DecimalCodec

public abstract class FloatingCodec<T extends Floating<T>> extends Object
This class represents the base codec for encoding and decoding IEEE 754 floating point numbers. See BinaryCodec and DecimalCodec for implementations.
Author:
Thomas Kasper
  • Constructor Details

    • FloatingCodec

      public FloatingCodec()
  • Method Details

    • initialize

      protected final void initialize()
      Initializes the codec, so that the max, min and subnormal min value are guaranteed to be accessible.

      Without this method, codecs which memoize those values might get stuck in an endless loop, since these methods are also called from within the Floating(int, java.math.BigDecimal) constructor

    • decode

      public abstract T decode(BigInteger value)
      Decodes the floating point's binary representation
      Parameters:
      value - the binary representation
      Returns:
      the decoded floating point number
    • encode

      public abstract BigInteger encode(T value)
      Encodes the floating point into its binary representation
      Parameters:
      value - the floating point number
      Returns:
      the encoded binary representation
    • isPositive

      public abstract boolean isPositive(BigInteger value)
      Checks if the value is positive
      Parameters:
      value - the value
      Returns:
      whether the value is positive
    • isNegative

      public abstract boolean isNegative(BigInteger value)
      Checks if the value is negative
      Parameters:
      value - the value
      Returns:
      whether the value is negative
    • isInfinity

      public abstract boolean isInfinity(BigInteger value)
      Checks if the value is Infinity's binary representation
      Parameters:
      value - the value
      Returns:
      whether the value is Infinity
    • isPositiveInfinity

      public abstract boolean isPositiveInfinity(BigInteger value)
      Checks if the value is +Infinity's binary representation
      Parameters:
      value - the value
      Returns:
      whether the value is +Infinity
    • isNegativeInfinity

      public abstract boolean isNegativeInfinity(BigInteger value)
      Checks if the value is -Infinity's binary representation
      Parameters:
      value - the value
      Returns:
      whether the value is -Infinity
    • getPositiveInfinity

      public abstract BigInteger getPositiveInfinity()
      Returns +Infinity's (like Double.POSITIVE_INFINITY) binary representation
      Returns:
      +Infinity
    • getNegativeInfinity

      public abstract BigInteger getNegativeInfinity()
      Returns -Infinity's (like Double.NEGATIVE_INFINITY) binary representation
      Returns:
      -Infinity
    • isNaN

      public abstract boolean isNaN(BigInteger value)
      Checks if the value is NaN's binary representation
      Parameters:
      value - the value
      Returns:
      whether the value is NaN
    • isQuietNaN

      public abstract boolean isQuietNaN(BigInteger value)
      Checks if the value is qNaN's binary representation
      Parameters:
      value - the value
      Returns:
      whether the value is qNaN
    • isSignalingNaN

      public abstract boolean isSignalingNaN(BigInteger value)
      Checks if the value is sNaN's binary representation
      Parameters:
      value - the value
      Returns:
      whether the value is sNaN
    • getQuietNaN

      public abstract BigInteger getQuietNaN(int signum)
      Returns qNaN binary representation (on most processors)
      Parameters:
      signum - the signum
      Returns:
      qNaN
    • getSignalingNaN

      public abstract BigInteger getSignalingNaN(int signum)
      Returns sNaN's binary representation (on most processors)
      Parameters:
      signum - the signum
      Returns:
      sNaN
    • getNaN

      public abstract BigInteger getNaN(int signum)
      Returns NaN (qNaN on most processors)
      Returns:
      NaN
    • getZero

      public abstract BigInteger getZero(int signum)
      Returns (possibly negative) zero's binary representation
      Returns:
      zero
    • getMinSubnormalValue

      public abstract T getMinSubnormalValue()
      Returns the smallest postive (> 0) subnormal value
      Returns:
      the smallest postive value
    • getMinValue

      public abstract T getMinValue()
      Returns the smallest postive (> 0) normalized value.
      Returns:
      the smallest postive value
    • getMaxValue

      public abstract T getMaxValue()
      Returns the largest possible value
      Returns:
      the largest value
    • getEpsilon

      public abstract BigDecimal getEpsilon()
      Returns the difference between 1 and the smallest number greater than 1
      Returns:
      the difference
    • getExponentRange

      public abstract Map.Entry<Integer,Integer> getExponentRange()
      Returns the smallest and largest possible exponent
      Returns:
      the smallest and largest exponent