public class Real extends Number implements Field<Real>, Comparable<Real>
BigDecimal
and implements the Field
interface.
This class is immutable.Field.InverseNonExistent
Modifier and Type | Field and Description |
---|---|
static Real |
ONE
a number representing 1
|
static Real |
ZERO
a number representing 0
|
Constructor and Description |
---|
Real(BigDecimal value)
Construct a
Real from a BigDecimal . |
Real(BigInteger value)
Construct a
Real from a BigInteger . |
Real(double value)
Construct a
Real from a double . |
Real(long value)
Construct a
Real from an integer. |
Real(String value)
Construct a
Real from a String . |
Modifier and Type | Method and Description |
---|---|
Real |
add(Real that)
+ : G × G → G
|
int |
compareTo(Real that) |
Real |
divide(Real that)
/ : F × F → F
That is the same as
this.multiply(that.inverse()) |
Real |
divide(Real that,
int scale)
/ : R × R → R
Divide this number by another one.
|
double |
doubleValue() |
boolean |
equals(Object obj) |
float |
floatValue() |
int |
hashCode() |
int |
intValue() |
Real |
inverse()
For each a in F, there exists an element b in F such that
a × b = b × a = 1.
|
long |
longValue() |
Real |
minus(Real that)
- : G × G → G
The operation "-" is not in the definition of of an additive group but can be deduced.
|
Real |
multiply(Real that)
× : G × G → G
|
Real |
ONE()
The multiplicative element 1 in the group such that for any elements a in the group,
the equation 1 × a = a × 1 = a holds.
|
Real |
opposite()
For each a in G, there exists an element b in G such that
a + b = b + a = 0.
|
BigDecimal |
toBigDecimal()
Convert this number to a
BigDecimal . |
String |
toString() |
Real |
ZERO()
The additive element 0 in the group, such that for all elements a in the group,
the equation 0 + a = a + 0 = a holds.
|
byteValue, shortValue
public static final Real ZERO
public static final Real ONE
public Real(double value)
Real
from a double
.value
- a double
public Real(long value)
Real
from an integer.value
- an integerpublic Real(BigDecimal value)
Real
from a BigDecimal
.value
- a BigDecimal
public Real(BigInteger value)
Real
from a BigInteger
.value
- a BigInteger
public Real(String value)
Real
from a String
.value
- a String
representation of a numberpublic BigDecimal toBigDecimal()
BigDecimal
.BigDecimal
public float floatValue()
floatValue
in class Number
public double doubleValue()
doubleValue
in class Number
public Real add(Real that)
AbelianGroup
add
in interface AbelianGroup<Real>
that
- the object to be addedpublic Real minus(Real that)
AbelianGroup
this.add(that.opposite())
.minus
in interface AbelianGroup<Real>
that
- the object to be subtracted (subtrahend)public Real opposite()
AbelianGroup
this.add(this.opposite()) == this.ZERO
opposite
in interface AbelianGroup<Real>
public Real divide(Real that)
Field
this.multiply(that.inverse())
public Real divide(Real that, int scale)
scale
.that
- another non-zero real numberscale
- rounding scale as in BigDecimal
public Real inverse() throws Field.InverseNonExistent
Field
this.multiply(this.inverse()) == this.ONE
inverse
in interface Field<Real>
Field.InverseNonExistent
- if the inverse does not existpublic Real ZERO()
AbelianGroup
ZERO
in interface AbelianGroup<Real>
public Real ONE()
Monoid
public int compareTo(Real that)
compareTo
in interface Comparable<Real>
Copyright © 2010-2020 NM FinTech Ltd.. All Rights Reserved.