com.rubecula.jquantity
Class Value

java.lang.Object
  extended bycom.rubecula.util.Item
      extended bycom.rubecula.jquantity.BaseNumber
          extended bycom.rubecula.jquantity.MutableNumber
              extended bycom.rubecula.jquantity.DivisibleMutable
                  extended bycom.rubecula.jquantity.Rational
                      extended bycom.rubecula.jquantity.Value
All Implemented Interfaces:
Arithmetical, Arithmutable, Auditable, java.lang.Cloneable, java.lang.Comparable, Divisible, Estimable, Fuzzy, FuzzyMutable, Identifiable, Millable, Mutable, Nameable, Normalizable, Presentable, java.io.Serializable, Trigonometrical

public class Value
extends Rational

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).

Since:
V_0_3 (replaces the old version of Value.java)
Version:
$Revision: 1.46 $
Author:
Robin Hillyard
See Also:
Serialized Form

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

$FactorNone

public static final int $FactorNone
The trivial factoring scheme: numbers represent themselves.

See Also:
Constant Field Values

$FactorPi

public static final int $FactorPi
The angle factoring scheme: numbers represent themselves multiplied by pi.

See Also:
Constant Field Values

$FactorE

public static final int $FactorE
The exponential factoring scheme: numbers represent themselves multiplied by e.

See Also:
Constant Field Values

$FactorInvPi

public static final int $FactorInvPi
The angle factoring scheme: numbers represent themselves divided by pi.

See Also:
Constant Field Values

$FactorInvE

public static final int $FactorInvE
The exponential factoring scheme: numbers represent themselves divided by e.

See Also:
Constant Field Values

ConversionFactors

private static final Rational[] ConversionFactors
The conversion factors for the various schemes, in order: 1, pi, e.


Identifiers

private static final java.lang.String[] Identifiers
The identifiers for the various schemes, in order: null, "pi", "e".


$0

public static final Value $0
The pure constant value 0.


$1

public static final Value $1
The pure constant value 1.


$Pi

public static final Value $Pi
The constant value pi (1 with factor pi).


$2_Pi

public static final Value $2_Pi
The constant value 2pi (2 with factor pi).


$Pi_2

public static final Value $Pi_2
The constant value pi/2 (1/2 with factor pi).


$Angle_0

public static final Value $Angle_0
The constant angular value 0 (0 with factor pi).


$E

public static final Value $E
The constant value e (1 with factor e).


$Infinity

public static final Value $Infinity
The pure constant value representing infinity.


$Mu0

public static Value $Mu0
Vacuum permeability (in henry/meter or Newtons per square Ampere). Value: 4 pi / 10^7 This value is exact. It is approximately equal to: 12.566370614... x 10-7 See Mu0.


_Scheme

private int _Scheme
The factoring scheme used for this Value. The default value is $FactorNone, meaning the number should be interpreted as is. Other schemes include $FactorPi and $FactorE.

Constructor Detail

Value

public 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).

Parameters:
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).

Value

public Value(Rational base,
             int scheme)
Secondary constructor to instantiate a Value, based on a given Rational (base) and factored with a specific scheme (scheme).

Parameters:
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).

Value

public Value(Rational base)
Secondary constructor to instantiate a value, based on a given Rational (base) and factored with the trivial scheme ($FactorNone). Note that base is referenced, not cloned.

Parameters:
base - The Rational whose value will be used as the "stored" value of the new instance (and also the effective value).

Value

protected Value(Value base)
Unused constructor.

Parameters:
base - immaterial.
Throws:
ValueException: - Value(Value) constructor would be ambiguous. Use clone() to copy.
Method Detail

defaultIdentifier

public java.lang.String defaultIdentifier()
Method to yield a defaultIdentifier in the case that none is given.

Overrides:
defaultIdentifier in class Rational
Returns:
id + (scheme) where id is any explicit identifier given, else the result of calling Rational.defaultIdentifier().

