org.apache.commons.math3.util

## Class BigReal

- java.lang.Object
- - org.apache.commons.math3.util.BigReal

- All Implemented Interfaces:
    java.io.Serializable, java.lang.Comparable<BigReal>, FieldElement<BigReal>

      public class BigReal
      extends java.lang.Object
      implements FieldElement<BigReal>, java.lang.Comparable<BigReal>, java.io.Serializable

  Arbitrary precision decimal number.

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

  Since:
    2.0
  Version:
    $Id: BigReal.java 1416643 2012-12-03 19:37:14Z tn $
  See Also:
    Serialized Form

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `private java.math.BigDecimal` | `d` Underlying BigDecimal.
    `static BigReal` | `ONE` A big real representing 1.
    `private java.math.RoundingMode` | `roundingMode` Rounding mode for divisions.
    `private int` | `scale` BigDecimal scale
    `private static long` | `serialVersionUID` Serializable version identifier.
    `static BigReal` | `ZERO` A big real representing 0.

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `BigReal(java.math.BigDecimal val)` Build an instance from a BigDecimal.
    `BigReal(java.math.BigInteger val)` Build an instance from a BigInteger.
    `BigReal(java.math.BigInteger unscaledVal, int scale)` Build an instance from an unscaled BigInteger.
    `BigReal(java.math.BigInteger unscaledVal, int scale, java.math.MathContext mc)` Build an instance from an unscaled BigInteger.
    `BigReal(java.math.BigInteger val, java.math.MathContext mc)` Build an instance from a BigInteger.
    `BigReal(char[] in)` Build an instance from a characters representation.
    `BigReal(char[] in, int offset, int len)` Build an instance from a characters representation.
    `BigReal(char[] in, int offset, int len, java.math.MathContext mc)` Build an instance from a characters representation.
    `BigReal(char[] in, java.math.MathContext mc)` Build an instance from a characters representation.
    `BigReal(double val)` Build an instance from a double.
    `BigReal(double val, java.math.MathContext mc)` Build an instance from a double.
    `BigReal(int val)` Build an instance from an int.
    `BigReal(int val, java.math.MathContext mc)` Build an instance from an int.
    `BigReal(long val)` Build an instance from a long.
    `BigReal(long val, java.math.MathContext mc)` Build an instance from a long.
    `BigReal(java.lang.String val)` Build an instance from a String representation.
    `BigReal(java.lang.String val, java.math.MathContext mc)` Build an instance from a String representation.

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `BigReal` | `add(BigReal a)` Compute this + a.
    `java.math.BigDecimal` | `bigDecimalValue()` Get the BigDecimal value corresponding to the instance.
    `int` | `compareTo(BigReal a)`
    `BigReal` | `divide(BigReal a)` Compute this ÷ a.
    `double` | `doubleValue()` Get the double value corresponding to the instance.
    `boolean` | `equals(java.lang.Object other)`
    `Field<BigReal>` | `getField()` Get the `Field` to which the instance belongs.
    `java.math.RoundingMode` | `getRoundingMode()` Gets the rounding mode for division operations The default is `RoundingMode.HALF_UP`
    `int` | `getScale()` Sets the scale for division operations.
    `int` | `hashCode()`
    `BigReal` | `multiply(BigReal a)` Compute this × a.
    `BigReal` | `multiply(int n)` Compute n × this.
    `BigReal` | `negate()` Returns the additive inverse of `this` element.
    `BigReal` | `reciprocal()` Returns the multiplicative inverse of `this` element.
    `void` | `setRoundingMode(java.math.RoundingMode roundingMode)` Sets the rounding mode for decimal divisions.
    `void` | `setScale(int scale)` Sets the scale for division operations.
    `BigReal` | `subtract(BigReal a)` Compute this - a.

    - ### Methods inherited from class java.lang.Object

      `clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### ZERO

          public static final BigReal ZERO

      A big real representing 0.

    - #### ONE

          public static final BigReal ONE

      A big real representing 1.

    - #### serialVersionUID

          private static final long serialVersionUID

      Serializable version identifier.
      See Also:
        Constant Field Values

    - #### d

          private final java.math.BigDecimal d

      Underlying BigDecimal.

    - #### roundingMode

          private java.math.RoundingMode roundingMode

      Rounding mode for divisions.

    - #### scale

          private int scale

      BigDecimal scale

  - ### Constructor Detail

    - #### BigReal

          public BigReal(java.math.BigDecimal val)

      Build an instance from a BigDecimal.
      Parameters:
        `val` - value of the instance

    - #### BigReal

          public BigReal(java.math.BigInteger val)

      Build an instance from a BigInteger.
      Parameters:
        `val` - value of the instance

    - #### BigReal

          public BigReal(java.math.BigInteger unscaledVal,
                 int scale)

      Build an instance from an unscaled BigInteger.
      Parameters:
        `unscaledVal` - unscaled value
        `scale` - scale to use

    - #### BigReal

          public BigReal(java.math.BigInteger unscaledVal,
                 int scale,
                 java.math.MathContext mc)

      Build an instance from an unscaled BigInteger.
      Parameters:
        `unscaledVal` - unscaled value
        `scale` - scale to use
        `mc` - to used

    - #### BigReal

          public BigReal(java.math.BigInteger val,
                 java.math.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,
                 java.math.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,
                 java.math.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,
                 java.math.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,
                 java.math.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,
                 java.math.MathContext mc)

      Build an instance from a long.
      Parameters:
        `val` - value of the instance
        `mc` - context to use

    - #### BigReal

          public BigReal(java.lang.String val)

      Build an instance from a String representation.
      Parameters:
        `val` - character representation of the value

    - #### BigReal

          public BigReal(java.lang.String val,
                 java.math.MathContext mc)

      Build an instance from a String representation.
      Parameters:
        `val` - character representation of the value
        `mc` - context to use

  - ### Method Detail

    - #### getRoundingMode

          public java.math.RoundingMode getRoundingMode()

      Gets the rounding mode for division operations The default is `RoundingMode.HALF_UP`
      Returns:
        the rounding mode.
      Since:
        2.1

    - #### setRoundingMode

          public void setRoundingMode(java.math.RoundingMode roundingMode)

      Sets the rounding mode for decimal divisions.
      Parameters:
        `roundingMode` - rounding mode for decimal divisions
      Since:
        2.1

    - #### getScale

          public int getScale()

      Sets the scale for division operations. The default is 64
      Returns:
        the scale
      Since:
        2.1

    - #### setScale

          public void setScale(int scale)

      Sets the scale for division operations.
      Parameters:
        `scale` - scale for division operations
      Since:
        2.1

    - #### 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 MathArithmeticException

      Compute this ÷ a.
      Specified by:
        `divide` in interface `FieldElement<BigReal>`
      Parameters:
        `a` - element to add
      Returns:
        a new element representing this ÷ a
      Throws:
        `MathArithmeticException` - if `a` is zero

    - #### reciprocal

          public BigReal reciprocal()
                             throws MathArithmeticException

      Returns the multiplicative inverse of `this` element.
      Specified by:
        `reciprocal` in interface `FieldElement<BigReal>`
      Returns:
        the inverse of `this`.
      Throws:
        `MathArithmeticException` - 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 × this = ∑i=1n 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 `java.lang.Comparable<BigReal>`

    - #### doubleValue

          public double doubleValue()

      Get the double value corresponding to the instance.
      Returns:
        double value corresponding to the instance

    - #### bigDecimalValue

          public java.math.BigDecimal bigDecimalValue()

      Get the BigDecimal value corresponding to the instance.
      Returns:
        BigDecimal value corresponding to the instance

    - #### equals

          public boolean equals(java.lang.Object other)

      Overrides:
        `equals` in class `java.lang.Object`

    - #### hashCode

          public int hashCode()

      Overrides:
        `hashCode` in class `java.lang.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

Copyright (c) 2003-2013 Apache Software Foundation