

PREV CLASS NEXT CLASS  FRAMES NO FRAMES  
SUMMARY: INNER  FIELD  CONSTR  METHOD  DETAIL: FIELD  CONSTR  METHOD 
java.lang.Object  +java.lang.Number  +com.sgi.math.CR
Constructive real numbers, also known as recursive, or computable reals. Each recursive real number is represented as an object that provides an approximation function for the real number. The approximation function guarantees that the generated approximation is accurate to the specified precision. Arithmetic operations on constructive reals produce new such objects; they typically do not perform any real computation. In this sense, arithmetic computations are exact: They produce a description which describes the exact answer, and can be used to later approximate it to arbitrary precision.
When approximations are generated, e.g. for output, they are accurate to the requested precision; no cumulative rounding errors are visible. In order to achieve this precision, the approximation function will often need to approximate subexpressions to greater precision than was originally demanded. Thus the approximation of a constructive real number generated through a complex sequence of operations may eventually require evaluation to very high precision. This usually makes such computations prohibitively expensive for large numerical problems. But it is perfectly appropriate for use in a desk calculator, for small numerical problems, for the evaluation of expressions computated by a symbolic algebra system, for testing of accuracy claims for floating point code on small inputs, or the like.
We expect that the vast majority of uses will ignore the particular implementation, and the member functons approximate and get_appr. Such applications will treat CR as a conventional numerical type, with an interface modelled on java.math.BigInteger. No subclasses of CR will be explicitly mentioned by such a program.
All standard arithmetic operations, as well as a few algebraic and transcendal functions are provided. Constructive reals are immutable; thus all of these operations return a new constructive real.
A few uses will require explicit construction of approximation functions. The requires the construction of a subclass of CR with an overridden approximate function. Note that approximate should only be defined, but never called. get_appr provides the same functionality, but adds the caching necessary to obtain reasonable performance.
Any operation may throw com.sgi.math.AbortedError if the thread in which it is executing is interrupted. (InterruptedException cannot be used for this purpose, since CR inherits from Number.)
Any operation may also throw com.sgi.math.PrecisionOverflowError If the precision request generated during any subcalculation overflows a 28bit integer. (This should be extremely unlikely, except as an outcome of a division by zero, or other erroneous computation.)
Field Summary  
static CR 
PI
The ratio of a circle's circumference to its diameter. 
static boolean 
please_stop
Setting this to true requests that all computations be aborted by throwing AbortedError. 
Constructor Summary  
CR()

Method Summary  
CR 
abs()
The absolute value of a constructive reals. 
CR 
add(CR x)
Add two constructive reals. 
protected abstract java.math.BigInteger 
approximate(int precision)
Must be defined in subclasses of CR. 
java.math.BigInteger 
BigIntegerValue()
Return a BigInteger which differs by less than one from the constructive real. 
int 
compareTo(CR x)
Should be called only if x != y. 
int 
compareTo(CR x,
int a)
Approximate comparison with only an absolute tolerance. 
int 
compareTo(CR x,
int r,
int a)
Return 0 if x = y to within the indicated tolerance, 1 if x < y, and +1 if x > y. 
CR 
cos()
The trigonometric cosine function. 
CR 
divide(CR x)
The quotient of two constructive reals. 
double 
doubleValue()
Return a double which differs by less than one in the least represented bit from the constructive real. 
CR 
exp()
The exponential function, i.e. 
float 
floatValue()
Return a float which differs by less than one in the least represented bit from the constructive real. 
java.math.BigInteger 
get_appr(int precision)
Returns value / 2 ** prec rounded to an integer. 
int 
intValue()
Return an int which differs by less than one from the constructive real. 
CR 
inverse()
The multiplicative inverse of a constructive real. 
CR 
ln()
The natural (base e) logarithm. 
long 
longValue()
Return a long which differs by less than one from the constructive real. 
CR 
max(CR x)
The maximum of two constructive reals. 
CR 
min(CR x)
The minimum of two constructive reals. 
CR 
multiply(CR x)
The product of two constructive reals 
CR 
negate()
The additive inverse of a constructive real 
CR 
select(CR x,
CR y)
The real number x if this < 0, or y otherwise. 
CR 
shiftLeft(int n)
Multiply a constructive real by 2**n. 
CR 
shiftRight(int n)
Multiply a constructive real by 2**(n). 
int 
signum()
Should be called only if x != 0. 
int 
signum(int a)
Equivalent to compareTo(CR.valueOf(0), a) 
CR 
sin()
The trigonometric sine function. 
CR 
sqrt()
The square root of a constructive real. 
CR 
subtract(CR x)
The difference between two constructive reals 
java.lang.String 
toString()
Equivalent to toString(10, 10) 
java.lang.String 
toString(int n)
Equivalent to toString(n,10) 
java.lang.String 
toString(int n,
int radix)
Return a textual representation accurate to n places to the right of the decimal point. 
static CR 
valueOf(java.math.BigInteger n)
The constructive real number corresponding to a BigInteger. 
static CR 
valueOf(double n)
The constructive real number corresponding to a Java double. 
static CR 
valueOf(float n)
The constructive real number corresponding to a Java float. 
static CR 
valueOf(int n)
The constructive real number corresponding to a Java int. 
static CR 
valueOf(long n)
The constructive real number corresponding to a Java long. 
static CR 
valueOf(java.lang.String s,
int radix)
Return the constructive real number corresponding to the given textual representation and radix. 
Methods inherited from class java.lang.Number 
byteValue, shortValue 
Methods inherited from class java.lang.Object 
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait 
Field Detail 
public static volatile boolean please_stop
public static CR PI
Constructor Detail 
public CR()
Method Detail 
protected abstract java.math.BigInteger approximate(int precision)
public static CR valueOf(java.math.BigInteger n)
public static CR valueOf(int n)
public static CR valueOf(long n)
public static CR valueOf(double n)
public static CR valueOf(float n)
public java.math.BigInteger get_appr(int precision)
public int compareTo(CR x, int r, int a)
x
 The other constructive realr
 Relative tolerance in bitsa
 Absolute tolerance in bitspublic int compareTo(CR x, int a)
x
 The other constructive reala
 Absolute tolerance in bitspublic int compareTo(CR x)
public int signum(int a)
public int signum()
public static CR valueOf(java.lang.String s, int radix) throws java.lang.NumberFormatException
s
 [] digit* [. digit*]radix
 public java.lang.String toString(int n, int radix)
n
 Number of digits included to the right of decimal pointradix
 Base ( >= 2, <= 16) for the resulting representation.public java.lang.String toString(int n)
n
 Number of digits included to the right of decimal pointpublic java.lang.String toString()
toString
in class java.lang.Object
public java.math.BigInteger BigIntegerValue()
public int intValue()
intValue
in class java.lang.Number
public long longValue()
longValue
in class java.lang.Number
public double doubleValue()
doubleValue
in class java.lang.Number
public float floatValue()
floatValue
in class java.lang.Number
public CR add(CR x)
public CR shiftLeft(int n)
n
 shift count, may be negativepublic CR shiftRight(int n)
n
 shift count, may be negativepublic CR negate()
public CR subtract(CR x)
public CR multiply(CR x)
public CR inverse()
public CR divide(CR x)
public CR select(CR x, CR y)
public CR max(CR x)
public CR min(CR x)
public CR abs()
public CR exp()
public CR cos()
public CR sin()
public CR ln()
public CR sqrt()


PREV CLASS NEXT CLASS  FRAMES NO FRAMES  
SUMMARY: INNER  FIELD  CONSTR  METHOD  DETAIL: FIELD  CONSTR  METHOD 