Top Description Fields Constructors Methods
org.apache.commons.math3.util

public Class BigReal

extends Object
implements FieldElement<BigReal>, Comparable<BigReal>, Serializable
Class Inheritance
All Implemented Interfaces
java.io.Serializable, java.lang.Comparable, org.apache.commons.math3.FieldElement
Imports
java.io.Serializable, java.math.BigDecimal, .BigInteger, .MathContext, .RoundingMode, org.apache.commons.math3.Field, .FieldElement, org.apache.commons.math3.exception.MathArithmeticException, org.apache.commons.math3.exception.util.LocalizedFormats

Arbitrary precision decimal number.

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

Since
2.0

Field Summary

Modifier and TypeField and Description
private final BigDecimal
d

Underlying BigDecimal.

public static final BigReal
ONE

A big real representing 1.

private RoundingMode
roundingMode

Rounding mode for divisions.

private int
scale

BigDecimal scale

private static final long
serialVersionUID

Serializable version identifier.

public static final BigReal
ZERO

A big real representing 0.

Constructor Summary

AccessConstructor and Description
public
BigReal(BigDecimal
value of the instance
val
)

Build an instance from a BigDecimal.

public
BigReal(BigInteger
value of the instance
val
)

Build an instance from a BigInteger.

public
BigReal(BigInteger
unscaled value
unscaledVal
,
int
scale to use
scale
)

Build an instance from an unscaled BigInteger.

public
BigReal(BigInteger
unscaled value
unscaledVal
,
int
scale to use
scale
,
MathContext
to used
mc
)

Build an instance from an unscaled BigInteger.

public
BigReal(BigInteger
value of the instance
val
,
MathContext
context to use
mc
)

Build an instance from a BigInteger.

public
BigReal(char[]
character representation of the value
in
)

Build an instance from a characters representation.

public
BigReal(char[]
character representation of the value
in
,
int
offset of the first character to analyze
offset
,
int
length of the array slice to analyze
len
)

Build an instance from a characters representation.

public
BigReal(char[]
character representation of the value
in
,
int
offset of the first character to analyze
offset
,
int
length of the array slice to analyze
len
,
MathContext
context to use
mc
)

Build an instance from a characters representation.

public
BigReal(char[]
character representation of the value
in
,
MathContext
context to use
mc
)

Build an instance from a characters representation.

public
BigReal(double
value of the instance
val
)

Build an instance from a double.

public
BigReal(double
value of the instance
val
,
MathContext
context to use
mc
)

Build an instance from a double.

public
BigReal(int
value of the instance
val
)

Build an instance from an int.

public
BigReal(int
value of the instance
val
,
MathContext
context to use
mc
)

Build an instance from an int.

public
BigReal(long
value of the instance
val
)

Build an instance from a long.

public
BigReal(long
value of the instance
val
,
MathContext
context to use
mc
)

Build an instance from a long.

public
BigReal(String
character representation of the value
val
)

Build an instance from a String representation.

public
BigReal(String
character representation of the value
val
,
MathContext
context to use
mc
)

Build an instance from a String representation.

Method Summary

Modifier and TypeMethod and Description
public BigReal
add(BigReal
element to add
a
)

Implements org.apache.commons.math3.FieldElement.add.

Compute this + a.

public BigDecimal

Returns:

BigDecimal value corresponding to the instance
bigDecimalValue
()

Get the BigDecimal value corresponding to the instance.

public int
compareTo(BigReal
the object to be compared.
a
)

Implements java.lang.Comparable.compareTo.

Compares this object with the specified object for order.

public BigReal
divide(BigReal
element to divide by
a
)

Implements org.apache.commons.math3.FieldElement.divide.

Compute this ÷ a.

public double

Returns:

double value corresponding to the instance
doubleValue
()

Get the double value corresponding to the instance.

public boolean
equals(Object
the reference object with which to compare.
other
)

Overrides java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.

public Field<BigReal>
getField()

Implements org.apache.commons.math3.FieldElement.getField.

Get the Field to which the instance belongs.

public RoundingMode

Returns:

the rounding mode.
getRoundingMode
()

Gets the rounding mode for division operations The default is RoundingMode.HALF_UP

public int

Returns:

the scale
getScale
()

Sets the scale for division operations.

public int
hashCode()

Overrides java.lang.Object.hashCode.

Returns a hash code value for this object.

public BigReal
multiply(BigReal
element to multiply
a
)

Implements org.apache.commons.math3.FieldElement.multiply.

Compute this × a.

public BigReal
multiply(final int
Number of times this must be added to itself.
n
)

Implements org.apache.commons.math3.FieldElement.multiply, org.apache.commons.math3.FieldElement.multiply.

Compute n × this.</center>

public BigReal
negate()

Implements org.apache.commons.math3.FieldElement.negate.

Returns the additive inverse of this element.

public BigReal
reciprocal()

Implements org.apache.commons.math3.FieldElement.reciprocal.

Returns the multiplicative inverse of this element.

