|
|||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||
java.lang.Objectcom.rubecula.util.Item
com.rubecula.jquantity.BaseNumber
com.rubecula.jquantity.Approximation
This Class approximates a value using an immutable double-precision value. Note that this class is limited in its ability to store large numbers. For such numbers, or for numbers which are rational, Rational should be used. This Class should only be used for the results of applying arbitrary mathematical functions to numbers - such numbers are generally less precise than is possible with double precision in any case, so this class is normally adequate - provided that the size limit is not exceeded.
| Field Summary | |
private double |
_Bound
_Bound is the relative value of the estimate of the size of any error in the value itself (according to the model). |
private int |
_Model
_Model is the distribution model of possible errors in the value itself. |
private double |
_Value
The value of this approximation. |
(package private) static Approximation |
$_Alpha
The fine structure constant, Alpha (dimensionless). |
(package private) static Approximation |
$_au
Astronomical Unit (approx): 1.49597893*E11. |
(package private) static Approximation |
$_e
Electron charge (in Coulombs) Value: 1.60217653(14)E-19. |
(package private) static Approximation |
$_G
Gravitation constant (in m^3 kg^-1 sec^-2) Value: 6.6742(10) x 10-11 Relative Error: 1.5E-4. |
(package private) static Approximation |
$_R
Rydberg constant (in per meters). |
static Approximation |
$1
The constant value of 1 (exact). |
private static double |
$1_Rt10
// TODO move this to end of file and check still OK |
static Approximation |
$e
The constant value of e (best double-precision approximation). |
static Approximation |
$pi
The constant value of pi (best double-precision approximation), |
(package private) static int |
$PrecisionDouble
Number of significant figures held by doubles: 15 [pessimistic by half a place - 52 bits are used for mantissa] |
(package private) static int |
$PrecisionFloat
Number of significant figures held by floats: 7 [pessimistic I think] |
private static double |
ERROR_ADD
The relative error bounds for the double add operation. |
private static double |
ERROR_ATAN
The relative error bounds for the arctan operation. |
private static double |
ERROR_DIV
The relative error bounds for the double divide operation. |
private static double |
ERROR_EXP
The relative error bounds for the exponential operation. |
private static double |
ERROR_LOG
The relative error bounds for the natural logarithm operation. |
private static double |
ERROR_MUL
The relative error bounds for the double multiply operation. |
private static double |
ERROR_TAN
The relative error bounds for the tangent operation. |
| Fields inherited from class com.rubecula.jquantity.BaseNumber |
|
| Fields inherited from class com.rubecula.util.Item |
JQUANTITY_TEST |
| Fields inherited from interface com.rubecula.jquantity.Fuzzy |
$DistGaussian, $DistInvalid, $DistNone, $DistUniform, $Names |
| Constructor Summary | |
protected |
Approximation()
Constructor to create a new (exact) Approximation with value 0. |
|
Approximation(BaseNumber value)
Primary constructor to create a new Approximation equivalent to a given BaseNumber. |
|
Approximation(double value)
Primary constructor to create a new (exact) Approximation. |
|
Approximation(double value,
double boundRel)
Primary constructor to create a new Approximation. |
|
Approximation(double value,
double boundRel,
int model)
Primary constructor to create a new Approximation. |
| Method Summary | |
Trigonometrical |
arctanX2()
Method to evaluate the arctangent function. |
Trigonometrical |
arctanX2(Approximation divisor)
Method to evaluate the arctangent function of this divided by divisor. |
java.lang.String |
audit(java.lang.String label)
Method to return a detailed string from an arithmetical object for debugging purposes. |
double |
doubleValue()
Method to get the value of this approximation. |
Trigonometrical |
exp()
Method to evaluate the exponential function. |
Divisible |
factored(double factor)
Method to yield the quotient of this divided by factor, and return it as the result. |
float |
floatValue()
Method to yield this value as a float. |
double |
getBound()
Method to get the relative bound of this Rational. |
double |
getBoundAbs()
Method to get the absolute bound of non-fuzzy value. |
double |
getEstimate()
Method to get the current estimate of an arithmetical value. |
java.lang.String |
getIdentifier()
Get an identifier for this object. |
int |
getModel()
Method to get the error distribution model of this non-fuzzy object. |
private static Approximation |
InitialValueOf(java.lang.String string)
Private class method to create an approximation from a string which represents a double, optionally followed by "*" to indicate fuzziness in the last digit. |
(package private) static double |
IntrinsicError()
Method to get the intrinsic error of an ordinary double number. |
(package private) static double |
IntrinsicError(int halfplaces)
Method to get the intrinsic error of a number accurate to 1/2 half-places significant figures. |
int |
intValue()
If possible, get the integer value of this approximation. |
Divisible |
inverse()
Method to yield the reciprocal of this and return it as the result. |
boolean |
isExact()
Method to determine if the quantity represented is non-fuzzy; |
boolean |
isInfinite()
Method to determine if this value is infinite. |
boolean |
isInteger()
Method to determine if this object is an integer. |
boolean |
isUnity()
Method to determine if this is equal to the value 1. |
Trigonometrical |
log()
Method to evaluate the natural log function. |
long |
longValue()
If possible, get the long value of this approximation. |
static void |
main(java.lang.String[] args)
Test program. |
Presentable |
makePresentableInstance(Presentation presentation)
Instance method to convert a Presentation into a Presentable. |
protected BaseNumber |
minus()
Method to return this but with changed sign. |
static Approximation |
Parse(NumberPresentation presentation)
Class method to translate the NumberPresentation representation into an Approximation. |
protected BaseNumber |
pow(double power)
Method to yield the value of this to a power. |
protected BaseNumber |
pow(int power)
Method to yield the value of this to a power. |
Presentation |
present(AttrMap attributes)
Convert this Presentable object into a Presentation, according to the set of attributes provided. |
protected BaseNumber |
product(BaseNumber multiplicand)
Method to yield the product of this approximation with a BaseNumber. |
Divisible |
quotient(BaseNumber divisor)
Method to yield the quotient of this approximation divided by a BaseNumber. |
(package private) static double |
RootSumSquare(double x,
double y)
General method to yield the root-sum-square of two numbers, or in other words the length of the hyponteneuse of a right-angled triangle where x and y are the lengths of the two sides of the triange which include the right angle. |
protected BaseNumber |
scaled(long factor)
Method to yield the result of scaling an approximation by a factor. |
int |
signum()
Method to get the sign of this approximation. |
protected BaseNumber |
square()
Method to yield the square of this value. |
protected BaseNumber |
sum(BaseNumber addend)
Method to yield the sum of this approximation with a BaseNumber. |
Trigonometrical |
tan_theta_2()
Method to evaluate the tangent function. |
(package private) void |
test(java.io.PrintStream output,
java.lang.String name)
|
java.lang.String |
toString()
Method to represent this object as a string. |
void |
updateEstimate()
No-op method to update the current estimate. |
static BaseNumber |
valueOf(java.lang.String valueString)
Method to create an approximation from a string which represents a double, optionally followed by "*" to indicate fuzziness in the last digit. |
| Methods inherited from class com.rubecula.jquantity.BaseNumber |
abs, bestModel, BestModel, byteValue, characteristic, Characteristic, difference, impartFuzziness, isEqual, isUncertain, isZero, shortValue, valueOf, valueOfLog10 |
| Methods inherited from class com.rubecula.util.Item |
audit, audit, compareTo, Debug, getClassNameShort, getType, IsDebug, present, SetDebug, test, test, Wrap |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Methods inherited from interface com.rubecula.util.Auditable |
audit, audit |
| Field Detail |
public static final Approximation $1
public static final Approximation $pi
Math.PIpublic static final Approximation $e
Math.Estatic final Approximation $_R
static final Approximation $_Alpha
static final Approximation $_e
static final Approximation $_G
static final Approximation $_au
static final int $PrecisionDouble
static final int $PrecisionFloat
private static final double $1_Rt10
private final double _Value
private final double _Bound
private final int _Model
private static final double ERROR_ADD
private static final double ERROR_MUL
private static final double ERROR_DIV
private static final double ERROR_EXP
private static final double ERROR_LOG
private static final double ERROR_TAN
private static final double ERROR_ATAN
| Constructor Detail |
public Approximation(double value,
double boundRel,
int model)
value - the closest known value to the quantity to be represented.boundRel - the relative error bound on the value.model - the error distribution model.
public Approximation(double value,
double boundRel)
value - the closest known value to the quantity to be represented.boundRel - the relative error bound on the value.public Approximation(double value)
value - the closest known value to the quantity to be represented.public Approximation(BaseNumber value)
value - the equivalent Approximation to value.protected Approximation()
| Method Detail |
public static BaseNumber valueOf(java.lang.String valueString)
throws PresentationException
valueString - The string representation of a double, optionally followed by
"*".
PresentationException - problem parsing valueString.private static Approximation InitialValueOf(java.lang.String string)
valueOf(String), printing any exception thrown on System.err.
It is used for class initializations of values.
string - The string representation of a double, optionally followed by
"*".
public static Approximation Parse(NumberPresentation presentation)
throws PresentationException
presentation - NumberPresentation representation of an approximation.
PresentationException - if presentation cannot be parsed as an
Approximation.public void updateEstimate()
updateEstimate in interface Estimablepublic double getEstimate()
getEstimate in interface Estimablepublic Divisible inverse()
inverse in interface Divisiblepublic Divisible quotient(BaseNumber divisor)
quotient in interface Divisibledivisor - the number to divide into this.
java.lang.RuntimeException - if the divisor is zero.public Divisible factored(double factor)
factored in interface Divisiblefactor - the scale factor.
public double getBoundAbs()
getBoundAbs in class BaseNumberBaseNumber.getBound(),
BaseNumber.doubleValue(),
Math.abs(double)public double getBound()
getBound in interface FuzzygetBound in class BaseNumberpublic int getModel()
getModel in interface FuzzygetModel in class BaseNumberpublic boolean isExact()
isExact in interface FuzzyisExact in class BaseNumberpublic boolean isInteger()
isInteger in interface Arithmeticalprotected BaseNumber scaled(long factor)
scaled in class BaseNumberfactor - a long integer which is to be multiplied by this.
protected BaseNumber product(BaseNumber multiplicand)
product in class BaseNumbermultiplicand - the number to multiply into this.
public java.lang.String getIdentifier()
getIdentifier in interface Identifiablepublic int intValue()
longValue().
intValue in class BaseNumberjava.lang.RuntimeException - the integer is out of range.
java.lang.RuntimeException - this is not equivalent to an long (i.e. not integral).public long longValue()
longValue in class BaseNumberjava.lang.RuntimeException - this is not equivalent to an long (i.e. not integral).protected BaseNumber sum(BaseNumber addend)
sum in class BaseNumberaddend - the number to add to this.
public int signum()
signum in interface Arithmeticalpublic double doubleValue()
doubleValue in class BaseNumberpublic boolean isInfinite()
isInfinite in interface Arithmeticalpublic java.lang.String audit(java.lang.String label)
audit in interface Auditablelabel - String: the label to associate with the data.
public boolean isUnity()
isUnity in interface Arithmetical
public Presentation present(AttrMap attributes)
throws PresentationException
Presentable
present in interface Presentableattributes - the map of attributes required for the resulting
presentation.
PresentationException - if unable to parse appropriately.public Trigonometrical exp()
log().
exp in interface Trigonometricalpublic Trigonometrical log()
exp().
log in interface Trigonometricaljava.lang.RuntimeException - if this is not positive.public Trigonometrical arctanX2(Approximation divisor)
tan_theta_2().
divisor - the divisor of the value from which to take twice the
arctangent.
public Trigonometrical arctanX2()
tan_theta_2().
arctanX2 in interface Trigonometricalpublic Trigonometrical tan_theta_2()
arctanX2().
tan_theta_2 in interface Trigonometricalprotected BaseNumber square()
protected BaseNumber pow(int power)
pow in class BaseNumberpower - the power to which this must be raised.
protected BaseNumber pow(double power)
power - the power to which this must be raised.
public Presentable makePresentableInstance(Presentation presentation)
throws PresentationException
makePresentableInstance in interface Presentablepresentation - a NumberPresentation to be converted into an Approximation.
PresentationException - in case of parsing error or if the presentation is not a
NumberPresentation.public float floatValue()
floatValue in class BaseNumberprotected BaseNumber minus()
minus in class BaseNumberpublic java.lang.String toString()
toString in class ItemItem.present(),
Presentation.toString()
void test(java.io.PrintStream output,
java.lang.String name)
public static void main(java.lang.String[] args)
args - ignored.static double IntrinsicError(int halfplaces)
halfplaces - the number of significant half-places (must be positive).
static double IntrinsicError()
static double RootSumSquare(double x,
double y)
x - either of the two numbers (order is immaterial).y - the other of the two numbers.
|
|||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||