The mathematics modules described in this chapter serve several purposes.
They provide access to the underlying representation of REAL
and
LONGREAL
values, as well as facilities for common mathematical
functions and constants.
The REAL
and LONGREAL
types, collectively referred to as the
real numeric types, are used to represent floating-point
numbers, which may be stored in various ways on a computer. The actual
values are approximations of real numbers and may not be wholely accurate.
Hence, precise details of the floating-point representation are often
required when creating operations that involve real numeric types in order
to minimize errors and calculate error bounds.
A full discourse on floating-point numbers, as well as more complete descriptions of algorithms used for manipulating floating-point data, is beyond the scope of this manual. For further information, consult the following references:
IEEE Standard for Binary Floating-Point Arithmetic (ANSI/IEEE STD 754-1985) (R1990) Institute of Electrical and Electronics Engineers, Inc. (IEEE) IEEE Standard for Radix-Independent Floating-Point Arithmetic (ANSI/IEEE STD 854-1987) (R1994) Institute of Electrical and Electronics Engineers, Inc. (IEEE) Information technology -- Language independent arithmetic -- Part 1: Integer and floating point arithmetic (ISO/IEC 10967-1:1994(E)) International Organization for Standardization (ISO) What Every Computer Scientist Should Know About Floating-Point Arithmetic David Goldberg ACM Computing Surveys, Vol. 23, No. 1, March 1991, pp. 5-48 Software Manual for the Elementary Functions William James Cody Prentice Hall, July 1980 Computer Approximations John F. Hart Krieger Publishing Company, June 1978
The modules LowReal
and LowLReal
give access to the underlying
properties of the types REAL
and LONGREAL
.
Default properties of the real numeric types are defined by the constants in these modules. (An implementation may provide facilities for dynamically changing properties from these defaults.)
Please note:
OOC lib LIA-1 -------- -------- radix r places p gUnderflow denorm small fmin_N expoMin emin expoMax emax
fmax
, which is required by ISO/IEC
10967-1:199x, is given by the predefined function MAX
when applied
to the corresponding real numeric type.
radix
places used
to store values of the corresponding real numeric type.
Please note: It is possible that
expoMin = expoMax
, which is likely for the case of fixed point representation.
Please note: On some systems, large
may be a machine
representation of infinity.
Please note: If an implementation has stored values strictly
between `0.0' and small
, then presumbly the implementation
supports gradual underflow.
TRUE
if, and only if, the implementation of
the corresponding real numeric type conforms to IEC 559:1989 (IEEE
754:1987) in all regards.
Please note:
IEC559
is TRUE
, the value of radix
is 2
.
LowReal.IEC559
is TRUE
, the 32-bit format of IEC
559:1989 is used for the type REAL
.
LowLReal.IEC559
is TRUE
, the 64-bit format of IEC
559:1989 is used for the type LONGREAL
.
TRUE
if, and only if, the implementation of
the corresponding real numeric type conforms to ISO/IEC 10967-1:199x
(LIA-1) in all regards: parameters, arithmetic, exceptions, and
notification.
TRUE
if, and only if, each operation produces
a result that is one of the values of the corresponding real numeric type
nearest to the mathematical result.
Please note: If rounds
is TRUE
, and the mathematical
result lies mid-way between two values of the corresponding real numeric
type, then the selection from the two possible values is
implementation-dependent.
TRUE
if, and only if, there are values of the
corresponding real numeric type between `0.0' and small
.
TRUE
if, and only if, every operation that
attempts to produce a real value out of range raises an exception.
TRUE
if, and only if, expressions of the
corresponding real numeric type are computed to higher precision than the
stored values.
Please note: If extend
is TRUE
, then values greater
than large
can be computed in expressions, but cannot be stored in
variables.
setMode
and currentMode()
procedures.
The following functions are provided in either LowReal
(for
REAL
) or LowLReal
(for LONGREAL
):
(x: REAL): INTEGER
(x: LONGREAL): INTEGER
expoMin
and expoMax
. If x=0.0
, an exception
occurs and may be raised.
(x: REAL): REAL
(x: LONGREAL): LONGREAL
x = scale(fraction(x), exponent(x))
(real: REAL): BOOLEAN
(real: LONGREAL): BOOLEAN
TRUE
if, and only if, real is a
representation of Infinity (either positive or negative).
(real: REAL): BOOLEAN
(real: LONGREAL): BOOLEAN
TRUE
if, and only if, real is a NaN ("Not
a Number") representation.
Please note: The routines
IsInfinity
andIsNaN
allow, for example, for string formatting routines to have a reasonably portable way to check whether they are dealing with out of range or illegal numbers.
(x: REAL): REAL
(x: LONGREAL): LONGREAL
Ifx > 0.0
, return1.0
Ifx = 0.0
, return either1.0
or-1.0
Ifx < 0.0
, return-1.0
Please note: The uncertainty about the handling of 0.0
is to
allow for systems that distinguish between +0.0
and -0.0
(such
as IEEE 754 systems).
(x: REAL): REAL
(x: LONGREAL): LONGREAL
(x: REAL): REAL
(x: LONGREAL): LONGREAL
Please note: When this value exists, one, or both, of the following
is true: ulp(x) = succ(x)-x
or ulp(x) = x-pred(x)
.
(x: REAL): REAL
(x: LONGREAL): LONGREAL
(x: REAL): REAL
(x: LONGREAL): LONGREAL
-intpart(abs(x))
.
(x: REAL): REAL
(x: LONGREAL): LONGREAL
fractpart(x) + intpart(x) = x
.
(x: REAL; n: INTEGER): REAL
(x: LONGREAL; n: INTEGER): LONGREAL
x*radix^n
, if such a value exists;
otherwise, an exception occurs and may be raised.
(x: REAL; n: INTEGER): REAL
(x: LONGREAL; n: INTEGER): LONGREAL
(x: REAL; n: INTEGER): REAL
(x: LONGREAL; n: INTEGER): LONGREAL
(expart: INTEGER; frapart: REAL): REAL
(expart: INTEGER; frapart: LONGREAL): LONGREAL
synthesize(exponent(x), fraction(x)) = x.
(m: Modes)
Please note:
NaN
s in implementations
conforming to IEC 559:1989 (IEEE 754:1987)).
Modes
that
may be used are not specified by this manual.
setMode
on operations on values of the corresponding
real numeric type in processes other than the calling process is not
defined. Implementations are not required to preserve the status flags (if
any) with the process state.
(): Modes
setMode
), or the default status flags (if setMode
is not
used).
Please note: The returned value is not necessarily the value set by
setMode
, because a call of setMode
might attempt to set flags
that cannot be set by the program.
(): BOOLEAN
TRUE
if the current process is in the
exceptional execution state because of the raising of the corresponding
LowReal
or LowLReal
exception; otherwise, it returns
FALSE
.
The modules RealMath
and LRealMath
provide facilities for
common mathematical functions and constants for REAL
and
LONGREAL
numeric types.
Please note: The angle in all trigonometric functions is measured in radians.
The following useful mathematical constants are provided:
Please note: Due to the approximations involved, sin(pi)
might not exactly equal zero. Similarly, exp1
might not exactly
equal exp(1)
.
The following are mathematical functions provided in either RealMath
(for REAL
) or LRealMath
(for LONGREAL
):
(x: REAL): REAL
(x: LONGREAL): LONGREAL
(x: REAL): REAL
(x: LONGREAL): LONGREAL
e
raised to the power of x.
(x: REAL): REAL
(x: LONGREAL): LONGREAL
(x: REAL): REAL
(x: LONGREAL): LONGREAL
(x: REAL): REAL
(x: LONGREAL): LONGREAL
(x: REAL): REAL
(x: LONGREAL): LONGREAL
pi/2
, an exception is raised.
(x: REAL): REAL
(x: LONGREAL): LONGREAL
[-pi/2, pi/2]
. If the absolute value of
x is greater than one, an exception is raised.
(x: REAL): REAL
(x: LONGREAL): LONGREAL
[0, pi]
. If the absolute value of
x is greater than one, an exception is raised.
(x: REAL): REAL
(x: LONGREAL): LONGREAL
[-pi/2, pi/2]
.
(base, exponent: REAL): REAL
(base, exponent: LONGREAL): LONGREAL
Please note: This function is mathematically equivalent to
exp(exponent * ln(base))
, but may be computed
differently.
(x: REAL): LONGINT
(x: LONGREAL): LONGINT
LONGINT
, an
exception occurs and may be raised.
Please note: If the value of x is midway between two integer values, the result is an implementation-defined selection of one of the two possible values.
(): BOOLEAN
TRUE
if the current process is in the
exceptional execution state because of the raising of the corresponding
RealMath
or LRealMath
exception; otherwise, it returns
FALSE
.
Very often, a program requires numbers with a greater range or accuracy than exists with the built-in Oberon-2 integer types. Hence, the module `Integers' provides facilities for arbitrary precision integer operations.
For further information on how these kinds of facilites may be implemented, consult the following reference:
The Art Of Computer Programming: Volume 2, Seminumerical Algorithms, Second Edition Donald E. Knuth Addison-Wesley Publishing Co., January 1981
The following operations are used to create initial instances of
Integer
and convert Integer
s to standard numeric
types.
(x: LONGREAL): Integer
Integer
whose value is the
largest integer not greater than x.
Example:
VAR n: Integers.Integer; n:=Integers.Entier(1.0D20); => n = 100000000000000000000 n:=Integers.Entier(1111111111.5D0); => n = 1111111111 n:=Integers.Entier(0.0); => n = 0
(x: Integer): LONGREAL
LONGREAL
. If the result cannot be represented as a LONGREAL
because the value of x is either too large or too small, this function
returns either MIN(LONGREAL)
or MAX(LONGREAL)
.
(x: LONGINT): Integer
Integer
whose value is x.
(x: Integer): LONGINT
LONGINT
.
If the result cannot be represented as a LONGINT
because the value of
x is either too large or too small, this function returns either
MIN(LONGINT)
or MAX(LONGINT)
.
Example:
VAR n: Integers.Integer; s: LONGINT; f: LONGREAL; n:=Integers.Long(1234); s:=Integers.Short(n); => s = 1234 f:=Integers.Float(n); => f = 1.23400000000000E+3 n:=Integers.Long(80000000H); s:=Integers.Short(n); => s = -2147483648 f:=Integers.Float(n); => f = -2.14748364800000E+9 n:=Integers.Long(7FFFFFFFH); s:=Integers.Short(n); => s = 2147483647 f:=Integers.Float(n); => f = 2.14748364700000E+9
The following are common mathematical operations, which operate on
Integer
s:
(x: Integer): Integer
(x: Integer): BOOLEAN
TRUE
if x is an odd number, and
FALSE
if it is even.
(x, y: Integer): LONGINT
Ifx > y
, return1
Ifx = y
, return0
Ifx < y
, return-1
(x, y: Integer): Integer
x-y
).
Example:
VAR n: Integers.Integer; n:=Integers.Difference(Integers.Long(2000000), Integers.Long(999)); => n = 1999001 n:=Integers.Difference(Integers.Long(999), Integers.Long(-2000000)); => n = -2000999 n:=Integers.Difference(Integers.Long(-999), Integers.Long(999)); => n = -1998 n:=Integers.Difference(Integers.Long(-2000000), Integers.Long(-999)); => n = -1999001
(x, y: Integer): Integer
x+y
).
Example:
VAR n: Integers.Integer; n:=Integers.Sum(Integers.Long(999), Integers.Long(2000000)); => n = 2000999 n:=Integers.Sum(Integers.Long(999), Integers.Long(-2000000)); => n = -1999001 n:=Integers.Sum(Integers.Long(-999), Integers.Long(999)); => n = 0 n:=Integers.Sum(Integers.Long(-2000000), Integers.Long(-999)); => n = -2000999
(x, y: Integer): Integer
x*y
).
Example:
VAR n: Integers.Integer; n:=Integers.Product(Integers.Long(100000000), Integers.Long(100000000)); => n = 10000000000000000 n:=Integers.Product(Integers.Long(71234), Integers.Long(66000)); => n = 4701444000
(x, y: Integer): Integer
x DIV y
).
Pre-condition: y is not zero.
(x, y: Integer): Integer
x MOD y
).
Pre-condition: y is not zero.
Example:
VAR m, n: Integers.Integer; n:=Integers.Quotient(Integers.Long(2000000000), Integers.Long(1234)); m:=Integers.Remainder(Integers.Long(2000000000), Integers.Long(1234)); => n = 1620745, m = 670 n:=Integers.Quotient(Integers.Long(2000000000), Integers.Long(123456)); m:=Integers.Remainder(Integers.Long(2000000000), Integers.Long(123456)); => n = 16200, m = 12800
(x, y: Integer; VAR quo, rem: Integer)
Pre-condition: y is not zero.
Example:
VAR m, n: Integers.Integer; Integers.QuoRem(Integers.Long(2000000000), Integers.Long(1234), n, m); => n = 1620745, m = 670 Integers.QuoRem(Integers.Long(2000000000), Integers.Long(123456), n, m); => n = 16200, m = 12800
(x, y: Integer): Integer
Example:
VAR n: Integers.Integer; n:=Integers.GCD(Integers.Long(40902), Integers.Long(24140)); => n = 34 n:=Integers.GCD(Integers.Long(27182818), Integers.Long(10000000)); => n = 2 n:=Integers.GCD(Integers.Long(2940), Integers.Long(238)); => n = 14
(x: Integer; exp: LONGINT): Integer
Pre-condition: exp is greater than zero.
Example:
VAR n: Integers.Integer; n:=Integers.Power(Integers.Long(2940), 2); => n = 8643600 n:=Integers.Power(Integers.Long(2), 33); => n = 8589934592 n:=Integers.Power(Integers.Long(10), 9); => n = 1000000000 n:=Integers.Power(Integers.Long(2), 100); => n = 1267650600228229401496703205376
(x: Integer): SHORTINT
Ifx > 0
, return1
Ifx = 0
, return0
Ifx < 0
, return-1
(x: LONGINT): Integer
x!=x(x-1)(x-2)...(2)(1)
).
Pre-condition: x is not negative.
VAR n: Integers.Integer; n:=Integers.Factorial(13); => n = 6227020800 n:=Integers.Factorial(20); => n = 2432902008176640000
The following operations are used to extract pieces of Integers
:
(x: Integer; exp10: LONGINT): CHAR
Pre-condition: exp10 is not negative.
VAR n: Integers.Integer; c: CHAR; Integers.ConvertFromString("1267650600228229401496703205376", n); c:=Integers.ThisDigit10(n, 0); => c = "6" c:=Integers.ThisDigit10(n, 10); => c = "9" c:=Integers.ThisDigit10(n, 30); => c = "1"
(x: Integer): LONGINT
x MOD 1000000000
).
Example:
VAR n: Integers.Integer; s: LONGINT; Integers.ConvertFromString("1267650600228229401496703205376", n); s:=Integers.Digits10Of(n); => s = 703205376
The following operations are used to convert between strings and
Integer
s:
(s: ARRAY OF CHAR; VAR x: Integer)
Integer
value, which is
assigned to x. Leading spaces and tab characters in s are
skipped.
Pre-condition: s is in the form of a signed whole number (see section Syntax of Text Tokens)
(x: Integer; VAR s: ARRAY OF CHAR)
Example:
VAR n: Integers.Integer; str: ARRAY 1024 OF CHAR; Integers.ConvertFromString("1234567890", n); => n = 1234567890 Integers.ConvertToString(n, str); => str = "1234567890" Integers.ConvertFromString(" -9999999999", n); => n = -9999999999 Integers.ConvertToString(n, str); => str = "-9999999999" Integers.ConvertFromString(" 12345678901234567890123456789", n); => n = 12345678901234567890123456789 Integers.ConvertToString(n, str); => str = "12345678901234567890123456789"
The following operations can be used to internalize and externalize
Integers
(i.e., read from and write to channels):
(VAR w: BinaryRider.Writer; x: Integer)
(VAR r: BinaryRider.Reader; VAR x: Integer)
Integer
value from a channel using reader r,
and assigns it to x.
Module `Reals' provides facilities for arbitrary precision floating
point operations. Real numbers are represented by type Real
.
These facilities are based on a FORTRAN library (MPFUN) created by David
H. Bailey. For more information, see
http://www.nersc.gov/~dhb/
or contact mp-request@nas.nasa.gov.
Numeric Precision-setting Constants
The following operations are used to create initial instances of Real
and convert Real
s to standard numeric types.
(x: LONGREAL): Real
Real
whose value is x.
(a: Real): Real
Real
that has the same value
as a.
The following operations are used to convert between strings and
Reals
:
(str: ARRAY OF CHAR): Real
Real
value and returns the
result.
The numeric representation of str must be of the format
number = ["+" | "-"] {decimal_digit} ["." {decimal_digit}] [scale] where scale = ("E" | "D") ["+" | "-"] decimal_digit {decimal_digit} and decimal_digit = "0".."9" | " "
Thus the following is a valid input:
"1.23456 12938 23456 E + 200"
Please note: This real number definition is backwardly compatible with the Oberon-2 real string, but it has been extended to allow splitting of very large numbers into more readable segments by inserting spaces.
(a: Real; VAR str: ARRAY OF CHAR; n: LONGINT)
(q: Real): LONGREAL
LONGREAL
value. If the result cannot be represented as a LONGREAL
because the
value of q is either too large or too small, this function returns
either MIN(LONGREAL)
or MAX(LONGREAL)
.
(q: Real): Real
Real
whose value is the largest
integer not greater than q.
Example:
VAR n: Reals.Real; n:=entier(Reals.Long(3.6)); (* ENTIER(3.6) *) => n = 3.0E+0 n:=entier(Reals.Long(-3.6)); (* ENTIER(-3.6) *) => n = -4.0E+0
(q: Real): Real
(z1, z2: Real): Real
z1+z2
).
(z1, z2: Real): Real
z1-z2
).
(z1, z2: Real): Real
z1*z2
).
(z1, z2: Real): Real
z1/z2
).
Pre-condition: z2 is not zero.
Example:
VAR m, n, s: Reals.Real; m:=Reals.ToReal("0.123456789012345678901234567890123456790"); => m = 1.234567890123456789012345678E-1 n:=Reals.ToReal("123456789012345678901234567890123456789"); => n = 1.234567890123456789012345678E+38 s:=Reals.add(n, m); => s = 1.234567890123456789012345678E+38 s:=Reals.sub(n, m); => s = 1.234567890123456789012345678E+38 s:=Reals.div(n, m); => s = 1.0E+39 s:=Reals.mul(n, m); => s = 1.524157875323883675049535156E+37 s:=Reals.div(Reals.Long(1), Reals.Long(3)); (* 1/3 *) => s = 3.333333333333333333333333333E-1 n:=Reals.add(s, s); (* 1/3+1/3 *) => n = 6.666666666666666666666666666E-1 s:=Reals.div(Reals.Long(1), Reals.Long(3)); (* 1/3 *) => s = 3.333333333333333333333333333E-1 n:=Reals.mul(s, s); (* 1/3*1/3 *) => n =1.111111111111111111111111111E-1 s:=Reals.div(Reals.Long(1), Reals.Long(3)); (* 1/3 *) => s = 3.333333333333333333333333333E-1 n:=Reals.mul(s, Reals.Long(3)); (* 1/3*3 *) => n = 1.0E+0
(z: Real): Real
(a, b: Real): LONGINT
Ifa > b
, return1
Ifa = b
, return0
Ifa < b
, return-1
Note that this operation is faster than merely subtracting a and b and examining the sign of the result.
(x, exp: Real): Real
Pre-condition: exp is greater than zero.
Example:
VAR n: Reals.Real; n:=Reals.power(Reals.Long(2.0), Reals.Long(64)); (* 2^64 *) => n = 1.8446744073709551616E+19
(z: Real; n: LONGINT): Real
Pre-condition: z is non-negative.
Example:
VAR n: Reals.Real; n:=Reals.root(Reals.Long(-8), 3); (* -8^(-1/3) *) => n = -2.0E+0 n:=Reals.root(Reals.power(Reals.Long(2), Reals.Long(64)), 64); => n = 2.0E+0 (* (2^64)^(-1/64) *)
(z: Real): Real
[-pi/2, pi/2]
.
Pre-condition: x is non-negative.
(z: Real): Real
e
raised to the power of z).
(z: Real): Real
Pre-condition: z is positive.
(z, base: Real): Real
Pre-condition: z is positive.
Example:
VAR n: Reals.Real; n:=Reals.log(Reals.eps, Reals.Long(10)); (* log10(eps) *) => n = -4.9E+2
(z: Real): Real
(z: Real): Real
(z: Real; VAR sin, cos: Real)
Example:
VAR m, n: Reals.Real; Reals.sincos(pi, m, n); => m = 0.0E+0 (* Sin(pi) *) => n =-1.0E+0 (* Cos(pi) *) Reals.sincos(div(pi, Reals.Long(8)), m, n); => m = 3.82683432365089771728459984E-1 (* Sin(pi/8) *) => n = 9.238795325112867561281831893E-1 (* Cos(pi/8) *) Reals.sincos(Reals.Long(1), m, n); => m = 8.414709848078965066525023216E-1 (* Sin(1) *) => n = 5.403023058681397174009366074E-1 (* Cos(1) *)
(z: Real): Real
Pre-condition: z is not an odd multiple of pi/2
.
(z: Real): Real
[-pi/2, pi/2]
.
Pre-condition: the absolute value of z is less than or equal to one.
Example:
VAR n: Reals.Real; n:=Reals.arcsin(Reals.sin(Reals.Long(1))); (* arcsin(sin(1)) *) => n = 1.0E+0
(z: Real): Real
[0, pi]
.
Pre-condition: the absolute value of z is less than or equal to one.
(z: Real): Real
[-pi/2, pi/2]
.
Example:
VAR n: Reals.Real; n:=Reals.mul(Reals.Long(4), Reals.arctan(Reals.Long(1))); (* 4*arctan(1) *) => n = 3.141592653589793238462643383E+0
(xn, xd: Real): Real
xn/xd
. The signs
of the two arguments are taken into account when determining quadrant
information. The result is in the range [-pi, pi]
.
(z: Real; VAR sinh, cosh: Real)
(z: Real): Real
(z: Real): Real
(z: Real): Real
(words: INTEGER)
curMant
).
The modules ComplexMath
and LComplexMath
provide facilities
for complex numbers, which includes common mathematical functions for types
COMPLEX
and LONGCOMPLEX
.
Instances of the following two classes are used to represent complex numbers:
REAL
LONGREAL
Please note: To create initial instances of COMPLEX
and
LONGCOMPLEX
, you must use the corresponding CMPLX()
function.
The following are instances of the corresponding complex number type. They are provided for convenience and have values that represent the specified complex number:
i
is initialized to CMPLX (0.0, 1.0)
.
one
is initialized to CMPLX (1.0, 0.0)
.
zero
is initialized to CMPLX (0.0, 0.0)
.
The following functions are provided in either ComplexMath
(for
COMPLEX
) or
LComplexMath
(for LONGCOMPLEX
):
(r, i: REAL): COMPLEX
(r, i: LONGREAL): LONGCOMPLEX
(z: COMPLEX): COMPLEX
(z: LONGCOMPLEX): LONGCOMPLEX
Please note: This function provides the only reliable way to assign
complex number values. If a
and b
are complex numbers,
do not use a := b
.
(z: COMPLEX): REAL
(z: LONGCOMPLEX): LONGREAL
(z: COMPLEX): REAL
(z: LONGCOMPLEX): LONGREAL
(z1, z2: COMPLEX): COMPLEX
(z1, z2: LONGCOMPLEX): LONGCOMPLEX
(z1, z2: COMPLEX): COMPLEX
(z1, z2: LONGCOMPLEX): LONGCOMPLEX
(z1, z2: COMPLEX): COMPLEX
(z1, z2: LONGCOMPLEX): LONGCOMPLEX
(z1, z2: COMPLEX): COMPLEX
(z1, z2: LONGCOMPLEX): LONGCOMPLEX
(z: COMPLEX): REAL
(z: LONGCOMPLEX): LONGREAL
Please note: An overflow exception may be raised in this computation, even when the complex number itself is well defined.
(z: COMPLEX): REAL
(z: LONGCOMPLEX): LONGREAL
[-pi, pi]
. If the modulus (abs(x)
) of
z is zero, an exception is raised.
(z: COMPLEX): COMPLEX
(z: LONGCOMPLEX): LONGCOMPLEX
(base: COMPLEX; exponent: REAL): COMPLEX
(base: LONGCOMPLEX; exponent: LONGREAL): LONGCOMPLEX
(z: COMPLEX): COMPLEX
(z: LONGCOMPLEX): LONGCOMPLEX
Please note: The result is the complex number with an arg()
of half the value of the arg()
of z, and whose abs()
is the
positive square root of the abs()
of z.
(z: COMPLEX): COMPLEX
(z: LONGCOMPLEX): LONGCOMPLEX
e
raised to the power of z.
(z: COMPLEX): COMPLEX
(z: LONGCOMPLEX): LONGCOMPLEX
(z: COMPLEX): COMPLEX
(z: LONGCOMPLEX): LONGCOMPLEX
(z: COMPLEX): COMPLEX
(z: LONGCOMPLEX): LONGCOMPLEX
(z: COMPLEX): COMPLEX
(z: LONGCOMPLEX): LONGCOMPLEX
pi/2
, an exception is raised.
(z: COMPLEX): COMPLEX
(z: LONGCOMPLEX): LONGCOMPLEX
(z: COMPLEX): COMPLEX
(z: LONGCOMPLEX): LONGCOMPLEX
(z: COMPLEX): COMPLEX
(z: LONGCOMPLEX): LONGCOMPLEX
(abs, arg: REAL): COMPLEX
(abs, arg: LONGREAL): LONGCOMPLEX
(scalar: REAL; z: COMPLEX): COMPLEX
(scalar: LONGREAL; z: LONGCOMPLEX): LONGCOMPLEX
(): BOOLEAN
TRUE
if the current process is in the
exceptional execution state because of the raising of the corresponding
ComplexMath
or LComplexMath
exception; otherwise, it returns
FALSE
.
"Random number" generating routines, like those provided in module `RandomNumbers', are more correctly called pseudo-random number generators because they have only the appearance of randomness, and actually exhibit a specific, repeatable pattern. However, the generated sequence of numbers should pass certain statistical tests as if it were a truly random sequence.
The algorithm implemented by `RandomNumbers' is "good" in the sense that it passes many of these statistical tests, but it is not necessarily useful in all cases. A different algorithm might be better suited to a particular application simply because the inherent structure of the generated number sequence better satisfies the application's required properties.
Because of the deterministic quality of random number generators, the user is required to specify an initial value, or seed. Sequences generated using the same seed (and the same algorithm) will always produce the same results. To get a different sequence, simply use a different seed. A common way to generate different seeds is to initialize using the system's clock time. (This is not done directly within `RandomNumbers' because then it is not possible to reproduce results, which could cause difficulties during, say, testing and debugging.)
Also note that sequences will repeat themselves eventually. In this
case, a sequence will start to repeat after, at most, modulo-1
elements, and possibly much sooner than that.
A complete discussion of random number generating algorithms is beyond the scope of this manual. For more information about the algorithm used in this module, and other random number generators, consult the following references:
Random number generators: good ones are hard to find S.K. Park and K.W. Miller Communications of the ACM, Vol. 31, No. 10, October 1988, pp. 1192-1201 The Art Of Computer Programming: Volume 2, Seminumerical Algorithms, Second Edition Donald E. Knuth Addison-Wesley Publishing Co., January 1981
(VAR seed: LONGINT)
(seed: LONGINT)
[1..modulo-1]
.
(range: LONGINT): LONGINT
[1..modulo-1]
, and the result is a number in the interval
[0, range-1]
.
(): REAL
[0, 1)
.
Example:
VAR l: LONGINT; r: REAL; RandomNumbers.PutSeed(314159); l := RandomNumbers.RND(100); => l = 19 l := RandomNumbers.RND(10000); => l = 5610 l := RandomNumbers.RND(9999999); => l = 6158792 l := RandomNumbers.RND(365); => l = 54 RandomNumbers.GetSeed(l); => l = 143441039 r := RandomNumbers.Random(); => r = 0.6225381 r := RandomNumbers.Random(); => r = 0.9990177 r := RandomNumbers.Random(); => r = 0.4895853 r := RandomNumbers.Random(); => r = 0.4605866 RandomNumbers.GetSeed(l); => l = 989102265
Go to the first, previous, next, last section, table of contents.