Class BigReal

java.lang.Object
org.hipparchus.util.BigReal
All Implemented Interfaces:
Serializable, Comparable<BigReal>, FieldElement<BigReal>

public class BigReal extends Object implements FieldElement<BigReal>, Comparable<BigReal>, Serializable
Arbitrary precision decimal number.

This class is a simple wrapper around the standard BigDecimal in order to implement the FieldElement interface.

See Also:
  • Field Details

    • ZERO

      public static final BigReal ZERO
      A big real representing 0.
    • ONE

      public static final BigReal ONE
      A big real representing 1.
  • Constructor Details

    • BigReal

      public BigReal(BigDecimal val)
      Build an instance from a BigDecimal.
      Parameters:
      val - value of the instance
    • BigReal

      public BigReal(BigInteger val)
      Build an instance from a BigInteger.
      Parameters:
      val - value of the instance
    • BigReal

      public BigReal(BigInteger unscaledVal, int scale)
      Build an instance from an unscaled BigInteger.
      Parameters:
      unscaledVal - unscaled value
      scale - scale to use
    • BigReal

      public BigReal(BigInteger unscaledVal, int scale, MathContext mc)
      Build an instance from an unscaled BigInteger.
      Parameters:
      unscaledVal - unscaled value
      scale - scale to use
      mc - to used
    • BigReal

      public BigReal(BigInteger val, MathContext mc)
      Build an instance from a BigInteger.
      Parameters:
      val - value of the instance
      mc - context to use
    • BigReal

      public BigReal(char[] in)
      Build an instance from a characters representation.
      Parameters:
      in - character representation of the value
    • BigReal

      public BigReal(char[] in, int offset, int len)
      Build an instance from a characters representation.
      Parameters:
      in - character representation of the value
      offset - offset of the first character to analyze
      len - length of the array slice to analyze
    • BigReal

      public BigReal(char[] in, int offset, int len, MathContext mc)
      Build an instance from a characters representation.
      Parameters:
      in - character representation of the value
      offset - offset of the first character to analyze
      len - length of the array slice to analyze
      mc - context to use
    • BigReal

      public BigReal(char[] in, MathContext mc)
      Build an instance from a characters representation.
      Parameters:
      in - character representation of the value
      mc - context to use
    • BigReal

      public BigReal(double val)
      Build an instance from a double.
      Parameters:
      val - value of the instance
    • BigReal

      public BigReal(double val, MathContext mc)
      Build an instance from a double.
      Parameters:
      val - value of the instance
      mc - context to use
    • BigReal

      public BigReal(int val)
      Build an instance from an int.
      Parameters:
      val - value of the instance
    • BigReal

      public BigReal(int val, MathContext mc)
      Build an instance from an int.
      Parameters:
      val - value of the instance
      mc - context to use
    • BigReal

      public BigReal(long val)
      Build an instance from a long.
      Parameters:
      val - value of the instance
    • BigReal

      public BigReal(long val, MathContext mc)
      Build an instance from a long.
      Parameters:
      val - value of the instance
      mc - context to use
    • BigReal

      public BigReal(String val)
      Build an instance from a String representation.
      Parameters:
      val - character representation of the value
    • BigReal

      public BigReal(String val, MathContext mc)
      Build an instance from a String representation.
      Parameters:
      val - character representation of the value
      mc - context to use
  • Method Details

    • getReal

      public double getReal()
      Get the real value of the number.
      Specified by:
      getReal in interface FieldElement<BigReal>
      Returns:
      real value
    • getRoundingMode

      public RoundingMode getRoundingMode()
      Gets the rounding mode for division operations The default is RoundingMode.HALF_UP
      Returns:
      the rounding mode.
    • setRoundingMode

      public void setRoundingMode(RoundingMode roundingMode)
      Sets the rounding mode for decimal divisions.
      Parameters:
      roundingMode - rounding mode for decimal divisions
    • getScale

      public int getScale()
      Sets the scale for division operations. The default is 64
      Returns:
      the scale
    • setScale

      public void setScale(int scale)
      Sets the scale for division operations.
      Parameters:
      scale - scale for division operations
    • add

      public BigReal add(BigReal a)
      Compute this + a.
      Specified by:
      add in interface FieldElement<BigReal>
      Parameters:
      a - element to add
      Returns:
      a new element representing this + a
    • subtract

      public BigReal subtract(BigReal a)
      Compute this - a.
      Specified by:
      subtract in interface FieldElement<BigReal>
      Parameters:
      a - element to subtract
      Returns:
      a new element representing this - a
    • negate

      public BigReal negate()
      Returns the additive inverse of this element.
      Specified by:
      negate in interface FieldElement<BigReal>
      Returns:
      the opposite of this.
    • divide

      public BigReal divide(BigReal a) throws MathRuntimeException
      Compute this ÷ a.
      Specified by:
      divide in interface FieldElement<BigReal>
      Parameters:
      a - element to divide by
      Returns:
      a new element representing this ÷ a
      Throws:
      MathRuntimeException - if a is zero
    • reciprocal

      public BigReal reciprocal() throws MathRuntimeException
      Returns the multiplicative inverse of this element.
      Specified by:
      reciprocal in interface FieldElement<BigReal>
      Returns:
      the inverse of this.
      Throws:
      MathRuntimeException - if this is zero
    • multiply

      public BigReal multiply(BigReal a)
      Compute this × a.
      Specified by:
      multiply in interface FieldElement<BigReal>
      Parameters:
      a - element to multiply
      Returns:
      a new element representing this × a
    • multiply

      public BigReal multiply(int n)
      Compute n × this. Multiplication by an integer number is defined as the following sum \[ n \times \mathrm{this} = \sum_{i=1}^n \mathrm{this} \]
      Specified by:
      multiply in interface FieldElement<BigReal>
      Parameters:
      n - Number of times this must be added to itself.
      Returns:
      A new element representing n × this.
    • compareTo

      public int compareTo(BigReal a)
      Specified by:
      compareTo in interface Comparable<BigReal>
    • doubleValue

      public double doubleValue()
      Get the double value corresponding to the instance.
      Returns:
      double value corresponding to the instance
    • bigDecimalValue

      public BigDecimal bigDecimalValue()
      Get the BigDecimal value corresponding to the instance.
      Returns:
      BigDecimal value corresponding to the instance
    • equals

      public boolean equals(Object other)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • getField

      public Field<BigReal> getField()
      Get the Field to which the instance belongs.
      Specified by:
      getField in interface FieldElement<BigReal>
      Returns:
      Field to which the instance belongs