RealFns.mesa
Copyright Ó 1985, 1986, 1987, 1991 by Xerox Corporation. All rights reserved.
Stewart, August 27, 1982 11:21 am
E. McCreight, November 16, 1984 11:47:34 am PST (RealFnsExtras)
Russ Atkinson (RRA) November 14, 1986 7:06:17 pm PST
Doug Wyatt, January 15, 1987 1:14:03 pm PST
Willie-s, August 6, 1991 1:05 pm PDT
RealFns: CEDAR DEFINITIONS
= BEGIN
Exponent and logarithm functions
Exp: PROC [REAL] RETURNS [REAL];
For an input argument n, returns e^n (e=2.718...).
Computed by continued fractions.
Ln: PROC [REAL] RETURNS [REAL];
Computes the natural logarithm (base e) of the input argument.
Log: PROC [base, arg: REAL] RETURNS [REAL];
Computes logarithm to the base base of arg.
Computed by Ln(arg)/Ln(base).
Power: PROC [base, exponent: REAL] RETURNS [REAL];
Calculates base to the exponent power by e(exponent*Ln(base)).
Root: PROC [index, arg: REAL] RETURNS [REAL];
Calculates the index root of arg by e(Ln(arg)/index).
SqRt: PROC [REAL] RETURNS [REAL];
Calculates the square root of the input value by Newton's iteration.
Trigonometric functions
Sin: PROC [radians: REAL] RETURNS [sin: REAL];
SinDeg: PROC [degrees: REAL] RETURNS [sin: REAL];
Cos: PROC [radians: REAL] RETURNS [cos: REAL];
CosDeg: PROC [degrees: REAL] RETURNS [cos: REAL];
Tan: PROC [radians: REAL] RETURNS [tan: REAL];
TanDeg: PROC [degrees: REAL] RETURNS [tan: REAL];
Computes the trigonometric functions by polynomial;
good to 7.33 decimal places.
ArcTan: PROC [y, x: REAL] RETURNS [radians: REAL];
ArcTanDeg: PROC [y, x: REAL] RETURNS [degrees: REAL];
Good to 8.7 decimal places.
CoTan: PROC [radians: REAL] RETURNS [cotan: REAL];
CoTanDeg: PROC [degrees: REAL] RETURNS [cotan: REAL];
ArcSin: PROC [x: REAL] RETURNS [ REAL];
ArcSinDeg: PUBLIC PROC [x: REAL] RETURNS [degrees: REAL];
ArcCos: PROC[x: REAL] RETURNS [REAL];
ArcCosDeg: PUBLIC PROC [x: REAL] RETURNS [degrees: REAL];
Hyperbolic circle functions
SinH: PROC [x: REAL] RETURNS [REAL];
Hyperbolic sine
CosH: PROC [x: REAL] RETURNS [REAL];
Hyperbolic cosine
TanH: PROC [x: REAL] RETURNS [REAL];
Hyperbolic tangent
CotH: PROC [x: REAL] RETURNS [REAL];
Hyperbolic cotangent
InvSinH: PROC [x: REAL] RETURNS [REAL];
InvCosH: PROC [x: REAL] RETURNS [REAL];
...defined for x >= 1.0, returns non-negative result
InvTanH: PROC [x: REAL] RETURNS [REAL];
...defined for x IN (-1.0..1.0)
InvCotH: PROC [x: REAL] RETURNS [REAL];
...defined for x NOT IN [-1.0..1.0]
Gamma functions
LnGamma: PROC [x: REAL] RETURNS [REAL];
.. defined for x>0
Gamma: PROC [x: REAL] RETURNS [REAL];
.. defined for x>0; computed by Exp[LnGamma[x]]
Gamma[x+1] = x! for integer x.
Bessel functions
J0: PROC [x: REAL] RETURNS [REAL];
Bessel function of first kind of order 0
J1: PROC [x: REAL] RETURNS [REAL];
Bessel function of first kind of order 1
Jn: PROC [n: INT, x: REAL] RETURNS [REAL];
Bessel function of first kind of order n
Rational approximation
Rational: TYPE ~ RECORD [numerator: INT, denominator: INT];
RationalFromReal: PROC [x: REAL, limit: INT ¬ INT.LAST] RETURNS [Rational];
... computes the best rational approximation to a real using continued fractions.
|numerator| <= limit, 0 < denominator <= limit.
Approximate equality
AlmostZero: PROC [x: REAL, distance: [-126..127]] RETURNS [BOOL];
AlmostZero[x, distance] ==
ABS[x] < 2^distance
AlmostEqual: PROC [y, x: REAL, distance: [-126..0]] RETURNS [BOOL];
AlmostEqual[y, x, distance] ==
NotNaN[x] AND NotNaN[y] AND
ABS[x-y] <= MAX[ABS[x], ABS[y]] * 2^distance
Notes:
When either number is a Nan (not-a-number), then equality is never guaranteed, so FALSE is a conservative answer.
Comparing anything against 0.0 can give surprising results using the above definition, since ABS[x-0] = MAX[ABS[x], ABS[0]], which implies that AlmostEqual[0, x, distance] is only true for distance = 0.
END.