|
JADE v6.1 | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjava.lang.Number
com.dautelle.math.numbers.RealtimeNumber
com.dautelle.math.numbers.Real
This class represents a real number of arbitrary precision with
known/guaranteed uncertainty. A real number consists of a
mantissa
, a maximum error
(on the mantissa) and a decimal exponent
:
((mantissa ± error) · 10exponent
).
The decimal representations of real instances are indicative of
their precision as only digits guaranteed to be exact are written out.
For example, the string "2.000"
represents a real
value of (2.0 ± 0.001)
.
The precision
or accuracy
of any real number is available and guaranteed
(the true/exact value is always within the precision/accuracy range).
Operations on instances of this class are quite fast as information substantially below the precision level (aka noise) is not processed/stored. There is no limit on a real precision but precision degenerates (due to numeric errors) and calculations accelerate as more and more operations are performed.
Instances of this class can be utilized to find approximate
solutions to linear equations using the Matrix
class for which
high-precision reals is often required, the primitive type
double
being not accurate enough to resolve equations
when the matrix's size exceeds 100x100. Furthermore, even for small
matrices the "qualified" result is indicative of possible system
singularities.
Nested Class Summary | |
static class |
Real.Value
This inner class represents a mutable image of an immutable Real . |
Nested classes inherited from class com.dautelle.math.numbers.RealtimeNumber |
RealtimeNumber.Factory |
Field Summary | |
static Real |
NaN
Holds a Not-a-Number instance (infinite error). |
Method Summary | |
Real |
abs()
Returns the absolute value of this real number. |
Real |
add(Real that)
Returns the sum of this real number with the one specified. |
java.lang.StringBuffer |
appendTo(java.lang.StringBuffer sb)
Appends the decimal text representation of this real number to the StringBuffer argument. |
boolean |
approxEquals(Real that)
Indicates if this real is approximately equals to the one specified. |
int |
compareTo(java.lang.Object that)
Compares two real numbers numerically. |
Real |
divide(Real that)
Returns this real number divided by the one specified. |
double |
doubleValue()
Returns the value of this real number as a double . |
boolean |
equals(java.lang.Object that)
Compares this real number against the specified object. |
java.lang.Object |
export()
Exports this object out of the current pool context. |
float |
floatValue()
Returns the value of this real number as a float . |
int |
getAccuracy()
Returns the number of decimal digits guaranteed exact which appear to the right of the decimal point (absolute error). |
LargeInteger |
getError()
Returns the maximum error (positive) on this real's mantissa. |
int |
getExponent()
Returns the exponent of the power of 10 multiplier. |
LargeInteger |
getMantissa()
Returns this real's mantissa. |
int |
getPrecision()
Returns the total number of decimal digits guaranteed exact (relative error). |
int |
hashCode()
Returns the hash code for this real number. |
int |
intValue()
Returns the value of this real number as an int . |
Real |
inverse()
Returns the inverse of this real number. |
boolean |
isNaN()
Indicates if this real is Not-a-Number (unbounded value interval). |
boolean |
isNegative()
Indicates if this real is less than zero. |
boolean |
isPositive()
Indicates if this real is greater than zero. |
long |
longValue()
Returns the value of this real number as a long . |
Real |
multiply(Real that)
Returns the product of this real number with the one specified. |
Real |
negate()
Returns the negation of this real number. |
Operable |
opposite()
Returns the additive inverse of this object. |
Operable |
plus(Operable that)
Returns the sum of this object with the one specified. |
Operable |
reciprocal()
Returns the multiplicative inverse of this object. |
static void |
setIntegerAccuracy(int accuracy)
Sets the local number of decimal zeros
in the fraction part for reals created from integer values
(default 18 zeros). |
Real |
subtract(Real that)
Returns the difference between this real number and the one specified. |
Operable |
times(Operable that)
Returns the product of this object with the one specified. |
java.lang.Object |
toHeap()
Moves this object to the heap. |
LargeInteger |
toLargeInteger()
Converts this real to a LargeInteger instance. |
java.lang.String |
toString()
Returns the decimal text representation of this real number. |
void |
toXml(XmlElement xml)
Sets the attributes and content of the XML element corresponding to this object. |
static Real |
valueOf(java.lang.CharSequence chars)
Returns the real for the specified character sequence. |
static Real |
valueOf(double doubleValue)
Converts a double value to a real instance. |
static Real |
valueOf(LargeInteger integer)
Converts an integer value to a real instance. |
static Real |
valueOf(LargeInteger mantissa,
LargeInteger error,
int exponent)
Returns a real having the specified mantissa, error and exponent values. |
static Real |
valueOf(long integer)
Converts an integer value to a real instance. |
static Real |
valueOf(XmlElement xml)
XML factory method. |
Methods inherited from class com.dautelle.math.numbers.RealtimeNumber |
clone, isLocalObject, isPoolObject, pow, recycle |
Methods inherited from class java.lang.Number |
byteValue, shortValue |
Methods inherited from class java.lang.Object |
finalize, getClass, notify, notifyAll, wait, wait, wait |
Field Detail |
public static final Real NaN
Method Detail |
public static Real valueOf(LargeInteger mantissa, LargeInteger error, int exponent)
// x = 0.0 ± 0.01 ("0.00" or "0E-2") Real x = Real.valueOf(LargeInteger.ZERO, LargeInteger.ONE, -2); // y = -12.3 ± 0.005 ("-12300±5E-3") Real y = Real.valueOf(LargeInteger.valueOf("-12300"), LargeInteger.valueOf("5"), -3); // The real 1.0 with an accuracy of 100 digits. Real one = Real.valueOf(LargeInteger.ONE.E(100), LargeInteger.ONE, -100);
mantissa
- this real mantissa.error
- the maximum error on the mantissa.exponent
- the decimal exponent.
(mantissa ± error)·10exponent)
java.lang.IllegalArgumentException
- if error <= 0
public static Real valueOf(java.lang.CharSequence chars) throws java.lang.NumberFormatException
±
symbol),
the number of digits is characteristic of the precision.
Example of valid character sequences for 1.2 ± 0.001
:
chars
- the character sequence.
java.lang.NumberFormatException
- if the character sequence does not contain
a parsable real.public static Real valueOf(double doubleValue)
double
value to a real instance.
The error is derived from the inexact representation of
double
values intrinsic to the 64 bits IEEE 754 format.
doubleValue
- the double
value to convert.public static Real valueOf(long integer)
integer
accuracy
setting.
integer
- the integer value to convert.
public static Real valueOf(LargeInteger integer)
integer
accuracy
setting.
integer
- the integer value to convert.
public static Real valueOf(XmlElement xml)
xml
- the XML element describing the real to return
(e.g. <math:Real value="1.23000"/>
).
valueOf(CharSequence)
public static void setIntegerAccuracy(int accuracy)
local
number of decimal zeros
in the fraction part for reals created from integer values
(default 18
zeros).
accuracy
- the accuracy of reals created from integer values.valueOf(long)
,
valueOf(LargeInteger)
public LargeInteger getMantissa()
public LargeInteger getError()
null
if this isNaN()
.
null
if
this.isNaN()
public int getExponent()
public int getAccuracy()
public final int getPrecision()
public boolean isPositive()
this > 0
public boolean isNegative()
this < 0
public boolean isNaN()
true
if this number has unbounded value interval;
false
otherwise.public boolean approxEquals(Real that)
Note: This method returns false
if this
or
that
isNaN()
.
that
- the real to compare with.
this ≈ that
public LargeInteger toLargeInteger()
LargeInteger
instance.
Any fractional part of this real is discarded.
java.lang.ArithmeticException
- if this.isNaN()
public Real negate()
-this
.public Real add(Real that)
that
- the real to be added.
this + that
.public Real subtract(Real that)
that
- the real to be subtracted.
this - that
.public Real multiply(Real that)
that
- the real multiplier.
this * that
.public Real divide(Real that)
that
- the real divisor.
this / that
.
java.lang.ArithmeticException
- if that.equals(ZERO)
public final Real inverse()
1 / this
.public Real abs()
abs(this)
.public java.lang.StringBuffer appendTo(java.lang.StringBuffer sb)
StringBuffer
argument. Only digits guaranteed to be exact
are written.
sb
- the StringBuffer
to append.
StringBuffer
.public java.lang.String toString()
appendTo(new StringBuffer()).toString()
appendTo(java.lang.StringBuffer)
public boolean equals(java.lang.Object that)
that
- the object to compare with.
true
if the objects are the same;
false
otherwise.public int hashCode()
public int intValue()
int
.
int
.public long longValue()
long
.
long
.public float floatValue()
float
.
float
.public double doubleValue()
double
.
double
.public int compareTo(java.lang.Object that)
compareTo
in interface java.lang.Comparable
that
- the real to compare with.
that
.
java.lang.ClassCastException
- that
is not a Real
.public Operable plus(Operable that)
Operable
plus
in interface Operable
that
- the object to be added.
this + that
.public Operable opposite()
Operable
this.plus(this.opposite()) == ZERO
,
with ZERO
being the additive identity.
opposite
in interface Operable
-this
.public Operable times(Operable that)
Operable
times
in interface Operable
that
- the object multiplier.
this * that
.public Operable reciprocal()
Operable
this.times(this.reciprocal()) == ONE
,
with ONE
being the multiplicative identity.
reciprocal
in interface Operable
ONE / this
.public void toXml(XmlElement xml)
Representable
toXml
in interface Representable
xml
- the XML element to set according to this object's desired XML
representation.public java.lang.Object export()
Realtime
Realtime
members are exported as well (recursion).
This method affects only objects belonging to the current pool context.
To avoid pool depletion, a "free" object from the outer pool
is moved to replace the object being exported.
export
in interface Realtime
export
in class RealtimeNumber
public java.lang.Object toHeap()
Realtime
Realtime
members are moved to the heap as well (recursion).
This method affects only objects belonging to a pool context
(current or not).
toHeap
in interface Realtime
toHeap
in class RealtimeNumber
|
JADE v6.1 | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |