Module ieee754java

Class Binary<T extends Binary<T>>

java.lang.Object
java.lang.Number
at.syntaxerror.ieee754.binary.Binary<T>
All Implemented Interfaces:
Serializable, Comparable<T>
Direct Known Subclasses:
Binary1024, Binary128, Binary16, Binary2048, Binary256, Binary32, Binary512, Binary64, Binary80

public abstract class Binary<T extends Binary<T>> extends Number implements Comparable<T>
This class is the base class for implementing IEEE 754 floating point specifications
Author:
Thomas Kasper
See Also:
  • Field Details

  • Constructor Details

    • Binary

      @Deprecated public Binary(int signum, BigDecimal value, boolean unchecked)
      Deprecated.
      internal use only
      Parameters:
      signum -
      value -
      unchecked -
    • Binary

      public Binary(int signum, BigDecimal value)
      Creates a new binary floating-point number with the given signum and value.

      If the value exceeds the maximum value, the value becomes Infinity with the respective sign.

      If the value is less than the minimum value, the values becomes 0.

      Parameters:
      signum - the signum (either -1, 0, or 1; must be the same as the value's signum)
      value - the value
    • Binary

      public Binary(int signum, BinaryType type)
      Creates a new special binary floating-point number.
      Parameters:
      signum - the signum (either -1 or 1)
      type - the special type (must not be BinaryType.FINITE)
  • Method Details

    • getBigDecimal

      public BigDecimal getBigDecimal()
      Returns the BigDecimal stored. Fails if the number is not finite.
      Returns:
      the stored BigDecimal
    • getSignum

      public int getSignum()
      Returns the signum, which is either -1 (negative), 0 (zero), or 1 (positive)
      Returns:
      the signum
    • isPositive

      public boolean isPositive()
      Checks whether this number is positive
      Returns:
      whether this number is positive
    • isNegative

      public boolean isNegative()
      Checks whether this number is negative
      Returns:
      whether this number is negative
    • isFinite

      public boolean isFinite()
      Checks whether this number is finite
      Returns:
      whether this number is finite
    • isNaN

      public boolean isNaN()
      Checks whether this number is sNaN or qNaN
      Returns:
      whether this number is NaN
    • isSignalingNaN

      public boolean isSignalingNaN()
      Checks whether this number is sNaN
      Returns:
      whether this number is sNaN
    • isQuietNaN

      public boolean isQuietNaN()
      Checks whether this number is qNaN
      Returns:
      whether this number is qNaN
    • isInfinity

      public boolean isInfinity()
      Checks whether this number is Infinity
      Returns:
      whether this number is Infinity
    • isPositiveInfinity

      public boolean isPositiveInfinity()
      Checks whether this number is +Infinity
      Returns:
      whether this number is +Infinity
    • isNegativeInfinity

      public boolean isNegativeInfinity()
      Checks whether this number is -Infinity
      Returns:
      whether this number is -Infinity
    • isZero

      public boolean isZero()
      Checks whether this number is 0
      Returns:
      whether this number is 0
    • isPositiveZero

      public boolean isPositiveZero()
      Checks whether this number is +0.

      Note: The signum value 0 also classifies as positive in this case

      Returns:
      whether this number is +0
    • isNegativeZero

      public boolean isNegativeZero()
      Checks whether this number is -0
      Returns:
      whether this number is -0
    • encode

      public BigInteger encode()
      Encodes this number into its binary representation
      Returns:
      the binary representation
    • intValue

      public int intValue()
      Specified by:
      intValue in class Number
    • longValue

      public long longValue()
      Specified by:
      longValue in class Number
    • floatValue

      public float floatValue()
      Specified by:
      floatValue in class Number
    • doubleValue

      public double doubleValue()
      Specified by:
      doubleValue in class Number
    • compareTo

      public int compareTo(T o)
      Specified by:
      compareTo in interface Comparable<T extends Binary<T>>
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • getCodec

      public abstract BinaryCodec<T> getCodec()
      Returns the codec used for this binary floating-point number
      Returns:
      the codec