cast

public void cast(int scheme)
Method to force the factoring scheme of this Value. The stored value does not change. The effective value will change if scheme does not equal the current value of _Scheme.

Parameters:
scheme - the new factoring scheme.

convert

public void convert(int scheme)
Method to refactor the scheme of this Value. The effective value does not change. The stored value will change if scheme does not equal the current value of _Scheme.

Parameters:
scheme - the new factoring scheme.

normalizeValue

public 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.

Returns:
convertValue(int) passing the value of $FactorNone.

convertValue

public 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.

Parameters:
scheme - the scheme required for the returned instance.
Returns:
this or clone().convert(scheme).

castValue

public 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.

Parameters:
scheme - the scheme required for the returned instance.
Returns:
this or clone().cast(scheme).

audit

public java.lang.String audit(java.lang.String label)
Method to return a detailed string from an arithmetical object for debugging purposes.

Specified by:
audit in interface Auditable
Overrides:
audit in class Rational
Parameters:
label - String: the label to associate with the data
Returns:
the detailed string.

Parse

public static Rational Parse(SymbolicPresentation presentation,
                             java.lang.String identifier)
                      throws PresentationException
Class method to translate the given SymbolicPresentation representation of a Value into a Value.

Parameters:
presentation - SymbolicPresentation representation of a Value.
identifier - A string with which to identify this Value.
Returns:
Value : a new object parsed from the presentation.
Throws:
PresentationException - if the presentation cannot be parsed as a Value object.

valueOf

public 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.

Parameters:
number - an integer (either WholeNumber or Manifest) for which we require the (widened) Value.
Returns:
the Value, widened from number and returned as a Rational.

valueOf

public static BaseNumber valueOf(java.lang.String string,
                                 java.lang.String id)
                          throws PresentationException
Translates the String representation of a Value into an explicitly identified Value.

Parameters:
string - String representation of a Value.
id - Identifier for new Value (or null).
Returns:
(as a BaseNumber) a new instance of Value parsed from the string string.
Throws:
PresentationException - if the string cannot be parsed as a Value object.

valueOf

public static BaseNumber valueOf(java.lang.String string)
                          throws PresentationException
Translates the String representation of a Value into Value, identified by the string itself.

Parameters:
string - String representation of a Value.
Returns:
(as a BaseNumber) a new instance of Value parsed from the string string.
Throws:
PresentationException - if the string cannot be parsed as a Value object.

makePresentableInstance

public Presentable makePresentableInstance(Presentation presentation)
                                    throws PresentationException
Instance method to convert a Presentation into a Presentable. Ideally, this would be a class method, but such a method cannot be defined in an interface. Nor can it be defined in an abstract class with the intention of overriding it in a subclass. Polymorphism just doesn't work that way.
Therefore, the present value (as in fields) of the instance is essentially ignored - only the methods are important.

Specified by:
makePresentableInstance in interface Presentable
Overrides:
makePresentableInstance in class Rational
Parameters:
presentation - of a number to be converted into a Presentable number.
Returns:
a Value which is the result of passing presentation to Parse(Presentation).
Throws:
PresentationException - if presentation cannot be parsed appropriately.

Parse

public static Presentable Parse(Presentation presentation)
                         throws PresentationException
Method to create a Value from a Presentation and return it as a Presentable.

Parameters:
presentation - the SymbolicPresentation which should be parsed to form a Value.
Returns:
A Value which corresponds to the presentation OR, if presentation is not a SymbolicPresentation, the the result of Rational.Parse(Presentation).
Throws:
PresentationException - if the presentation cannot be parsed as a Presentable object.

clone

public java.lang.Object clone()
Creates and returns a copy of this object.

Overrides:
clone in class Rational
Returns:
a clone of this instance.
Throws:
RationalException - : Rational not Cloneable (should be impossible)
See Also:
Cloneable

getBoundAbs

public double getBoundAbs()
Method to get the absolute bound of non-fuzzy value.