public void
setRoundingMode(RoundingMode
rounding mode for decimal divisions
roundingMode
)

Sets the rounding mode for decimal divisions.

public void
setScale(int
scale for division operations
scale
)

Sets the scale for division operations.

public BigReal
subtract(BigReal
element to subtract
a
)

Implements org.apache.commons.math3.FieldElement.subtract.

Compute this - a.

Inherited from java.lang.Object:
clonefinalizegetClassnotifynotifyAlltoStringwaitwaitwait

Field Detail

dback to summary
private final BigDecimal d

Underlying BigDecimal.

ONEback to summary
public static final BigReal ONE

A big real representing 1.

roundingModeback to summary
private RoundingMode roundingMode

Rounding mode for divisions.

scaleback to summary
private int scale

BigDecimal scale

serialVersionUIDback to summary
private static final long serialVersionUID

Serializable version identifier.

ZEROback to summary
public static final BigReal ZERO

A big real representing 0.

Constructor Detail

BigRealback to summary
public BigReal(BigDecimal val)

Build an instance from a BigDecimal.

Parameters
val:BigDecimal

value of the instance

BigRealback to summary
public BigReal(BigInteger val)

Build an instance from a BigInteger.

Parameters
val:BigInteger

value of the instance

BigRealback to summary
public BigReal(BigInteger unscaledVal, int scale)

Build an instance from an unscaled BigInteger.

Parameters
unscaledVal:BigInteger

unscaled value

scale:int

scale to use

BigRealback to summary
public BigReal(BigInteger unscaledVal, int scale, MathContext mc)

Build an instance from an unscaled BigInteger.

Parameters
unscaledVal:BigInteger

unscaled value

scale:int

scale to use

mc:MathContext

to used

BigRealback to summary
public BigReal(BigInteger val, MathContext mc)

Build an instance from a BigInteger.

Parameters
val:BigInteger

value of the instance

mc:MathContext

context to use

BigRealback to summary
public BigReal(char[] in)

Build an instance from a characters representation.

Parameters
in:char[]

character representation of the value

BigRealback to summary
public BigReal(char[] in, int offset, int len)

Build an instance from a characters representation.

Parameters
in:char[]

character representation of the value

offset:int

offset of the first character to analyze

len:int

length of the array slice to analyze

BigRealback to summary
public BigReal(char[] in, int offset, int len, MathContext mc)

Build an instance from a characters representation.

Parameters
in:char[]

character representation of the value

offset:int

offset of the first character to analyze

len:int

length of the array slice to analyze

mc:MathContext

context to use

BigRealback to summary
public BigReal(char[] in, MathContext mc)

Build an instance from a characters representation.

Parameters
in:char[]

character representation of the value

mc:MathContext

context to use

BigRealback to summary
public BigReal(double val)

Build an instance from a double.

Parameters
val:double

value of the instance

BigRealback to summary
public BigReal(double val, MathContext mc)

Build an instance from a double.

Parameters
val:double

value of the instance

mc:MathContext

context to use

BigRealback to summary
public BigReal(int val)

Build an instance from an int.

Parameters
val:int

value of the instance

BigRealback to summary
public BigReal(int val, MathContext mc)

Build an instance from an int.

Parameters
val:int

value of the instance

mc:MathContext

context to use

BigRealback to summary
public BigReal(long val)

Build an instance from a long.

Parameters
val:long

value of the instance

BigRealback to summary
public BigReal(long val, MathContext mc)

Build an instance from a long.

Parameters
val:long

value of the instance

mc:MathContext

context to use

BigRealback to summary
public BigReal(String val)

Build an instance from a String representation.

Parameters
val:String

character representation of the value

BigRealback to summary
public BigReal(String val, MathContext mc)

Build an instance from a String representation.

Parameters
val:String

character representation of the value

mc:MathContext

context to use

Method Detail

addback to summary
public BigReal add(BigReal a)

Implements org.apache.commons.math3.FieldElement.add.

Doc from org.apache.commons.math3.FieldElement.add.

Compute this + a.

Parameters
a:BigReal

element to add

Returns:BigReal

a new element representing this + a

bigDecimalValueback to summary
public BigDecimal bigDecimalValue()

Get the BigDecimal value corresponding to the instance.

Returns:BigDecimal

BigDecimal value corresponding to the instance

compareToback to summary
public int compareTo(BigReal a)

Implements java.lang.Comparable.compareTo.

Doc from java.lang.Comparable.compareTo.

Compares this object with the specified object for order. Returns a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object.

The implementor must ensure signum(x.compareTo(y)) == -signum(y.compareTo(x)) for all x and y. (This implies that x.compareTo(y) must throw an exception if and only if y.compareTo(x) throws an exception.)

The implementor must also ensure that the relation is transitive: (x.compareTo(y) > 0 && y.compareTo(z) > 0) implies x.compareTo(z) > 0.

Finally, the implementor must ensure that x.compareTo(y)==0 implies that signum(x.compareTo(z)) == signum(y.compareTo(z)), for all z.

Parameters
a:BigReal

the object to be compared.

