Module ieee754java

Class Floating<T extends Floating<T>>

java.lang.Object
java.lang.Number
at.syntaxerror.ieee754.Floating<T>
All Implemented Interfaces:
Serializable, Comparable<T>
Direct Known Subclasses:
Binary, Decimal

public abstract class Floating<T extends Floating<T>> extends Number implements Comparable<T>
This class represents the base class for IEEE 754 binary and decimal numbers.
Author:
Thomas Kasper
See Also:
  • Field Details

  • Constructor Details

    • Floating

      public Floating(int signum, BigDecimal value)
      Creates a new 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
    • Floating

      public Floating(int signum, FloatingType type)
      Creates a new special floating-point number.
      Parameters:
      signum - the signum (either -1 or 1)
      type - the special type (must not be FloatingType.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 Floating<T>>
    • toString

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

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