- 5.2
Algorithm Conventions
The specification often uses a numbered list to specify steps in
an algorithm. These algorithms are used to clarify semantics. In
practice, there may be more efficient algorithms available to
implement a given feature.
When an algorithm is to produce a value as a result, the
directive "return x" is used to indicate that the result of
the algorithm is the value of x and that the algorithm
should terminate. The notation Result(n) is used as
shorthand for "the result of step n". Type(x) is used
as shorthand for "the type of x".
Mathematical operations such as addition, subtraction, negation,
multiplication, division, and the mathematical functions defined
later in this section should always be understood as computing
exact mathematical results on mathematical real numbers, which do
not include infinities and do not include a negative zero that is
distinguished from positive zero. Algorithms in this standard that
model floating-point arithmetic include explicit steps, where
necessary, to handle infinities and signed zero and to perform
rounding. If a mathematical operation or function is applied to a
floating-point number, it should be understood as being applied to
the exact mathematical value represented by that floating-point
number; such a floating-point number must be finite, and if it is
+0 or -0 then the corresponding mathematical value is
simply 0.
The mathematical function abs(x) yields the absolute
value of x, which is -x if x is negative (less
than zero) and otherwise is x itself.
The mathematical function sign(x) yields 1 if x is
positive and -1 if x is negative. The sign function is not used in
this standard for cases when x is zero.
The notation "x modulo y" (y must be finite and
nonzero) computes a value k of the same sign as y (or zero)
such that abs(k)< abs(y) and x-k = q
* y for some integer q.
The mathematical function floor(x) yields the largest
integer (closest to positive infinity) that is not larger than
x.
NOTE
floor(x) = x-(x modulo 1).
If an algorithm is defined to "throw an exception", execution of
the algorithm is terminated and no result is returned. The calling
algorithms are also terminated, until an algorithm step is reached
that explicitly deals with the exception, using terminology such as
"If an exception was thrown...". Once such an algorithm step has
been encountered the exception is no longer considered to have
occurred.