Returns:int

a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object.

divideback to summary
public BigReal divide(BigReal a) throws MathArithmeticException

Implements org.apache.commons.math3.FieldElement.divide.

Doc from org.apache.commons.math3.FieldElement.divide.

Compute this ÷ a.

Parameters
a:BigReal

element to divide by

Returns:BigReal

a new element representing this ÷ a

Exceptions
MathArithmeticException:
if a is zero
doubleValueback to summary
public double doubleValue()

Get the double value corresponding to the instance.

Returns:double

double value corresponding to the instance

equalsback to summary
public boolean equals(Object other)

Overrides java.lang.Object.equals.

Doc from java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.

The equals method implements an equivalence relation on non-null object references:

  • It is reflexive: for any non-null reference value x, x.equals(x) should return true.
  • It is symmetric: for any non-null reference values x and y, x.equals(y) should return true if and only if y.equals(x) returns true.
  • It is transitive: for any non-null reference values x, y, and z, if x.equals(y) returns true and y.equals(z) returns true, then x.equals(z) should return true.
  • It is consistent: for any non-null reference values x and y, multiple invocations of x.equals(y) consistently return true or consistently return false, provided no information used in equals comparisons on the objects is modified.
  • For any non-null reference value x, x.equals(null) should return false.

An equivalence relation partitions the elements it operates on into equivalence classes; all the members of an equivalence class are equal to each other. Members of an equivalence class are substitutable for each other, at least for some purposes.

Parameters
other:Object

the reference object with which to compare.

Returns:boolean

true if this object is the same as the obj argument; false otherwise.

Annotations
@Override
getFieldback to summary
public Field<BigReal> getField()

Implements org.apache.commons.math3.FieldElement.getField.

Doc from org.apache.commons.math3.FieldElement.getField.

Get the Field to which the instance belongs.

Returns:Field<BigReal>

Field to which the instance belongs

getRoundingModeback to summary
public RoundingMode getRoundingMode()

Gets the rounding mode for division operations The default is RoundingMode.HALF_UP

Returns:RoundingMode

the rounding mode.

Since
2.1
getScaleback to summary
public int getScale()

Sets the scale for division operations. The default is 64

Returns:int

the scale

Since
2.1
hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

Doc from java.lang.Object.hashCode.

Returns a hash code value for this object. This method is supported for the benefit of hash tables such as those provided by java.util.HashMap.

The general contract of hashCode is:

  • Whenever it is invoked on the same object more than once during an execution of a Java application, the hashCode method must consistently return the same integer, provided no information used in equals comparisons on the object is modified. This integer need not remain consistent from one execution of an application to another execution of the same application.
  • If two objects are equal according to the equals method, then calling the hashCode method on each of the two objects must produce the same integer result.
  • It is not required that if two objects are unequal according to the equals method, then calling the hashCode method on each of the two objects must produce distinct integer results. However, the programmer should be aware that producing distinct integer results for unequal objects may improve the performance of hash tables.
Returns:int

a hash code value for this object

Annotations
@Override
multiplyback to summary
public BigReal multiply(BigReal a)

Implements org.apache.commons.math3.FieldElement.multiply.

Doc from org.apache.commons.math3.FieldElement.multiply.

Compute this × a.

Parameters
a:BigReal

element to multiply

Returns:BigReal

a new element representing this × a

multiplyback to summary
public BigReal multiply(final int n)

Implements org.apache.commons.math3.FieldElement.multiply, org.apache.commons.math3.FieldElement.multiply.

Doc from org.apache.commons.math3.FieldElement.multiply.

Compute n × this. Multiplication by an integer number is defined as the following sum

n × this = ∑i=1n this.
Parameters
n:int

Number of times this must be added to itself.

Returns:BigReal

A new element representing n × this.

negateback to summary
public BigReal negate()

Implements org.apache.commons.math3.FieldElement.negate.

Doc from org.apache.commons.math3.FieldElement.negate.

Returns the additive inverse of this element.

Returns:BigReal

the opposite of this.

reciprocalback to summary
public BigReal reciprocal() throws MathArithmeticException

Implements org.apache.commons.math3.FieldElement.reciprocal.

Doc from org.apache.commons.math3.FieldElement.reciprocal.

Returns the multiplicative inverse of this element.

Returns:BigReal

the inverse of this.

Exceptions
MathArithmeticException:
if this is zero
setRoundingModeback to summary
public void setRoundingMode(RoundingMode roundingMode)

Sets the rounding mode for decimal divisions.

Parameters
roundingMode:RoundingMode

rounding mode for decimal divisions

Since
2.1
setScaleback to summary
public void setScale(int scale)

Sets the scale for division operations.

Parameters
scale:int

scale for division operations

Since
2.1
subtractback to summary
public BigReal subtract(BigReal a)

Implements org.apache.commons.math3.FieldElement.subtract.

Doc from org.apache.commons.math3.FieldElement.subtract.

Compute this - a.

Parameters
a:BigReal

element to subtract

Returns:BigReal

a new element representing this - a