OUT_OF_RANGE (The GNU Fortran Compiler)

### 8.219 `OUT_OF_RANGE` — Range check for numerical conversion ¶

Synopsis:

  `RESULT = OUT_OF_RANGE(X, MOLD[, ROUND])`

Description:

  `OUT_OF_RANGE(X, MOLD[, ROUND])` determines if the value of `X` can be safely converted to an object with the type of argument `MOLD`.

Class:

  Elemental function

Arguments:

  X | The type shall be either `INTEGER`, `UNSIGNED` or `REAL`.
  MOLD | The type shall be a scalar `INTEGER`, `UNSIGNED` or `REAL`. If it is a variable, it need not be defined.
  ROUND | (Optional) A scalar `LOGICAL` that shall only be present if X is of type `REAL` and MOLD is of type `INTEGER` or `UNSIGNED`.

Return value:

  The return value is of type `LOGICAL`.

  If MOLD is of type `INTEGER` or `UNSIGNED`, and ROUND is absent or present with the value false, the result is true if and only if the value of X is an IEEE infinity or NaN, or if the integer with largest magnitude that lies between zero and X inclusive is not representable by objects with the type and kind of MOLD.

  If MOLD is of type `INTEGER` or `UNSIGNED`, and ROUND is present with the value true, the result is true if and only if the value of X is an IEEE infinity or NaN, or if the integer nearest X, or the integer of greater magnitude if two integers are equally near to X, is not representable by objects with the type and kind of MOLD.

  Otherwise, the result is true if and only if the value of X is an IEEE infinity or NaN that is not supported by objects of the type and kind of MOLD, or if X is a finite number and the result of rounding the value of X to the model for the kind of MOLD has magnitude larger than that of the largest finite number with the same sign as X that is representable by objects with the type and kind of MOLD.

Example:

      PROGRAM test_out_of_range
        PRINT *, OUT_OF_RANGE (-128.5, 0_1)           ! Will print: F
        PRINT *, OUT_OF_RANGE (-128.5, 0_1, .TRUE.)   ! Will print: T
      END PROGRAM

Standard:

  Fortran 2018