5.4  Implementation-Supplied Numeric Functions

5.4.1 General Description

     Predefined algorithms are supplied by the implementation for the evaluation of
     commonly used numeric functions.  Additional functions related to other features of
     this Standard are defined in 6.4, 7.1, and 7.2.

5.4.2 Syntax

     1. numeric-supplied-function > ABS / ACOS / ANGLE / ASIN / ATN / CEIL / COS / COSH /
                                    COT / CSC / DATE / DEG / EPS / EXP / FP /
                                    MAXNUM / INT / IP / LOG / LOG10 / LOG2 / MAX /
                                    MIN / MOD / PI / RAD / REMAINDER / RND /
                                    ROUND / SEC / SGN / SIN / SINH / SQR / TAN /
                                    TANH / TIME / TRUNCATE
     2. randomize-statement       = RANDOMIZE

5.4.3 Examples

     2. RANDOMIZE

5.4.4 Semantics

     The values of the numeric-supplied functions, as well as the number of arguments
     required for each function, shall be as described below.  In all cases, X and Y stand
     for numeric-expressions, and N stands for an index, i.e., the rounded integer value
     of a numeric-expression.  Each function accepts numeric arguments within the range of
     the negative number with the largest magnitude to the largest positive number, except
     where noted.  For functions which return a value in angle measure (ACOS, ANGLE, ASIN
     and ATN), the value shall be in radians unless OPTION ANGLE DEGREES is in effect (see
     5.6), when the value shall be in degrees.  In the semantics below, "pi" (lower-case)
     stands for the true value of that constant.

     Function

          Function value

     ABS(X)

          The absolute value of X.

     ACOS(X)

          The arccosine of X in radians or degrees (see 5.6), where 0 <= ACOS(X) <= pi; X
          shall be in the range -1 <= X <= 1.

     ANGLE(X, Y)

          The angle in radians or degrees (see 5.6) between the positive x-axis and the
          vector joining the origin to the point with coordinates (X, Y), where -pi <
          ANGLE(X, Y) <= pi.  X and Y must not both be 0.  Note that counterclockwise is
          positive, e.g., ANGLE(1,1) = 45 degrees.

     ASIN(X)

          The arcsine of X in radians or degrees (see 5.6), where -pi/2 <= ASIN(X) <=
          pi/2; X shall be in the range -1 <= X <=1.

     ATN(X)

          The arctangent of X in radians or degrees (see 5.6), i.e., the angle whose
          tangent is X, where -(pi/2) < ATN(X) < (pi/2).

     CEIL(X)

          The smallest integer not less than X.

     COS(X)

          The cosine of X, where X is in radians or degrees (see 5.6).

     COSH(X)

          The hyperbolic cosine of X.

     COT(X)

          The cotangent of X, where X is in radians or degrees (see 5.6).

     CSC(X)

          The cosecant of X, where X is in radians or degrees (see 5.6).

     DATE

          The current date in decimal form YYDDD, where YY are the last two digits of
          the year and DDD is the ordinal number of the current day of the year; e.g.,
          the value of DATE on May 9, 1977 was 77129.  If there is no calendar
          available, then the value of DATE shall be -1.

     DEG(X)

          The number of degrees in X radians.

     EPS(X)

          The maximum of (X-X', X''-X, sigma) where X' and X'' are the predecessor and
          successor of X and sigma is the smallest positive value representable.  If X
          has no predecessor then X'=X and if X has no successor then X''=X.  Note
          EPS(0) is the smallest positive number representable by the implementation,
          and is therefore implementation-defined.  Note also that EPS may produce
          different results for different arithmetic options (see 5.6).

     EXP(X)

          The exponential of X, e.e., the value of the base of natural logarithms
          (e = 2.71828...) raised to the power X; if EXP(X) is less than machine
          infinitesimal, then its value shall be replaced by zero.

     FP(X)

          The factional part of X, i.e., X - IP(X).

     INT(X)

          The largest integer not greater than X; e.g., INT(1.3)=1 and INT(-1.3)=-2.

     IP(X)

          The integer part of X, e.e., SGN(X)*INT(ABS(X)).

     LOG(X)

          The natural logarithm of X; X shall be greater than zero.

     LOG10(X)

          The common logarithm of X; X shall be greater than zero.

     LOG2(X)

          The base 2 logarithm of X; X shall be greater than zero.

     MAX(X,Y)

          The larger (algebraically) of X and Y.

     MAXNUM

          The largest finite positive number representable and manipulable by the
          implementation; implementation-defined.  MAXNUM may represent different
          numbers for different arithmetic options (see 5.6).

     MIN(X, Y)

          The smaller (algebraically) of X and Y.

     MOD(X, Y)

          X modulo Y, i.e., X-Y*INT(X/Y). Y shall not equal zero.

     PI

          The constant 3.14159... which is the ration of the circumference of a circle
          to it's diameter.

     RAD(X)

          The number of radians in X degrees.

     REMAINDER(X, Y)

          The remainder function, ie.e., X-Y*IP(X/Y).  Y shall not equal zero.

     RND

          The next pseudo-random number in an implementation-defined sequence of
          pseudo-random numbers uniformly distributed in the range 0 <= RND < 1.

     ROUND(X, N)

          The value of X rounded to N decimal digits to the right of the decimal point
          (or -N digits to the left if N < 0); i.e., INT(X*10^N+.5)/10^N.

     SEC(X)

          The secant of X, where X is in radians or degrees (see 5.6).

     SGN(X)

          The sign of X: -1 if X < 0, 0 if X = 0, and +1 if X > 0.

     SIN(X)

          The sine of X, where X is in radians or degrees (see 5.6).

     SINH(X)

          The hyperbolic sine of X.

     SQR(X)

          The non-negative square root of X; X shall be non-negative.

     TAN(X)

          The tangent of X, where X is in radians or degrees (see 5.6).

     TANH(X)

          The hyperbolic tangent of X.

     TIME

          The time elapsed since the previous midnight, expressed in seconds; e.g., the
          value of TIME at 11:15 AM is 40500.  If there is no clock available, then the
          value of TIME shall be -1.  The value of TIME at midnight shall be zero (not
          86400).

     TRUNCATE(X, N)

          The value of X truncated to N decimal digits to the right of the decimal
          point (or -N digits to the left if N<0); i.e., IP(X*10^N)/10^N.

     If OPTION ANGLE DEGREES is in effect, then term "in radians or degrees" in the above
     list of function values shall mean degrees.  If OPTION ANGLE RADIANS is in effect, the
     term "in radians or degrees" shall mean radians.  The accuracy requirements (see
     5.6.4) for the periodic trigonometric functions SIN, COS, TAN, SEC, CSC, COT are
     limited to providing full accuracy of m+1 decimal digits only for arguments in the
     range of -2*pi to 2*pi.  Loss of accuracy outside this range is limited to the result
     of loss of precision in performing those range reductions on arguments necessary to
     compute values of these functions, i.e., "SIN (x)" may be evaluated as if it were
     written "SIN (MOD (x, 2*pi))" and similarly for the other functions.

     If no randomize-statement is executed, then the RND function shall generate the same
     sequence of pseudo-random numbers each time a program is run.  Execution of a
     randomize-statement shall override this implementation-supplied sequence of pseudo-
     rand numbers, generating a new (and unpredictable) starting point for the list of
     pseudo-random numbers used subsequently by the RND function.  The sequence of pseudo-
     random numbers shall be global to the entire program, not local to individual
     program-units.

5.4.5 Exceptions

     - The value of the argument of the LOG, LOG10, or LOG2 function is zero or negative
       (3004, fatal).

     - The value of the argument of the SQR function is negative (3005, fatal).

     - The magnitude of the value of a numeric-supplied-function is larger than MAXNUM or
       is mathematical infinity (1003, fatal).

     - The value of the second argument of the MOD or REMAINDER function is zero (3006,
       fatal).

     - The value of the argument of the ACOS or ASIN function is less than -1 or greater
       than 1 (3007, fatal).

     - An attempt is made to evaluate ANGLE(0,0) (3008, fatal).

5.4.6 Remarks

     In the case of implementations which do not have access to a randomizing device such
     as a real-time clock, the randomize statement may be implemented by means of an
     interaction with the user.

     This Standard requires that overflows be reported only for the final values of
     numeric-supplied-functions; exceptions which occur in the evaluation of these
     functions need not be reported, though implementations shall take appropriate actions
     in the event of such exceptions to insure the accuracy of the final values.  When
     overflow are reported for the final values of numeric-supplied-functions, it is
     recommended that the name of the function generating the overflow be reported also.

     It is recommended that, if the magnitude of the value of a numeric-supplied-function
     is nonzero, but less than machine infinitesimal, implementation report this as an
     underflow, set the value to zero (1503, nonfatal: return zero and continue).  In
     BASIC-2 implementations, this permits interception by exception handlers.

     The time-zone used for DATE and TIME is implementation-defined.

     It may not be possible, for reasons of overflow, to express the year in full format
     in DATE.  When this full format is needed, the function DATE$ should be used.
