Next: , Previous: MOD, Up: Intrinsic Procedures


8.80 MODULO — Modulo function

Description:
MODULO(A,P) computes the A modulo P.
Option:
f95, gnu
Class:
elemental function
Syntax:
X = MODULO(A,P)
Arguments:

A shall be a scalar of type INTEGER or REAL
P shall be a scalar of the same type and kind as A

Return value:
The type and kind of the result are those of the arguments.
If A and P are of type INTEGER:
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.
In all cases, if P is zero the result is processor-dependent.
Example:
          program test_mod
            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 test_mod
     

Specific names:

Name Arguments Return type Option
AMOD(A,P) REAL(4) REAL(4) f95, gnu
DMOD(A,P) REAL(8) REAL(8) f95, gnu