|
|||||||||||
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.MutableNumber
com.rubecula.jquantity.DivisibleMutable
com.rubecula.jquantity.Rational
com.rubecula.jquantity.Value
This class represents a Rational which may be factored in some way. The most common usage is to allow the representation of angles as multiples of pi (scheme 1).
Nested Class Summary | |
private static class |
Value.transcendental2Arctan
|
private static class |
Value.transcendentalExp
|
private static class |
Value.transcendentalLog
|
private static class |
Value.transcendentalSqrt
|
private static class |
Value.transcendentalSquare
|
private static class |
Value.transcendentalTanThetaBy2
|
private static class |
Value.ValueException
|
Nested classes inherited from class com.rubecula.jquantity.Rational |
Rational.RValueException |
Field Summary | |
private int |
_Scheme
The factoring scheme used for this Value. |
static Value |
$0
The pure constant value 0. |
static Value |
$1
The pure constant value 1. |
static Value |
$2_Pi
The constant value 2pi (2 with factor pi). |
static Value |
$Angle_0
The constant angular value 0 (0 with factor pi). |
static Value |
$E
The constant value e (1 with factor e). |
static int |
$FactorE
The exponential factoring scheme: numbers represent themselves multiplied by e. |
static int |
$FactorInvE
The exponential factoring scheme: numbers represent themselves divided by e. |
static int |
$FactorInvPi
The angle factoring scheme: numbers represent themselves divided by pi. |
static int |
$FactorNone
The trivial factoring scheme: numbers represent themselves. |
static int |
$FactorPi
The angle factoring scheme: numbers represent themselves multiplied by pi. |
static Value |
$Infinity
The pure constant value representing infinity. |
static Value |
$Mu0
Vacuum permeability (in henry/meter or Newtons per square Ampere). |
static Value |
$Pi
The constant value pi (1 with factor pi). |
static Value |
$Pi_2
The constant value pi/2 (1/2 with factor pi). |
private static Rational[] |
ConversionFactors
The conversion factors for the various schemes, in order: 1, pi, e. |
private static java.lang.String[] |
Identifiers
The identifiers for the various schemes, in order: null, "pi", "e". |
Fields inherited from class com.rubecula.jquantity.Rational |
_Denominator, _Estimate, _Numerator, $_c, $_degF, $_degR, $_g, $_Log10_E, $_Pi_2, $_Pi_4, $_Tan15Deg, $_Tan22_5Deg, $_Tan30Deg, $1_2, $10, $12, $2, $3, $6, $NaN, $Rt2, $Rt3, $Rt5, $S_Rt2, $S_Rt3, $S_Rt5 |
Fields inherited from class com.rubecula.jquantity.MutableNumber |
$__1 |
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 | |
|
Value(Rational base)
Secondary constructor to instantiate a value, based on a given Rational (base) and factored with the trivial scheme ($FactorNone). |
|
Value(Rational base,
int scheme)
Secondary constructor to instantiate a Value, based on a given Rational (base) and factored with a specific scheme (scheme). |
|
Value(Rational base,
int scheme,
java.lang.String id)
Primary constructor to instantiate a Value, based on a given Rational (base) and factored with a specific scheme (scheme). |
protected |
Value(Value base)
Unused constructor. |
Method Summary | |
void |
add(BaseNumber that)
MUTATING Instance method to add another BaseNumber into this object. |
Trigonometrical |
arctanX2()
Method to evaluate the arctangent function. |
java.lang.String |
audit(java.lang.String label)
Method to return a detailed string from an arithmetical object for debugging purposes. |
void |
cast(int scheme)
Method to force the factoring scheme of this Value. |
Value |
castValue(int scheme)
Method to return a Value with factoring scheme: either this value itself or a copy which has been cast to have the specified factoring. |
protected void |
cftest(java.io.PrintStream out,
java.lang.Object check)
|
(package private) int |
characteristic()
Method to yield the characteristic of a BaseNumber. |
java.lang.Object |
clone()
Creates and returns a copy of this object. |
int |
compareTo(Value val)
Compares this Rational with the specified Rational. |
protected int |
compareTo(Value val,
boolean strict)
Compares this Rational with the specified Rational. |
void |
convert(int scheme)
Method to refactor the scheme of this Value. |
Value |
convertValue(int scheme)
Method to return a Value with factoring scheme: either this value itself or a copy which has been converted to have the specified factoring. |
java.lang.String |
defaultIdentifier()
Method to yield a defaultIdentifier in the case that none is given. |
(package private) Value |
differenceValue(Value subtrahend)
Method to yield the difference of this less a BaseNumber (subtrahend). |
void |
divide(BaseNumber that)
MUTATING method to replace this by the quotient of this and that |
double |
doubleValue()
Returns the value of the specified number as a double .
|
Trigonometrical |
exp()
Method to evaluate the exponential function. |
float |
floatValue()
Returns the value of the specified number as a float .
|
(package private) static Value |
FullCircles(int n)
|
double |
getBoundAbs()
Method to get the absolute bound of non-fuzzy value. |
private Rational |
getConversionFactor()
|
double |
getEstimate()
Method to get the current estimate of an arithmetical value. |
(package private) Value |
halfValue()
|
(package private) Value |
inverseValue()
|
void |
invert()
MUTATING Instance method to invert this (i.e. replace this by its reciprocal) |
boolean |
isNormal()
Method to determine if this instance is already normalized. |
boolean |
isUnity()
Method to determine if this Value object has the exact value of 1. |
Trigonometrical |
log()
Method to evaluate the natural log function. |
long |
longValue()
Method to yield the equivalent integer value for this object. |
(package private) long |
longValue(double tolerance)
Method to yield the integer value of this object. // TODO Check whether it should return long instead. |
(package private) double |
magnitude()
Method to yield the magnitude of this Rational as a double. |
static void |
main(java.lang.String[] args)
Main method for testing this class. |
Presentable |
makePresentableInstance(Presentation presentation)
Instance method to convert a Presentation into a Presentable. |
(package private) Value |
minusValue()
Method to yield a copy of this but with the sign changed. |
void |
multiply(BaseNumber that)
MUTATING Instance method to multiply another Arithmetical into this object. |
Value |
normalizeValue()
Method to return a Value with no factoring: either this value itself or a copy which has been converted to have no factoring. |
static Presentable |
Parse(Presentation presentation)
Method to create a Value from a Presentation and return it as a Presentable. |
static Rational |
Parse(SymbolicPresentation presentation,
java.lang.String identifier)
Class method to translate the given SymbolicPresentation representation of a Value into a Value. |
protected BaseNumber |
pow(double power)
Method to yield this raised to a double-precision power. |
Presentation |
present(AttrMap attributes)
Convert this Presentable object into a Presentation, according to the set of attributes provided. |
(package private) Value |
productValue(Value multiplicand)
Method to multiply multiplicand to this and return their product as the result. |
(package private) Value |
quotientValue(Value that)
|
void |
raiseToPower(int power)
MUTATING Instance method to raise this to power power. |
(package private) Rational |
root(int p)
method root: to yield an exact (integer) Rational for the root of a positive integral Rational. |
void |
scale(Rational that)
MUTATING Instance method to multiply another Arithmetical into this object. |
Trigonometrical |
sqrt()
Method to evaluate the tangent function. |
(package private) Value |
squareValue()
|
(package private) Value |
sumValue(Value addend)
Method to add addend to this and return their sum as the result. |
Trigonometrical |
tan_theta_2()
Method to evaluate the tangent function. |
(package private) static Presentation |
TermPresentation(Presentation coefficient,
java.lang.String symbol)
This package-scope class method creates a SymbolicPresentation from the two components given. |
protected void |
test(java.io.PrintStream out,
Value check)
|
protected void |
test(java.io.PrintStream out,
Value check,
java.lang.String label)
|
private void |
testTranscendental(java.io.PrintStream out,
java.lang.String function)
|
(package private) void |
timesTenToPower(int power)
Package-protected MUTATING method to multiply this by a power of ten. |
(package private) Approximation |
toApproximation(double tolerance)
Method to convert this Value into the appropriate Approximation. |
Integral |
toIntegral()
Method to present a Rational as an Integral number. |
(package private) Rational |
toRational()
Method to narrows this object to a Rational.. |
java.lang.String |
toString()
Method to yield a string representing this Rational exactly. |
private Value |
transcendentalFunction(Transcendental function)
The following method calculates the transcendental function (determined by function) on this Value. |
(package private) static Value |
TwentyfourthCircles(long n)
|
(package private) Value |
twiceValue()
|
void |
updateEstimate()
MUTATING method to update the current estimate. |
static Rational |
valueOf(BaseNumber number)
Factory method to create a "constant" Value from a BaseNumber or, if number is Value, then to make a copy. |
static BaseNumber |
valueOf(java.lang.String string)
Translates the String representation of a Value into Value, identified by the string itself. |
static BaseNumber |
valueOf(java.lang.String string,
java.lang.String id)
Translates the String representation of a Value into an explicitly identified Value. |
Methods inherited from class com.rubecula.jquantity.Rational |
absRational, addAbsError, addTops, compareTo, compareTo, compareTo, differenceRational, factor, factored, fold, getBottom, getBound, getDenominator, getDenominatorAsIntegral, getModel, getNumerator, getNumeratorAsIntegral, getTop, half, hashCode, InitialValueOf, intValue, inverse, inverseRational, isExact, isInfinite, isInteger, isIntFuzzy, isNaN, minus, minusRational, modulo, multiplyTopAndBottom, negate, normalize, normalizeToBigDecimal, normalizeToInt, Parse, pow, pow, productRational, quotient, quotientRational, scale, scale, scaled, setBound, setBoundAbs, setModel, signum, squareRational, subtract, sumRational, toString, valueOf, valueOf, valueOf, valueOf, valueOf, valueOf, valueOf, valueOf, valueOf, valueOf, valueOfExponent, valueOfExponent, valueOfExponent |
Methods inherited from class com.rubecula.jquantity.MutableNumber |
assertMutable, factored, forcePositive, getIdentifier, getIdentifier, isLong, isMutable, product, setConstant, setIdentifier, setIdentifierPost, setIdentifierPre, setIdentifierPrePost, sum, test |
Methods inherited from class com.rubecula.jquantity.BaseNumber |
abs, bestModel, BestModel, byteValue, Characteristic, difference, impartFuzziness, isEqual, isUncertain, isZero, shortValue, 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 |
equals, finalize, getClass, notify, notifyAll, wait, wait, wait |
Methods inherited from interface com.rubecula.jquantity.Mutable |
isMutable, setConstant |
Methods inherited from interface com.rubecula.util.Auditable |
audit, audit |
Field Detail |
public static final int $FactorNone
public static final int $FactorPi
public static final int $FactorE
public static final int $FactorInvPi
public static final int $FactorInvE
private static final Rational[] ConversionFactors
private static final java.lang.String[] Identifiers
public static final Value $0
public static final Value $1
public static final Value $Pi
public static final Value $2_Pi
public static final Value $Pi_2
public static final Value $Angle_0
public static final Value $E
public static final Value $Infinity
public static Value $Mu0
private int _Scheme
Constructor Detail |
public Value(Rational base, int scheme, java.lang.String id)
base
- The Rational whose value will be used as the "stored" value
of the new instance (the effective value of the new instance will differ
if the factoring scheme is not the trivial $FactorNone.scheme
- One of three factoring schemes: $FactorNone (stored and
effective values are the same); $FactorPi (the effective value will be pi
times the stored value); $FactorE (the effective value will be e times
the stored value).id
- the explicit identifier for this new Value (else null).public Value(Rational base, int scheme)
base
- The Rational whose value will be used as the "stored" value
of the new instance (the effective value of the new instance will differ
if the factoring scheme is not the trivial $FactorNone.scheme
- One of three factoring schemes: $FactorNone (stored and
effective values are the same); $FactorPi (the effective value will be pi
times the stored value); $FactorE (the effective value will be e times
the stored value).public Value(Rational base)
base
- The Rational whose value will be used as the "stored" value
of the new instance (and also the effective value).protected Value(Value base)
base
- immaterial.
ValueException:
- Value(Value) constructor would be ambiguous. Use clone() to copy.Method Detail |
public java.lang.String defaultIdentifier()
defaultIdentifier
in class Rational
Rational.defaultIdentifier()
.public void cast(int scheme)
scheme
- the new factoring scheme.public void convert(int scheme)
scheme
- the new factoring scheme.public Value normalizeValue()
convertValue(int)
passing the value of $FactorNone
.public Value convertValue(int scheme)
scheme
- the scheme required for the returned instance.
public Value castValue(int scheme)
scheme
- the scheme required for the returned instance.
public java.lang.String audit(java.lang.String label)
audit
in interface Auditable
audit
in class Rational
label
- String: the label to associate with the data
public static Rational Parse(SymbolicPresentation presentation, java.lang.String identifier) throws PresentationException
presentation
- SymbolicPresentation representation of a Value.identifier
- A string with which to identify this Value.
PresentationException
- if the presentation cannot be parsed as a
Value object.public static Rational valueOf(BaseNumber number)
number
- an integer (either WholeNumber or Manifest)
for which we require the (widened) Value.
public static BaseNumber valueOf(java.lang.String string, java.lang.String id) throws PresentationException
string
- String representation of a Value.id
- Identifier for new Value (or null).
PresentationException
- if the string cannot be parsed as a
Value object.public static BaseNumber valueOf(java.lang.String string) throws PresentationException
string
- String representation of a Value.
PresentationException
- if the string cannot be parsed as a
Value object.public Presentable makePresentableInstance(Presentation presentation) throws PresentationException
makePresentableInstance
in interface Presentable
makePresentableInstance
in class Rational
presentation
- of a number to be converted into a Presentable number.
Parse(Presentation)
.
PresentationException
- if presentation cannot be parsed appropriately.public static Presentable Parse(Presentation presentation) throws PresentationException
presentation
- the SymbolicPresentation which should be parsed to form a Value.
Rational.Parse(Presentation)
.
PresentationException
- if the presentation cannot be parsed as a
Presentable object.public java.lang.Object clone()
clone
in class Rational
RationalException
- : Rational not Cloneable (should be impossible)Cloneable
public double getBoundAbs()
getBoundAbs
in class Rational
public boolean isUnity()
Rational.isUnity()
.
isUnity
in interface Arithmetical
isUnity
in class Rational
Arithmetical.isUnity()
public long longValue()
longValue
in class Rational
public float floatValue()
float
.
This may involve rounding.
floatValue
in class Rational
float
.public double doubleValue()
double
.
This may involve rounding.
doubleValue
in class Rational
double
.public void raiseToPower(int power)
raiseToPower
in interface Arithmutable
raiseToPower
in class Rational
power
- int the number of times this should be multiplied by itself.public void add(BaseNumber that)
add
in interface Arithmutable
add
in class Rational
that
- the addend.public void multiply(BaseNumber that) throws InvalidOperandException
multiply
in interface Arithmutable
multiply
in class Rational
that
- Arithmetical : the multiplicand.
InvalidOperandException
- if that is not compatible with the multiply operation.public void invert()
invert
in class Rational
public void divide(BaseNumber that) throws InvalidOperandException
divide
in class Rational
that
- the value to be divided into this
InvalidOperandException
- if that is not compatible with the multiply operation.public Trigonometrical exp()
log()
.
exp
in interface Trigonometrical
exp
in class Rational
public Trigonometrical log()
exp()
.
log
in interface Trigonometrical
log
in class Rational
public Trigonometrical arctanX2()
tan_theta_2()
.
arctanX2
in interface Trigonometrical
arctanX2
in class Rational
public Trigonometrical tan_theta_2()
arctanX2()
.
tan_theta_2
in interface Trigonometrical
tan_theta_2
in class Rational
public Trigonometrical sqrt()
arctanX2()
.
public void updateEstimate()
updateEstimate
in interface Estimable
updateEstimate
in class Rational
private Rational getConversionFactor()
public double getEstimate()
getEstimate
in interface Estimable
getEstimate
in class Rational
public Integral toIntegral()
toIntegral
in class Rational
protected BaseNumber pow(double power)
Rational
pow
in class Rational
power
- the power with which to raise this.
final Value minusValue()
final Value sumValue(Value addend) throws InvalidOperandException
addend
- the number to add to this.
InvalidOperandException
final Value differenceValue(Value subtrahend) throws InvalidOperandException
subtrahend
- the number to subtract from this.
InvalidOperandException
final Value productValue(Value multiplicand) throws InvalidOperandException
multiplicand
- the number to add to this.
InvalidOperandException
final Value quotientValue(Value that) throws InvalidOperandException
InvalidOperandException
final Value inverseValue() throws InvalidOperandException
InvalidOperandException
public boolean isNormal()
isNormal
in interface Normalizable
isNormal
in class Rational
final Rational toRational()
private final Value transcendentalFunction(Transcendental function) throws JQuantityException
function
- the inner class which implements Transcendental and represent the required transcendental function
JQuantityException
Rational root(int p)
root
in class Rational
p
- the inverse of the power to which this will be raised.
RationalException
public void scale(Rational that) throws InvalidOperandException
that
- Arithmetical : the multiplicand.
InvalidOperandException
- if that is not compatible with the multiply operation.Value squareValue()
Value twiceValue()
Value halfValue()
public java.lang.String toString()
Rational
toString
in class Rational
Rational.toString(double)
public Presentation present(AttrMap attributes) throws PresentationException
present
in interface Presentable
present
in class Rational
attributes
- a map of the required attributes for the presentation.
Supported attributes include:
PresentationException
- if this object cannot be presented
with the given attributes.Approximation toApproximation(double tolerance)
toApproximation
in class Rational
tolerance
- a non-negative representation of the maximum error being
introduced by this type conversion.
long longValue(double tolerance)
longValue
in class Rational
tolerance
- The tolerance within which we don't mind losing precision
as we perform this conversion.
RationalException
void timesTenToPower(int power)
Rational
timesTenToPower
in class Rational
power
- the power of ten by which to multiply this.final double magnitude()
Rational
magnitude
in class Rational
Rational.doubleValue()
int characteristic()
BaseNumber
characteristic
in class BaseNumber
BaseNumber.doubleValue()
,
BaseNumber.Characteristic(double)
protected int compareTo(Value val, boolean strict)
val
- Rational to which this Rational is to be compared.strict
- ignored if the factoring schemes are the same;
otherwise if strict is true then return -1, otherwise compare the equivalent values.
public int compareTo(Value val)
val
- Rational to which this Rational is to be compared.
static final Value TwentyfourthCircles(long n)
static final Value FullCircles(int n)
static Presentation TermPresentation(Presentation coefficient, java.lang.String symbol)
coefficient
- the coefficientsymbol
- the symbol, such as pi or e.
protected void cftest(java.io.PrintStream out, java.lang.Object check)
protected void test(java.io.PrintStream out, Value check, java.lang.String label)
protected void test(java.io.PrintStream out, Value check)
private void testTranscendental(java.io.PrintStream out, java.lang.String function)
public static void main(java.lang.String[] args)
Rational
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |