|
|||||||||||
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
Public class to represent precise rational numbers.
What's wrong with BigDecimal, you might ask?
BigDecimal can only represent rational numbers where the denominator is a
power of ten.
Many numbers are just not like that.
Furthermore, both numerator and denominator can be either exact integers
(i.e. Manifests or WholeNumbers) or fuzzy integers (i.e. FuzzInt)
so that Rational can
itself represent a complete range of potentially fuzzy numbers.
Infinity is a legal Rational number.
Nested Class Summary | |
private class |
Rational.RationalException
|
class |
Rational.RValueException
Title: RValueException Description: Checked exception class for Rational. |
Field Summary | |
protected BaseNumber |
_Denominator
_Denominator is the denominator of the rational quantity defined by this. |
protected double |
_Estimate
_Estimate is the best estimate of the value (STRICTLY for debugging purposes only). |
protected BaseNumber |
_Numerator
_Numerator is the numerator of the rational quantity defined by this. |
(package private) static Rational |
$_c
By definition, the velocity of light (in meter/second). |
(package private) static Rational |
$_degF
Degrees Fahrenheit/Celsius offset: 32. |
static Rational |
$_degR
Degrees Rankine/Kelvin conversion: 5/9. |
(package private) static Rational |
$_g
By definition, the standard (mean) gravity at the Earth's surface: 9.80665. |
static Rational |
$_Log10_E
|
(package private) static Rational |
$_Pi_2
|
(package private) static Rational |
$_Pi_4
|
(package private) static Rational |
$_Tan15Deg
2 - $Rt3. |
(package private) static Rational |
$_Tan22_5Deg
1 / (1 + Rt2). |
(package private) static Rational |
$_Tan30Deg
1/$Rt3. |
static Rational |
$0
$0 is the Rational representation of the exact value 0. |
static Rational |
$1
$1 is the Rational representation of the exact value 1. |
static Rational |
$1_2
$1_2 is the Rational representation of the exact value 1/2. |
static Rational |
$10
$10 is the Rational representation of the exact value 10. |
(package private) static Rational |
$12
|
static Rational |
$2
$2 is the Rational representation of the exact value 2. |
static Rational |
$3
|
(package private) static Rational |
$6
|
static Rational |
$E
Value of E as a Rational. |
static Rational |
$Infinity
$Infinity is the Rational representation of the (exact) value of infinity, i.e. 1/0. |
(package private) static Rational |
$NaN
|
static Rational |
$Pi
Value of Pi as a Rational. |
(package private) static Rational |
$Rt2
InitialValueOf($S_Rt2). |
(package private) static Rational |
$Rt3
InitialValueOf($S_Rt3). |
(package private) static Rational |
$Rt5
InitialValueOf($S_Rt5). |
(package private) static java.lang.String |
$S_Rt2
1.414213562373095048801688724209698078569671875377 |
(package private) static java.lang.String |
$S_Rt3
1.732050807568877293527446341505872366942805253810 |
(package private) static java.lang.String |
$S_Rt5
2.2360679774997896964091736687312762354406183596 |
private static int |
MAX_RATIO_BITS
|
private static double |
PRESENTATION_TOLERANCE
|
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 | |
|
Rational()
Empty constructor to make an undefined Rational object. |
(package private) |
Rational(java.math.BigDecimal x)
|
protected |
Rational(java.math.BigDecimal x,
java.lang.String identifier)
Factory method to create a Rational from a BigDecimal value and an identifier. |
|
Rational(Integral value)
Constructs a non-explicitly identified Rational representing the ratio of value divided by unity. |
|
Rational(Integral numerator,
Integral denominator)
Constructs a non-explicitly identified, normalized Rational representing the ratio of numerator divided by denominator. |
protected |
Rational(Integral numerator,
Integral denominator,
boolean normalize)
Constructs a non-explicitly identified Rational representing the ratio of numerator divided by denominator, with optional normalization. |
protected |
Rational(Integral numerator,
Integral denominator,
boolean normalize,
java.lang.String identifier)
Constructs an identified Rational representing the ratio of numerator divided by denominator, with optional normalization. |
|
Rational(Integral numerator,
Integral denominator,
java.lang.String identifier)
Constructs an identified Rational representing the ratio of numerator divided by denominator. |
|
Rational(Integral numerator,
java.lang.String identifier)
Constructs an identified Rational representing the ratio of numerator divided by denominator, with optional normalization. |
|
Rational(long numerator,
long denominator)
Convenience constructor for two longs. |
protected |
Rational(Rational source)
Constructor to make a copy of a Rational object. |
|
Rational(java.lang.String string)
Secondary constructor to create a Rational from a String. |
Method Summary | |
Rational |
absRational()
Method to yield the absolute (unsigned) value of this as a Rational. |
void |
add(BaseNumber that)
MUTATING Instance method to add another Arithmetical into this object. |
protected void |
addAbsError(double absBound,
int model)
This method is used to add in an intrinsic error bound. |
protected void |
addTops(Rational other)
|
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. |
private static Rational |
BigDecimalRational(java.math.BigInteger top,
java.math.BigInteger bottom,
double tolerance,
int characteristic,
java.lang.String id)
Class method to yield an explicitly identified Rational which approximates top/bottom to within tolerance (to exponent characteristic). |
private static java.math.BigInteger |
BigTenToPower(int x)
Class method to yield a BigInteger whose value is 10 to the power of x. |
java.lang.Object |
clone()
Creates and returns a deep copy of this object. |
int |
compareTo(Integral val)
Compares this Rational with the specified Integral. |
int |
compareTo(Rational val)
Compares this Rational with the specified Rational. |
protected int |
compareTo(Rational val,
boolean absolute)
Compares this Rational with the specified Rational. |
java.lang.String |
defaultIdentifier()
Method to yield a default string to identify this object in the event that it has no explicitly defined identifier. |
(package private) Rational |
differenceRational(Rational subtrahend)
Method to yield the difference of this less a BaseNumber (subtrahend). |
void |
divide(BaseNumber that)
MUTATING method to replace this by the sum of this and that |
private java.math.BigInteger[] |
divideNumeratorAndRemainder(Integral divisor)
|
double |
doubleValue()
Returns the value of the specified number as a double .
|
private void |
ensureDenominatorArithmutable()
MUTATING method to ensure that the numerator is an Arithmutable object. |
private void |
ensureDenominatorFuzzy()
|
private void |
ensureNumeratorArithmutable()
MUTATING method to ensure that the numerator is an Arithmutable object. |
private void |
ensureNumeratorFuzzy()
|
Trigonometrical |
exp()
Method to evaluate the exponential function. |
protected void |
factor(Integral divisor)
MUTATING METHOD: Replaces value with (this / divisor). |
Divisible |
factored(double factor)
Method to yield the quotient of this divided by factor, and return it as the result. |
float |
floatValue()
Returns the value of the specified number as a float .
|
(package private) Rational |
fold(Rational range)
Method to force this into a specific range. |
private void |
forceFuzzy()
MUTATING method to ensure that this Rational is (potentially) fuzzy, that is to say its Numerator must be FuzzyMutable. |
private java.math.BigInteger |
gcd(boolean strict)
|
private static java.math.BigInteger |
GetBigInteger(Integral x,
boolean strict)
|
long |
getBottom()
Method to yield the denominator as a long. |
double |
getBound()
Method to get the relative bound of this Rational. |
private static double |
GetBound(double x,
boolean exact)
Get the bounds for a number in double format which is either exact or accurate only to the number of decimal places given. |
double |
getBoundAbs()
Method to get the absolute bound of non-fuzzy value. |
protected BaseNumber |
getDenominator()
Method to access the denominator of this Rational object. |
protected Integral |
getDenominatorAsIntegral()
Method to access the denominator of this Rational object. |
double |
getEstimate()
Method to get the current estimate of an arithmetical value. |
int |
getModel()
Method to get the error distribution model of this non-fuzzy object. |
protected BaseNumber |
getNumerator()
Method to access the numerator of this Rational object. |
protected Integral |
getNumeratorAsIntegral()
Method to access the numerator of this Rational object. |
long |
getTop()
Method to yield the numerator as a long. |
Rational |
half()
Method to yield half the value of this. |
int |
hashCode()
Method to determine a hash code for this object. // TODO Surely this isn't a good hash code for Rational objects. |
static Rational |
InitialValueOf(java.lang.String string)
Create a constant value of a Rational from a string. |
private static Rational |
InitParse(Presentation presentation,
java.lang.String id)
|
private static java.math.BigInteger |
IntVal(java.math.BigDecimal x)
|
int |
intValue()
Method to yield the equivalent integer value for this object. |
Divisible |
inverse()
Method to yield the reciprocal of this and return it as the result. |
Rational |
inverseRational()
|
void |
invert()
MUTATING Instance method to invert this (i.e. replace this by its reciprocal) |
boolean |
isExact()
Method to determine if the quantity represented is non-fuzzy; |
boolean |
isInfinite()
Method to determine if an arithmetical object is infinite. |
boolean |
isInteger()
Method determines if it is safe and appropriate to convert this arithmetical object into BigInteger. |
(package private) boolean |
isIntFuzzy()
This method is used to determine if the numerical value of this is convertible to a int, without regard to the precision. |
(package private) boolean |
isNaN()
Method to determine if this Rational is "not a number". |
boolean |
isNormal()
Method to determine if this instance is already normalized. |
boolean |
isUnity()
Method to determine if this arithmetical 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 long value of this object. |
(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. |
protected BaseNumber |
minus()
Method to yield a copy of this but with the sign changed. |
Rational |
minusRational()
Method to yield a copy of this but with the sign changed. |
(package private) Rational |
modulo(long x)
Method to return the value of this modulo x |
void |
multiply(BaseNumber that)
MUTATING Instance method to multiply another Arithmetical into this object. |
protected void |
multiplyTopAndBottom(BaseNumber factor)
MUTATING method to multiply the top and bottom of a rational equally. |
void |
negate()
MUTATING Instance method to negate this. |
void |
normalize()
MUTATING instance method to remove any common factors from top and bottom. |
(package private) Rational |
normalizeToBigDecimal(double tolerance)
Normalize this such that the denominator is a power of ten AND the value of the result differs from the value of this by not more than the tolerance. |
(package private) Rational |
normalizeToInt(double tolerance)
Normalize this Rational so that the result: a) has a denominator unity and b) approximates this in value, to within tolerance. |
static Rational |
Parse(NumberPresentation presentation,
java.lang.String identifier)
Translates the NumberPresentation representation into a new Rational. |
static Presentable |
Parse(Presentation presentation)
Create a Rational from a Presentation and return it as a Presentable. |
protected BaseNumber |
pow(double power)
Method to yield this raised to a double-precision power. |
protected BaseNumber |
pow(int power)
Method to raise this to the power power return the result. |
Rational |
pow(Rational power)
|
Presentation |
present(AttrMap attributes)
Convert this Presentable object into a Presentation, according to the set of attributes provided. |
private Presentation |
present(AttrMap attributes,
double tolerance)
Method to convert this Rational into an equivalent Presentation. |
private Presentation |
present(AttrMap attributes,
double tolerance,
boolean notRatio)
Method to convert this Rational into an equivalent Presentation. |
private Presentation |
present(double tolerance)
Method to convert this Rational into an equivalent Presentation. |
private Presentation |
presentRatio()
Method to convert this Rational into the appropriate NumberPresentation as a ratio rather than as a decimal. |
Rational |
productRational(Rational multiplicand)
Method to multiply multiplicand to this and return their product as the result. |
Divisible |
quotient(BaseNumber divisor)
Method to divide this by multiplicand and return the quotient as the result. |
(package private) Rational |
quotientRational(Rational that)
|
void |
raiseToPower(int power)
MUTATING Instance method to raise this to power x. |
(package private) Rational |
root(int p)
method root: to yield an exact (integer) Rational for the root of a positive integral Rational. |
private static BaseNumber |
SafeReference(BaseNumber x)
This method yields a reference to a BaseNumber (the numerator or denominator) for the purpose of cloning/copying a Rational object safely. |
void |
scale(double factor)
MUTATING Instance method to multiply this by a (double) scale factor |
void |
scale(long factor)
MUTATING Instance method to multiply this by a scale factor. |
protected BaseNumber |
scaled(long multiplicand)
Method to multiply multiplicand by this and return their product as the result. |
void |
setBound(double bound)
MUTATING Method to set the relative bound of fuzzy value. |
protected void |
setBoundAbs(double bound)
MUTATING Method to set the absolute bound of fuzzy value. // TODO Move this down with the protected methods (not defined by FuzzyMutable). |
private void |
setDenominator(BaseNumber denominator)
MUTATING method to set the value of the denominator. |
private void |
setDenominator(Integral denominator)
MUTATING method to set the value of the denominator. |
private void |
setExact()
|
void |
setModel(int model)
MUTATING Method to set the error distribution model. |
private void |
setNumerator(BaseNumber numerator)
MUTATING method to set the value of the numerator. |
private void |
setNumerator(Integral numerator)
MUTATING method to set the value of the numerator. |
int |
signum()
Method to find the sign of the magnitude of this arithmetical object. |
(package private) Rational |
squareRational()
Method to return the Rational formed my multiplying this by itself. |
void |
subtract(Rational that)
MUTATING method to replace this by the difference of this and that |
Rational |
sumRational(Rational 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) 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 Rational into the appropriate Approximation. |
private java.math.BigDecimal |
toBigDecimal()
Method to yield a BigDecimal instance which approximates this. |
private java.math.BigDecimal |
toBigDecimal(double tolerance)
Method to yield a BigDecimal instance which approximates this. |
private java.math.BigDecimal |
toBigDecimal(int halfPlaces)
Method to yield a BigDecimal instance which approximates this. |
Integral |
toIntegral()
Method to present a Rational as an Integral number. |
java.lang.String |
toString()
Method to yield a string representing this Rational exactly. |
(package private) java.lang.String |
toString(double tolerance)
Method to determine a suitable string to represent this Rational, such that the resulting string is precise within tolerance. |
void |
updateEstimate()
MUTATING method to update the current estimate. |
static Rational |
valueOf(BaseNumber number)
Factory method to create a Rational from a BaseNumber or, if number is Rational, then to make a copy. |
(package private) static Rational |
valueOf(java.math.BigInteger integer,
java.math.BigInteger fraction,
int places)
Factory method to create a (decimal) Rational from two (big) integers. |
static Rational |
valueOf(double value)
Factory method to create a Rational from an exact double value. |
static Rational |
valueOf(double value,
boolean exact)
Factory method to create a Rational from a double value, that may or not be "exact". |
static Rational |
valueOf(double value,
double bound,
int model)
Factory method to create a Rational from a double value, given an indication of precision. |
static Rational |
valueOf(double value,
double bound,
int model,
java.lang.String identifier)
Factory method to create a Rational from a double value, given an indication of precision. |
static Rational |
valueOf(double value,
int precision,
java.lang.String identifier)
Factory method to create a Rational from a double value, given an indication of precision. |
static Rational |
valueOf(double value,
java.lang.String identifier)
Factory method to create a Rational from a double value, using standard double precision and with an explicit identifier. |
static Rational |
valueOf(float value)
Factory method to create a Rational from a float value, given an explicit identifier. |
static Rational |
valueOf(float value,
java.lang.String identifier)
Factory method to create a Rational from a float value without an explicit identifier. |
static Rational |
valueOf(Presentation presentation)
Convert Presentation presentation into a Rational. |
static BaseNumber |
valueOf(java.lang.String string)
Convenience factory method to create a new Rational instance from a value string and an implicit identifier (the value string itself). |
static BaseNumber |
valueOf(java.lang.String string,
java.lang.String id)
Convenience factory method to create a new Rational instance from a value string and an explicit identifier. |
(package private) static Rational |
valueOfExponent(int exponent)
Factory method to create a Rational which is equal to 10^exponent. |
(package private) static Rational |
valueOfExponent(int exponent,
int radix)
Factory method to create a Rational which is equal to radix^exponent. |
(package private) static Rational |
valueOfExponent(java.lang.String exponentStr,
int radix)
Factory method to create a Rational which is equal to the multiplier represented by an exponent string. |
private static BaseNumber |
WidenIntegral(BaseNumber number)
Method to convert an Integral object into an Arithmutable object if necessary. |
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, 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 Rational $1
public static final Rational $0
public static final Rational $10
public static final Rational $2
public static final Rational $1_2
public static final Rational $Infinity
public static final Rational $E
public static final Rational $Pi
protected BaseNumber _Numerator
protected BaseNumber _Denominator
protected double _Estimate
public static final Rational $3
static final Rational $6
static final Rational $12
static final Rational $NaN
static final Rational $_Pi_2
static final Rational $_Pi_4
public static final Rational $_Log10_E
static final java.lang.String $S_Rt2
static final java.lang.String $S_Rt3
static final java.lang.String $S_Rt5
static final Rational $Rt2
static final Rational $Rt3
static final Rational $Rt5
static final Rational $_Tan15Deg
static final Rational $_Tan22_5Deg
static final Rational $_Tan30Deg
static final Rational $_c
Manifest.$_c
This value is exact.
See c,c0.
static final Rational $_g
public static final Rational $_degR
static final Rational $_degF
private static final int MAX_RATIO_BITS
private static final double PRESENTATION_TOLERANCE
Constructor Detail |
public Rational()
public Rational(java.lang.String string) throws PresentationException
string
- the String from which to create a Rationa.
PresentationException
- if the string cannot be parsed as a
Rational object.public Rational(Integral numerator, Integral denominator, java.lang.String identifier)
numerator
- the numerator (top) of the ratio.denominator
- the denominator (bottom) of the ratio.identifier
- the identifier to be used to identify this object.public Rational(Integral numerator, Integral denominator)
numerator
- Integral which is the numerator (top) of the ratiodenominator
- Integral which is the denominator (bottom) of the ratiopublic Rational(Integral numerator, java.lang.String identifier)
numerator
- the numerator (top) of the ratioidentifier
- the identifier to be used to identify this object.public Rational(Integral value)
value
- the numerator (top) of the ratio.public Rational(long numerator, long denominator)
numerator
- the top of the ratiodenominator
- the bottom of the ratioprotected Rational(java.math.BigDecimal x, java.lang.String identifier)
x
- a BigDecimal number which is to be widened into a Rationa.identifier
- the identifier for the new instance.protected Rational(Integral numerator, Integral denominator, boolean normalize, java.lang.String identifier)
numerator
- the numerator (top) of the ratio,
which must be an instance of either Manifest or WholeNumber.denominator
- the denominator (bottom) of the ratio,
which must be an instance of either Manifest or WholeNumber.normalize
- normally true (only set to false if you really know what
you're doing).identifier
- the identifier to be used to identify this object (or null).
Rational.RationalException
- if either numerator or denominator is not an
instance of either Manifest or WholeNumber.protected Rational(Integral numerator, Integral denominator, boolean normalize)
numerator
- the numerator (top) of the ratio.denominator
- the denominator (bottom) of the ratio.normalize
- normally true (only set to false if you really know what
you're doing)Rational(java.math.BigDecimal x)
protected Rational(Rational source)
source
- the object to copy.
// TODO is their any real reason for having this constructor?
// TODO should this simply call clone()? Surely that would be more consistent?Method Detail |
public static Rational Parse(NumberPresentation presentation, java.lang.String identifier) throws PresentationException
presentation
- NumberPresentation.identifier
- A string with which to identify this Rational.
PresentationException
- if the presentation cannot be parsed as a
Rational object.public static Rational valueOf(BaseNumber number)
number
- the value to be widened into a Rational.
public static BaseNumber valueOf(java.lang.String string, java.lang.String id) throws PresentationException
string
- a representation of a NumberPresentation.id
- Identifier for new Rational.
PresentationException
- if the string cannot be parsed as a
Rational object.NumberPresentation.NumberPresentation(String)
,
Parse(NumberPresentation, String)
public static BaseNumber valueOf(java.lang.String string) throws PresentationException
string
- a representation of a NumberPresentation.
PresentationException
- if the string cannot be parsed as a
Rational object.valueOf(String,String)
public Presentable makePresentableInstance(Presentation presentation) throws PresentationException
makePresentableInstance
in interface Presentable
presentation
- of a number to be converted into a Presentable number.
PresentationException
- if presentation cannot be parsed appropriately.public static Presentable Parse(Presentation presentation) throws PresentationException
presentation
- A presentation which should be parsed to form a Presentable.
PresentationException
- if the presentation cannot be parsed as a
Presentable object.public java.lang.Object clone()
clone
in class MutableNumber
Rational.RationalException
- : Rational not Cloneable (should be impossible)Cloneable
public double getBoundAbs()
getBoundAbs
in class BaseNumber
BaseNumber.getBound()
,
BaseNumber.doubleValue()
,
Math.abs(double)
public double getBound()
getBound
in interface Fuzzy
getBound
in class BaseNumber
public int getModel()
getModel
in interface Fuzzy
getModel
in class BaseNumber
public boolean isExact()
isExact
in interface Fuzzy
isExact
in class BaseNumber
public int intValue()
intValue
in class BaseNumber
public long longValue()
longValue
in class BaseNumber
public float floatValue()
float
.
This may involve rounding.
floatValue
in class BaseNumber
float
.public double doubleValue()
double
.
This may involve rounding.
doubleValue
in class BaseNumber
double
.public int signum()
signum
in interface Arithmetical
public boolean isInteger()
isInteger
in interface Arithmetical
public boolean isUnity()
isUnity
in interface Arithmetical
public boolean isInfinite()
isInfinite
in interface Arithmetical
public void raiseToPower(int power)
Arithmutable
raiseToPower
in interface Arithmutable
power
- the number of times this should be multiplied by itself.public void scale(long factor)
Arithmutable
scale
in interface Arithmutable
factor
- the scale factor.public void negate()
Arithmutable
negate
in interface Arithmutable
public void add(BaseNumber that)
Arithmutable
add
in interface Arithmutable
that
- the number to add to this.public void multiply(BaseNumber that) throws InvalidOperandException
Arithmutable
multiply
in interface Arithmutable
that
- the number by which this is to be multiplied.
InvalidOperandException
- operands are not compatible for the multiply
operation.private void ensureDenominatorFuzzy()
private void ensureNumeratorFuzzy()
public void scale(double factor)
scale
in class DivisibleMutable
factor
- double the scale factorpublic void invert()
invert
in class DivisibleMutable
public void divide(BaseNumber that) throws InvalidOperandException
divide
in class DivisibleMutable
that
- the value to be divided into this
InvalidOperandException
- if that is not compatible with the multiply operation.public Divisible inverse()
inverse
in interface Divisible
public Divisible quotient(BaseNumber divisor) throws InvalidOperandException
quotient
in interface Divisible
divisor
- the number to multiply by this.
InvalidOperandException
- if that is not compatible with the multiply operation.public Divisible factored(double factor)
factored
in interface Divisible
factor
- the scale factor.
public Trigonometrical exp()
log()
.
exp
in interface Trigonometrical
public Trigonometrical log()
exp()
.
log
in interface Trigonometrical
public Trigonometrical arctanX2()
tan_theta_2()
.
arctanX2
in interface Trigonometrical
public Trigonometrical tan_theta_2()
arctanX2()
.
tan_theta_2
in interface Trigonometrical
protected void setBoundAbs(double bound)
bound
- the absolute boundpublic void setBound(double bound)
setBound
in interface FuzzyMutable
bound
- the relative boundpublic void setModel(int model)
setModel
in interface FuzzyMutable
model
- the distribution model:
$DistNone, $DistUniform or $DistGaussianpublic void updateEstimate()
updateEstimate
in interface Estimable
public double getEstimate()
getEstimate
in interface Estimable
public Integral toIntegral()
toIntegral
in class MutableNumber
public final Rational minusRational()
public final Rational sumRational(Rational addend)
addend
- the number to add to this.
final Rational differenceRational(Rational subtrahend)
subtrahend
- the number to subtract from this.
public final Rational productRational(Rational multiplicand)
multiplicand
- the number to add to this.
final Rational quotientRational(Rational that)
public final Rational inverseRational()
protected final BaseNumber getDenominator()
protected final BaseNumber getNumerator()
protected final Integral getDenominatorAsIntegral()
protected final Integral getNumeratorAsIntegral()
protected BaseNumber minus()
minus
in class BaseNumber
protected BaseNumber scaled(long multiplicand)
scaled
in class BaseNumber
multiplicand
- the number to multiply this by.
protected BaseNumber pow(int power)
pow
in class BaseNumber
power
- the exponent for this.
protected void factor(Integral divisor)
factor
in class MutableNumber
divisor
- value by which this WholeNumber is to be divided.MutableNumber.assertMutable()
,
_Denominator
,
getDenominator()
,
BaseNumber.product(BaseNumber)
,
BaseNumber.scaled(long)
,
updateEstimate()
static Rational valueOfExponent(int exponent, int radix)
exponent
- the power to which radix is to be raised.radix
- the base of the number system.
static Rational valueOfExponent(int exponent)
exponent
- the power to which radix is to be raised.
static Rational valueOfExponent(java.lang.String exponentStr, int radix)
exponentStr
- the power to which radix is to be raised, as a string.radix
- the base of the number system in which exponentStr is to
be interpreted and also the number to be raised by the appropriate power.
public static Rational valueOf(double value, int precision, java.lang.String identifier)
value
- double: the value to convert to Rational.precision
- int: the number of significant figures (approx.).identifier
- String: the identifier to be used to identify this object (or null).
public static Rational valueOf(double value, double bound, int model, java.lang.String identifier)
value
- the value to convert to Rational.bound
- an explicit value for the relative error bound.model
- the error bound model to be used.identifier
- String: the identifier to be used to identify this object (or null).
valueOf(double,int,String)
public static Rational valueOf(double value, double bound, int model)
value
- the value to convert to Rational.bound
- an explicit value for the relative error bound.model
- the error bound model to be used.
valueOf(double,double,int)
public static Rational valueOf(double value, java.lang.String identifier)
value
- the value to convert to Rational.identifier
- the explicit identifier for this value.
valueOf(double,double,int)
public static Rational valueOf(double value, boolean exact)
value
- double: the value to convert to Rational.exact
- an indication of whether the result should be be considered exact.
valueOf(double,int,String)
public static Rational valueOf(double value)
value
- the value as a double.
valueOf(double,boolean)
public static Rational valueOf(float value, java.lang.String identifier)
value
- the value to convert to Rational.identifier
- String: the identifier to be used to identify this object (or null).
valueOf(double,int,String)
public static Rational valueOf(float value)
value
- the value to convert to Rational.
valueOf(float,String)
private static java.math.BigInteger IntVal(java.math.BigDecimal x)
static Rational valueOf(java.math.BigInteger integer, java.math.BigInteger fraction, int places)
integer
- BigInteger : the integer part.fraction
- BigInteger : the fractional part.places
- int : the number of decimal places for fractional part.
protected void multiplyTopAndBottom(BaseNumber factor)
factor
- the number by which top and bottom will be multiplied.protected void addTops(Rational other)
public void subtract(Rational that)
that
- Rational the value to be subtracted from thispublic Rational absRational()
BaseNumber.abs()
public java.lang.String defaultIdentifier()
defaultIdentifier
in class MutableNumber
public java.lang.String audit(java.lang.String label)
audit
in interface Auditable
label
- String: the label to associate with the data
public Rational half()
Rational modulo(long x)
x
- the divisor for the modulo operation.
Rational fold(Rational range)
range
- defines the range (-limit < magnitude <= +limit).
public long getTop()
public final long getBottom()
public int hashCode()
boolean isNaN()
Rational normalizeToInt(double tolerance) throws Rational.RationalException
tolerance
- the acceptable error in value of the result.
Rational.RationalException
- if no acceptable result can be found.Rational normalizeToBigDecimal(double tolerance) throws Rational.RationalException
tolerance
- the acceptable discrepancy in values (may be zero).
Rational.RationalException
- An "equivalent" instance cannot be created.private static Rational BigDecimalRational(java.math.BigInteger top, java.math.BigInteger bottom, double tolerance, int characteristic, java.lang.String id)
top
- a BigInteger representing the numerator of the the value to
be approximated.bottom
- a BigInteger representing the denominator of the value to
be approximated.tolerance
- the starting value of tolerance.characteristic
- the characteristic of the original tolerance.id
- identifier to be used for the result
public void normalize()
normalize
in interface Normalizable
public boolean isNormal()
isNormal
in interface Normalizable
protected BaseNumber pow(double power)
power
- the power with which to raise this.
Rational root(int p) throws Rational.RationalException
p
- the inverse of the power to which this will be raised.
Rational.RationalException
Rational squareRational()
public java.lang.String toString()
toString
in class Item
toString(double)
final java.lang.String toString(double tolerance)
tolerance
- the maximum discrepancy between the value represented by
the result and this.
present(double)
private Presentation presentRatio() throws PresentationException
PresentationException
- if this object cannot be presented in
ratio form.private Presentation present(AttrMap attributes, double tolerance, boolean notRatio) throws PresentationException
attributes
- the Attributes map.tolerance
- the acceptable error in the result (normally tolerance is equal to the absolute bound).notRatio
- a boolean which, if true, prevents this being presented as a ratio.
PresentationException
- if this object cannot be presented
with this value of tolerance.private Presentation present(AttrMap attributes, double tolerance) throws PresentationException
tolerance
- the acceptable error in the result (normally tolerance is equal to the absolute bound).
PresentationException
- if this object cannot be presented
with this value of tolerance.private Presentation present(double tolerance) throws PresentationException
tolerance
- the acceptable error in the result (normally tolerance is equal to the absolute bound).
PresentationException
- if this object cannot be presented
with this value of tolerance.public Presentation present(AttrMap attributes) throws PresentationException
present
in interface Presentable
attributes
- a map of the required attributes for the presentation.
Supported attributes include:
PresentationException
- if this object cannot be presented
with the given attributes.public static Rational valueOf(Presentation presentation) throws PresentationException
presentation
- a Presentation.
PresentationException
- if presentation presentation cannot
be parsed as a Rational object.Approximation toApproximation(double tolerance)
tolerance
- a non-negative representation of the maximum error being
introduced by this type conversion.
public Rational pow(Rational power)
long longValue(double tolerance) throws Rational.RationalException
tolerance
- The tolerance within which we don't mind losing precision
as we perform this conversion.
Rational.RationalException
void timesTenToPower(int power)
power
- the power of ten by which to multiply this.double magnitude()
doubleValue()
boolean isIntFuzzy()
private java.math.BigDecimal toBigDecimal(double tolerance) throws Rational.RationalException
tolerance
- the degree to which the result may differ in value from this.
Rational.RationalException
- a suitable BigDecimal equivalent could not be found.private java.math.BigDecimal toBigDecimal(int halfPlaces) throws Rational.RationalException
halfPlaces
- the number of halfPlaces we want the big decimal to be accurate to.
Rational.RationalException
- a suitable BigDecimal equivalent could not be found.toBigDecimal(double)
private java.math.BigDecimal toBigDecimal() throws Rational.RationalException
Rational.RationalException
- a suitable BigDecimal equivalent could not be found.toBigDecimal(double)
public static Rational InitialValueOf(java.lang.String string)
string
- the string from which to create and identify the new object.
valueOf(String)
,
MutableNumber.setConstant()
private static java.math.BigInteger BigTenToPower(int x)
x
- the power of 10 required.
private void forceFuzzy()
protected void addAbsError(double absBound, int model)
absBound
- the (intrinsic) error bound which should be added in to
any existing error bound of this.model
- the model of the intrinsic error.private static double GetBound(double x, boolean exact)
x
- the value itself.exact
- true if the value is intended to be exact
(it can't be more exact than a double can be);
false if only the digits given are known.
protected int compareTo(Rational val, boolean absolute)
val
- Rational to which this Rational is to be compared.absolute
- Whether to take the difference (if true) or the quotient
(if false) when comparing the values.
public int compareTo(Rational val)
val
- Rational to which this Rational is to be compared.
public int compareTo(Integral val)
val
- Rational to which this Rational is to be compared.
private static Rational InitParse(Presentation presentation, java.lang.String id)
private static BaseNumber WidenIntegral(BaseNumber number)
number
- the number as an Integral.
private void ensureNumeratorArithmutable()
private void ensureDenominatorArithmutable()
private void setNumerator(BaseNumber numerator)
numerator
- the numerator (top) of the ratio,
which must be an instance of either Manifest or WholeNumber.
Rational.RationalException
- if either numerator or denominator is not an
instance of either Manifest or WholeNumber.private void setDenominator(BaseNumber denominator)
denominator
- the denominator (bottom) of the ratio,
which must be an instance of either Manifest or WholeNumber.
Rational.RationalException
- if either numerator or denominator is not an
instance of either Manifest or WholeNumber.private void setNumerator(Integral numerator)
numerator
- the numerator (top) of the ratio,
which must be an instance of either Manifest or WholeNumber.
Rational.RationalException
- if either numerator or denominator is not an
instance of either Manifest or WholeNumber.private void setDenominator(Integral denominator)
denominator
- the denominator (bottom) of the ratio,
which must be an instance of either Manifest or WholeNumber.
Rational.RationalException
- if either numerator or denominator is not an
instance of either Manifest or WholeNumber.private static BaseNumber SafeReference(BaseNumber x)
x
- the number to be copied
private void setExact()
private java.math.BigInteger[] divideNumeratorAndRemainder(Integral divisor)
private java.math.BigInteger gcd(boolean strict)
private static java.math.BigInteger GetBigInteger(Integral x, boolean strict)
public static void main(java.lang.String[] args)
args
- String[] : the command line options.
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |