MODULO (The GNU Fortran Compiler)

### 8.210 `MODULO` — Modulo function ¶

Synopsis:

  `RESULT = MODULO(A, P)`

Description:

  `MODULO(A,P)` computes the A modulo P.

Class:

  Elemental function

Arguments:

  A | Shall be a scalar of type `INTEGER` or `REAL`.
  P | Shall be a scalar of the same type and kind as A. It shall not be zero. (As a GNU extension, arguments of different kinds are permitted.)

Return value:

  The type and kind of the result are those of the arguments. (As a GNU extension, kind is the largest kind of the actual arguments.)

  If A and P are of type `INTEGER` or `UNSIGNED`:

    `MODULO(A,P)` has the value R such that `A=Q*P+R`, where Q is an integer and R is between 0 (inclusive) and P (exclusive).

  If A and P are of type `REAL`:

    `MODULO(A,P)` has the value of `A - FLOOR (A / P) * P`.

  The returned value has the same sign as P and a magnitude less than the magnitude of P.

Notes:

  `MOD` and `MODULO` yield identical results if their arguments are `UNSIGNED`.

Example:

      program test_modulo
        print *, modulo(17,3)
        print *, modulo(17.5,5.5)

        print *, modulo(-17,3)
        print *, modulo(-17.5,5.5)

        print *, modulo(17,-3)
        print *, modulo(17.5,-5.5)
      end program

Standard:

  Fortran 95 and later, extension for `UNSIGNED` (see Unsigned integers)

See also:

  `MOD` — Remainder function