Class OmegaBigDecimal

java.lang.Object
java.lang.Number
org.oristool.math.OmegaBigDecimal
All Implemented Interfaces:
Serializable, Comparable<OmegaBigDecimal>

public class OmegaBigDecimal extends Number implements Comparable<OmegaBigDecimal>
Immutable, arbitrary-precision signed decimal numbers with positive and negative infinity. Every actual computation is delegated to a java.math.BigDecimal instance.

All methods and constructors for this class throw NullPointerException when passed a null object reference for any input parameter.

See Also:
  • Field Details

  • Constructor Details

    • OmegaBigDecimal

      public OmegaBigDecimal(String number)
      Parses a number from the input string.
      Parameters:
      number - a string
    • OmegaBigDecimal

      public OmegaBigDecimal(BigDecimal number)
    • OmegaBigDecimal

      public OmegaBigDecimal(long number)
  • Method Details

    • toLeftNeighborhood

      public OmegaBigDecimal toLeftNeighborhood()
      Returns the left neighborhood of this value.
      Returns:
      left neighborhood
    • toRightNeighborhood

      public OmegaBigDecimal toRightNeighborhood()
      Returns the right neighborhood of this value.
      Returns:
      right neighborhood
    • toString

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

      public boolean equals(Object x)
      Compares this OmegaBigDecimal with the specified Object for equality. Unlike compareTo, this method considers two BigDecimal objects equal only if they are equal in value and scale (thus 2.0 is not equal to 2.00 when compared by this method). Positive (or negative) infinity is considered equal to itself.
      Overrides:
      equals in class Object
      Parameters:
      x - Object to which this OmegaBigDecimal is to be compared.
      Returns:
      true if and only if the specified Object is an OmegaBigDecimal and either its value and scale are equal to this OmegaBigDecimal's or they are both positive (negative) infinity.
      See Also:
    • hashCode

      public int hashCode()
      Returns the hash code for this OmegaBigDecimal. Note that two OmegaBigDecimal objects that are numerically equal but differ in scale (like 2.0 and 2.00) will have the same hash code (this is different wrt BigDecimal). Positive (negative) infinity objects always have the same hash code.
      Overrides:
      hashCode in class Object
      Returns:
      hash code for this OmegaBigDecimal.
      See Also:
    • 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(OmegaBigDecimal o)
      Specified by:
      compareTo in interface Comparable<OmegaBigDecimal>
    • isFinite

      public boolean isFinite()
    • bigDecimalValue

      public BigDecimal bigDecimalValue()
    • abs

      public OmegaBigDecimal abs()
      Returns the absolute value of this number.
      Returns:
      absolute value
    • negate

      public OmegaBigDecimal negate()
      Returns the opposite of this number.
      Returns:
      opposite
    • add

      public OmegaBigDecimal add(OmegaBigDecimal augend)
      Returns an OmegaBigDecimal whose value is (this + augend). In case of a +infinity -infinity indeterminate form, an exception is thrown.
      Parameters:
      augend - value to be added to this number
      Returns:
      this + augend
    • subtract

      public OmegaBigDecimal subtract(OmegaBigDecimal subtrahend)
      Returns an OmegaBigDecimal whose value is (this - subtrahend). In case of a +infinity -infinity indeterminate form, an exception is thrown.
      Parameters:
      subtrahend - value to be subtracted from this OmegaBigDecimal.
      Returns:
      this - subtrahend
    • multiply

      public OmegaBigDecimal multiply(OmegaBigDecimal multiplicand)
      Returns an OmegaBigDecimal whose value is this * multiplicand. In case of a 0 * +/- infinity indeterminate form, an exception is thrown.
      Parameters:
      multiplicand - value to be multiplied by this OmegaBigDecimal.
      Returns:
      this * multiplicand
    • divide

      public OmegaBigDecimal divide(BigDecimal divisor, MathContext mc)
      Returns a OmegaBigDecimal whose value is (this / divisor), with rounding according to the context settings.
      Parameters:
      divisor - value by which this OmegaBigDecimal is to be divided.
      mc - the context to use.
      Returns:
      this / divisor, rounded as necessary.
      Throws:
      IllegalArgumentException - if the divisor is BigDecimal.ZERO
      ArithmeticException - if the result is inexact but the rounding mode is UNNECESSARY or mc.precision == 0 and the quotient has a non-terminating decimal expansion.
    • min

      public OmegaBigDecimal min(OmegaBigDecimal val)
      Returns the minimum of this OmegaBigDecimal and val.
      Parameters:
      val - value with which the minimum is to be computed.
      Returns:
      the OmegaBigDecimal whose value is the lesser of this OmegaBigDecimal and val. If they are equal, as defined by the compareTo method, this is returned.
    • max

      public OmegaBigDecimal max(OmegaBigDecimal val)
      Returns the maximum of this OmegaBigDecimal and val.
      Parameters:
      val - value with which the maximum is to be computed.
      Returns:
      the OmegaBigDecimal whose value is the greater of this OmegaBigDecimal and val. If they are equal, as defined by the compareTo method, this is returned.
    • pow

      public OmegaBigDecimal pow(int n)
      Returns an OmegaBigDecimal whose value is this^n. The power is computed exactly, to unlimited precision.

      The parameter n must be in the range 0 through 999999999, inclusive. ZERO.pow(0) returns ONE.

      Parameters:
      n - power to raise this BigDecimal to.
      Returns:
      this^n
      Throws:
      ArithmeticException - if n is out of range.
      Since:
      1.5
    • isLeftNeighborhood

      public boolean isLeftNeighborhood()
    • isRightNeighborhood

      public boolean isRightNeighborhood()