INT (The GNU Fortran Compiler)

### 8.156 `INT` — Convert to integer type ¶

Synopsis:

  `RESULT = INT(A [, KIND))`

Description:

  Convert to integer type

Class:

  Elemental function, extension for `UNSIGNED` (see Unsigned integers).

Arguments:

  A | Shall be of type `INTEGER`, `REAL`, `COMPLEX` or `UNSIGNED` or a boz-literal-constant.
  KIND | (Optional) A scalar `INTEGER` constant expression indicating the kind parameter of the result.

Return value:

  These functions return a `INTEGER` variable or array under the following rules:

  (A)

    If A is of type `INTEGER`, `INT(A) = A`

  (B)

    If A is of type `REAL` and |A| < 1, `INT(A)` equals `0`. If |A| \geq 1, then `INT(A)` is the integer whose magnitude is the largest integer that does not exceed the magnitude of A and whose sign is the same as the sign of A.

  (C)

    If A is of type `COMPLEX`, rule B is applied to the real part of A.

  (D)

    If A is of type `UNSIGNED` and 0 \leq A \leq `HUGE(A)`, `INT(A) = A`. Outside that range, the result is interpreted using two’s complement.

Example:

      program test_int
        integer :: i = 42
        complex :: z = (-3.7, 1.0)
        print *, int(i)
        print *, int(z), int(z,8)
      end program

Specific names:

  Name | Argument | Return type | Standard
  --- | --- | --- | ---
  `INT(A)` | `REAL(4) A` | `INTEGER` | Fortran 77 and later
  `IFIX(A)` | `REAL(4) A` | `INTEGER` | Fortran 77 and later
  `IDINT(A)` | `REAL(8) A` | `INTEGER` | Fortran 77 and later

Standard:

  Fortran 77 and later, with boz-literal-constant Fortran 2008 and later.