Overrides:
getBoundAbs in class Rational
Returns:
the absolute bound of this. // TODO if infinite then bound should be zero (infinity is an exact number).

isUnity

public boolean isUnity()
Method to determine if this Value object has the exact value of 1. If this is a factored value, then false is returned (because the value cannot be exactly unity in such a case), else we return the value of Rational.isUnity().

Specified by:
isUnity in interface Arithmetical
Overrides:
isUnity in class Rational
Returns:
true if value is 1 and isExact().
See Also:
Arithmetical.isUnity()

longValue

public long longValue()
Method to yield the equivalent integer value for this object. Objects which are infinite or non-integral throw exceptions.

Overrides:
longValue in class Rational
Returns:
int : the integer value of this.

floatValue

public float floatValue()
Returns the value of the specified number as a float. This may involve rounding.

Overrides:
floatValue in class Rational
Returns:
the numeric value represented by this object after conversion to type float.

doubleValue

public double doubleValue()
Returns the value of the specified number as a double. This may involve rounding.

Overrides:
doubleValue in class Rational
Returns:
the numeric value represented by this object after conversion to type double.

raiseToPower

public void raiseToPower(int power)
MUTATING Instance method to raise this to power power.

Specified by:
raiseToPower in interface Arithmutable
Overrides:
raiseToPower in class Rational
Parameters:
power - int the number of times this should be multiplied by itself.

add

public void add(BaseNumber that)
MUTATING Instance method to add another BaseNumber into this object.

Specified by:
add in interface Arithmutable
Overrides:
add in class Rational
Parameters:
that - the addend.

multiply

public void multiply(BaseNumber that)
              throws InvalidOperandException
MUTATING Instance method to multiply another Arithmetical into this object.

Specified by:
multiply in interface Arithmutable
Overrides:
multiply in class Rational
Parameters:
that - Arithmetical : the multiplicand.
Throws:
InvalidOperandException - if that is not compatible with the multiply operation.

invert

public void invert()
MUTATING Instance method to invert this (i.e. replace this by its reciprocal)

Overrides:
invert in class Rational

divide

public void divide(BaseNumber that)
            throws InvalidOperandException
MUTATING method to replace this by the quotient of this and that

Overrides:
divide in class Rational
Parameters:
that - the value to be divided into this
Throws:
InvalidOperandException - if that is not compatible with the multiply operation.

exp

public Trigonometrical exp()
Method to evaluate the exponential function. This method is the inverse of log().

Specified by:
exp in interface Trigonometrical
Overrides:
exp in class Rational
Returns:
e(this) in the form of a Rational.

log

public Trigonometrical log()
Method to evaluate the natural log function. This method is the inverse of exp().

Specified by:
log in interface Trigonometrical
Overrides:
log in class Rational
Returns:
log(this) in the form of a Rational or an Approximation.

arctanX2

public Trigonometrical arctanX2()
Method to evaluate the arctangent function. This method is the inverse of tan_theta_2().

Specified by:
arctanX2 in interface Trigonometrical
Overrides:
arctanX2 in class Rational
Returns:
2 * atan(this) in the form of a Rational.

tan_theta_2

public Trigonometrical tan_theta_2()
Method to evaluate the tangent function. This method is the inverse of arctanX2().

Specified by:
tan_theta_2 in interface Trigonometrical
Overrides:
tan_theta_2 in class Rational
Returns:
tan(this/2) in the form of a Rational.

sqrt

public Trigonometrical sqrt()
Method to evaluate the tangent function. This method is the inverse of arctanX2().

Returns:
tan(this/2) in the form of a Rational.

updateEstimate

public void updateEstimate()
MUTATING method to update the current estimate.

Specified by:
updateEstimate in interface Estimable
Overrides:
updateEstimate in class Rational

getConversionFactor

private Rational getConversionFactor()

getEstimate

