
nexttoward(+X, +Y, -Result)

   Next representable number

Arguments
   X                   A number
   Y                   A number
   Result              Output: number

Type
   Arithmetic

Description
   This predicate is used by the ECLiPSe compiler to expand evaluable
   arithmetic expressions.  So the call to nexttoward(Y, X, Result) is
   equivalent to

    Result is nexttoward(X, Y)

    which should be preferred for portability.

    Result is the next representable number following X in the direction
    of Y.  If Y is greater than X, the result is the smallest representable
    number greater than X.  If Y is smaller than X, the result is the
    greatest representable number smaller than X.  Otherwise the result
    is identical to X or Y.

    If X and Y are floats, the next representable value depends on the
    floating point representation.

    If X and Y are integers, the next representable value is the next integer.

    If X and Y are breals, the result is the smallest interval enclosing
    all possible results of doing the operation on elements of the input
    intervals.

    If X and Y are rationals, the operation is undefined.

    If X and Y are of different types, the types are first made equal
    (via conversions integer -> rational -> float -> breal),
    then the result is computed as above.

   In coroutining mode, if X or Y is uninstantiated, the predicate delays.



Modes and Determinism
   nexttoward(+, +, -) is det

Exceptions
     4 --- X or Y is not instantiated (non-coroutining mode only).
     5 --- Operation not defined on rational numbers
    24 --- Number is not of a numeric type.

Examples
   
Success:
      Result is nexttoward(1.0, 2.0).	% gives Result = 1.0000000000000002
      Result is nexttoward(1.0, 0.0).	% gives Result = 0.99999999999999989
      Result is nexttoward(1.0, 1.0).	% gives Result = 1.0

      Result is nexttoward(0.0, 1.0).	% gives Result = 4.94065645841247e-324
      Result is nexttoward(1.0Inf, 0.0)	% gives Result = 1.7976931348623157e+308

      Result is nexttoward(5, 9).	% gives Result = 6
      Result is nexttoward(5, 0).	% gives Result = 4
      Result is nexttoward(5, 5).	% gives Result = 5

Error:
      Result is nexttoward(3_4, 2_1).	% type error


See Also
   is / 2, abs / 2, sgn / 2
