# The RealFloat, LongFloat and ExtendedFloat interfaces

For definitions of the terms used in these interfaces, see the ANSI/IEEE Standard 754-1985 for floating-point arithmetic.

These interfaces define operations that depend on the floating-point representation. They are all are instances of a generic interface `Float`:

        INTERFACE RealFloat = Float(Real) END RealFloat.
        INTERFACE LongFloat = Float(LongReal) END LongFloat.
        INTERFACE ExtendedFloat = Float(Extended) END ExtendedFloat.

    GENERIC INTERFACE Float(R); TYPE T = R.T;

This generic interface provides access to the floating-point operations required or recommended by the IEEE floating-point standard. Consult the standard for the precise specifications of the procedures, including when their arguments are NaNs, infinities, and signed zeros, and including what exceptions they can raise. The comments here specify their effect when the arguments are ordinary numbers and no exception is raised. Implementations on non-IEEE machines that have values similar to NaNs and infinities should explain how those values behave in an implementation guide.

    PROCEDURE Scalb(x: T; n: INTEGER): T;

Return `x * 2^n`.

    PROCEDURE Logb(x: T): T;

Return the exponent of `x`. More precisely, return the unique `n` such that the ratio `ABS(x) / Base^n` is in the range `[1..Base-1]`, unless `x` is denormalized, in which case return the minimum exponent value for `T`.

    PROCEDURE ILogb(x: T): INTEGER;

Like `Logb`, but returns an integer, never raises an exception, and always returns the `n` such that `ABS(x) / Base^n` is in the range `[1..Base-1]`, even for denormalized numbers.

    PROCEDURE NextAfter(x, y: T): T;

Return the next representable neighbor of `x` in the direction towards `y`. If `x = y`, return `x`.

    PROCEDURE CopySign(x, y: T): T;

Return `x` with the sign of `y`.

    PROCEDURE Finite(x: T): BOOLEAN;

Return `TRUE` if `x` is strictly between minus infinity and plus infinity. This always returns `TRUE` on non-IEEE machines.

    PROCEDURE IsNaN(x: T): BOOLEAN;

Return `FALSE` if `x` represents a numerical (possibly infinite) value, and `TRUE` if `x` does not represent a numerical value. For example, on IEEE implementations, returns `TRUE` if `x` is a `NaN`, `FALSE` otherwise.

    PROCEDURE Sign(x: T): [0..1];

Return the sign bit of `x`. For non-IEEE implementations, this is the same as `ORD(x >= 0)`; for IEEE implementations, `Sign(-0) = 1` and `Sign(+0) = 0`.

    PROCEDURE Differs(x, y: T): BOOLEAN;

Return `(x < y OR y < x)`. Thus, for IEEE implementations, `Differs(NaN,x)` is always `FALSE`; for non-IEEE implementations, `Differs(x,y)` is the same as `x # y`.

    PROCEDURE Unordered(x, y: T): BOOLEAN;

Return `NOT (x <= y OR y <= x)`.

    PROCEDURE Sqrt(x: T): T;

Return the square root of `T`. This must be correctly rounded if `FloatMode.IEEE` is `TRUE`.

    TYPE IEEEClass =
     {SignalingNaN, QuietNaN, Infinity, Normal, Denormal, Zero};

    PROCEDURE Class(x: T): IEEEClass;

Return the IEEE number class containing `x`.

    END Float.

    Last modified on Wed Apr  3 09:39:07 PST 1996 by heydon
         modified on Thu Jun  1 08:10:14 PDT 1995 by kalsow