public double getEstimate()
Method to get the current estimate of an arithmetical value.

Specified by:
getEstimate in interface Estimable
Overrides:
getEstimate in class Rational
Returns:
double: the current estimate.

toIntegral

public Integral toIntegral()
Method to present a Rational as an Integral number. If this is already of class Integral then just return this, else return the value of the superclass method.

Overrides:
toIntegral in class Rational
Returns:
an instance of Integral with value equivalent to this.

pow

protected BaseNumber pow(double power)
Description copied from class: Rational
Method to yield this raised to a double-precision power.

Overrides:
pow in class Rational
Parameters:
power - the power with which to raise this.
Returns:
either Rational (possibly this) or an Approximation.

minusValue

final Value minusValue()
Method to yield a copy of this but with the sign changed.

Returns:
negative version of this.

sumValue

final Value sumValue(Value addend)
              throws InvalidOperandException
Method to add addend to this and return their sum as the result.

Parameters:
addend - the number to add to this.
Returns:
the sum of this and addend.
Throws:
InvalidOperandException

differenceValue

final Value differenceValue(Value subtrahend)
                     throws InvalidOperandException
Method to yield the difference of this less a BaseNumber (subtrahend).

Parameters:
subtrahend - the number to subtract from this.
Returns:
the difference of this less subtrahend.
Throws:
InvalidOperandException

productValue

final Value productValue(Value multiplicand)
                  throws InvalidOperandException
Method to multiply multiplicand to this and return their product as the result.

Parameters:
multiplicand - the number to add to this.
Returns:
the product of this and multiplicand.
Throws:
InvalidOperandException

quotientValue

final Value quotientValue(Value that)
                   throws InvalidOperandException
Throws:
InvalidOperandException

inverseValue

final Value inverseValue()
                  throws InvalidOperandException
Throws:
InvalidOperandException

isNormal

public boolean isNormal()
Method to determine if this instance is already normalized. In the case of Rational, it is too complicated to determine if the instance is already normalized. So we just say it isn't. // TODO Implement isNormal more properly. This is dangerous as the meaning of isNormal doesn't correspond any longer to the activities of normalize method.

Specified by:
isNormal in interface Normalizable
Overrides:
isNormal in class Rational
Returns:
true if this Value is not factored

toRational

final Rational toRational()
Method to narrows this object to a Rational..

Returns:
the Rational with equivalent value to this.

transcendentalFunction

private final Value transcendentalFunction(Transcendental function)
                                    throws JQuantityException
The following method calculates the transcendental function (determined by function) on this Value.

Parameters:
function - the inner class which implements Transcendental and represent the required transcendental function
Returns:
the value of the transcendental function for this Value (either exact or fuzzy).
Throws:
JQuantityException

root

Rational root(int p)
method root: to yield an exact (integer) Rational for the root of a positive integral Rational. Throws an exception if this is not a positive integer or cannot otherwise yield an exact result.

Overrides:
root in class Rational
Parameters:
p - the inverse of the power to which this will be raised.
Returns:
the pth root of this.
Throws:
RationalException

scale

public void scale(Rational that)
           throws InvalidOperandException
MUTATING Instance method to multiply another Arithmetical into this object.

Parameters:
that - Arithmetical : the multiplicand.
Throws:
InvalidOperandException - if that is not compatible with the multiply operation.

squareValue

Value squareValue()

twiceValue

Value twiceValue()

halfValue

Value halfValue()

toString

public java.lang.String toString()
Description copied from class: Rational
Method to yield a string representing this Rational exactly.

Overrides:
toString in class Rational
Returns:
a string representing this exactly.
See Also:
Rational.toString(double)

present

public Presentation present(AttrMap attributes)
                     throws PresentationException
Convert this Presentable object into a Presentation, according to the set of attributes provided.

