Package dev.nm.number
Class Real
- java.lang.Object
-
- java.lang.Number
-
- dev.nm.number.Real
-
- All Implemented Interfaces:
AbelianGroup<Real>,Field<Real>,Monoid<Real>,Ring<Real>,Serializable,Comparable<Real>
- Direct Known Subclasses:
VariancebtX
public class Real extends Number implements Field<Real>, Comparable<Real>
A real number is an arbitrary precision number. This implementation is simply a wrapper aroundBigDecimaland implements theFieldinterface. This class is immutable.- See Also:
- Serialized Form
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface dev.nm.algebra.structure.Field
Field.InverseNonExistent
-
-
Constructor Summary
Constructors Constructor Description Real(double value)Construct aRealfrom adouble.Real(long value)Construct aRealfrom an integer.Real(String value)Construct aRealfrom aString.Real(BigDecimal value)Construct aRealfrom aBigDecimal.Real(BigInteger value)Construct aRealfrom aBigInteger.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Realadd(Real that)+ : G × G → GintcompareTo(Real that)Realdivide(Real that)/ : F × F → FRealdivide(Real that, int scale)/ : R × R → RdoubledoubleValue()booleanequals(Object obj)floatfloatValue()inthashCode()intintValue()Realinverse()For each a in F, there exists an element b in F such that a × b = b × a = 1.longlongValue()Realminus(Real that)- : G × G → GRealmultiply(Real that)× : G × G → GRealONE()The multiplicative element 1 in the group such that for any elements a in the group, the equation 1 × a = a × 1 = a holds.Realopposite()For each a in G, there exists an element b in G such that a + b = b + a = 0.BigDecimaltoBigDecimal()Convert this number to aBigDecimal.StringtoString()RealZERO()The additive element 0 in the group, such that for all elements a in the group, the equation 0 + a = a + 0 = a holds.-
Methods inherited from class java.lang.Number
byteValue, shortValue
-
-
-
-
Constructor Detail
-
Real
public Real(double value)
Construct aRealfrom adouble.- Parameters:
value- adouble
-
Real
public Real(long value)
Construct aRealfrom an integer.- Parameters:
value- an integer
-
Real
public Real(BigDecimal value)
Construct aRealfrom aBigDecimal.- Parameters:
value- aBigDecimal
-
Real
public Real(BigInteger value)
Construct aRealfrom aBigInteger.- Parameters:
value- aBigInteger
-
Real
public Real(String value)
Construct aRealfrom aString.- Parameters:
value- aStringrepresentation of a number
-
-
Method Detail
-
toBigDecimal
public BigDecimal toBigDecimal()
Convert this number to aBigDecimal.- Returns:
- the value in
BigDecimal
-
floatValue
public float floatValue()
- Specified by:
floatValuein classNumber
-
doubleValue
public double doubleValue()
- Specified by:
doubleValuein classNumber
-
add
public Real add(Real that)
Description copied from interface:AbelianGroup+ : G × G → G- Specified by:
addin interfaceAbelianGroup<Real>- Parameters:
that- the object to be added- Returns:
- this + that
-
minus
public Real minus(Real that)
Description copied from interface:AbelianGroup- : G × G → G The operation "-" is not in the definition of of an additive group but can be deduced. This function is provided for convenience purpose. It is equivalent to
.this.add(that.opposite())- Specified by:
minusin interfaceAbelianGroup<Real>- Parameters:
that- the object to be subtracted (subtrahend)- Returns:
- this - that
-
opposite
public Real opposite()
Description copied from interface:AbelianGroupFor each a in G, there exists an element b in G such that a + b = b + a = 0. That is, it is the object such asthis.add(this.opposite()) == this.ZERO- Specified by:
oppositein interfaceAbelianGroup<Real>- Returns:
- -this, the additive opposite
- See Also:
- Wikipedia: Additive inverse
-
divide
public Real divide(Real that)
Description copied from interface:Field/ : F × F → F That is the same asthis.multiply(that.inverse())
-
divide
public Real divide(Real that, int scale)
/ : R × R → R Divide this number by another one. Rounding is performed with the specifiedscale.- Parameters:
that- another non-zero real numberscale- rounding scale as inBigDecimal- Returns:
- this/that
-
inverse
public Real inverse() throws Field.InverseNonExistent
Description copied from interface:FieldFor each a in F, there exists an element b in F such that a × b = b × a = 1. That is, it is the object such asthis.multiply(this.inverse()) == this.ONE- Specified by:
inversein interfaceField<Real>- Returns:
- 1 / this if it exists
- Throws:
Field.InverseNonExistent- if the inverse does not exist- See Also:
- Wikipedia: Multiplicative inverse
-
ZERO
public Real ZERO()
Description copied from interface:AbelianGroupThe additive element 0 in the group, such that for all elements a in the group, the equation 0 + a = a + 0 = a holds.- Specified by:
ZEROin interfaceAbelianGroup<Real>- Returns:
- 0, the additive identity
-
ONE
public Real ONE()
Description copied from interface:MonoidThe multiplicative element 1 in the group such that for any elements a in the group, the equation 1 × a = a × 1 = a holds.
-
compareTo
public int compareTo(Real that)
- Specified by:
compareToin interfaceComparable<Real>
-
-