Specified by:
present in interface Presentable
Overrides:
present in class Rational
Parameters:
attributes - a map of the required attributes for the presentation. Supported attributes include:
Normalize
String On / Off*;
Tolerance
Double/String value (def: 0);
NYI: Places
Integer/String the number of decimal places to show
NYI: Round
String On * / Off
NYI: Radix
Integer/String the value of the radix
NYI: Zero
String On * / Off where to show 0.x or just .x
NYI: Decimal
String "." or ","
Returns:
an appropriate instance of Presentation.
Throws:
PresentationException - if this object cannot be presented with the given attributes.

toApproximation

Approximation toApproximation(double tolerance)
Method to convert this Value into the appropriate Approximation. Note that precision will generally be lost in this operation.

Overrides:
toApproximation in class Rational
Parameters:
tolerance - a non-negative representation of the maximum error being introduced by this type conversion.
Returns:
a Approximation which is exactly equivalent to this.

longValue

long longValue(double tolerance)
Method to yield the integer value of this object. // TODO Check whether it should return long instead.

Overrides:
longValue in class Rational
Parameters:
tolerance - The tolerance within which we don't mind losing precision as we perform this conversion.
Returns:
an integer which is equal to doubleValue(), within tolerance.
Throws:
RationalException

timesTenToPower

void timesTenToPower(int power)
Description copied from class: Rational
Package-protected MUTATING method to multiply this by a power of ten.

Overrides:
timesTenToPower in class Rational
Parameters:
power - the power of ten by which to multiply this.

magnitude

final double magnitude()
Description copied from class: Rational
Method to yield the magnitude of this Rational as a double.

Overrides:
magnitude in class Rational
Returns:
the (absolute) double value of this (or infinity if appropriate).
See Also:
Rational.doubleValue()

characteristic

int characteristic()
Description copied from class: BaseNumber
Method to yield the characteristic of a BaseNumber.

Overrides:
characteristic in class BaseNumber
Returns:
the power of 10 which, if divided into this, would yield a value between 1 and 9.99999
See Also:
BaseNumber.doubleValue(), BaseNumber.Characteristic(double)

compareTo

protected int compareTo(Value val,
                        boolean strict)
Compares this Rational with the specified Rational. This method is provided in preference to individual methods for each of the six boolean comparison operators (<, ==, >, >=, !=, <=). The suggested idiom for performing these comparisons is: (x.compareTo(y) <op> 0), where <op> is one of the six comparison operators.

Parameters:
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.
Returns:
-1, 0 or 1 as this Rational is numerically less than, equal to, or greater than val.

compareTo

public int compareTo(Value val)
Compares this Rational with the specified Rational. This method is provided in preference to individual methods for each of the six boolean comparison operators (<, ==, >, >=, !=, <=). The suggested idiom for performing these comparisons is: (x.compareTo(y) <op> 0), where <op> is one of the six comparison operators.

Parameters:
val - Rational to which this Rational is to be compared.
Returns:
-1, 0 or 1 as this Rational is numerically less than, equal to, or greater than val.

TwentyfourthCircles

static final Value TwentyfourthCircles(long n)

FullCircles

static final Value FullCircles(int n)

TermPresentation

static Presentation TermPresentation(Presentation coefficient,
                                     java.lang.String symbol)
This package-scope class method creates a SymbolicPresentation from the two components given. The first component is considered the coefficient and is suppressed if equal to "1".

Parameters:
coefficient - the coefficient
symbol - the symbol, such as pi or e.
Returns:
a SymbolicPresentation consisting of one or two presentations: the coefficient (if not 1) followed a presentation corresponding to symbol.

cftest

protected void cftest(java.io.PrintStream out,
                      java.lang.Object check)

test

protected void test(java.io.PrintStream out,
                    Value check,
                    java.lang.String label)

test

protected void test(java.io.PrintStream out,
                    Value check)

testTranscendental

private void testTranscendental(java.io.PrintStream out,
                                java.lang.String function)

main

public static void main(java.lang.String[] args)
Description copied from class: Rational
Main method for testing this class.