Intel® Fortran Compiler 17.0 Developer Guide and Reference
Elemental Intrinsic Function (Generic): Returns the modulo of the arguments.
result = MODULO (a,p)
a |
(Input) Must be of type integer or real. |
p |
(Input) Must have the same type and kind parameters as a. It must not have a value of zero. |
The result type is the same a. The result value depends on the type of a, as follows:
If a is of type integer and p is not equal to zero, the value of the result is a - FLOOR(REAL( a) / REAL( p)) * p, that is, the result has a value such that a = q * p + result where q is an integer. The following also applies:
If p > 0, then 0 <= result < p
If p < 0, then p < result <= 0
If a is of type real and p is not equal to zero, the value of the result is a - FLOOR( a/ p) * p.
If p is equal to zero (regardless of the type of a), the result is undefined.
MODULO (7, 3) has the value 1.
MODULO (9, -6) has the value -3.
MODULO (-9, 6) has the value 3.
The following shows more examples:
INTEGER I
REAL R
I= MODULO(8, 5) ! returns 3 Note: q=1
I= MODULO(-8, 5) ! returns 2 Note: q=-2
I= MODULO(8, -5) ! returns -2 Note: q=-2
I= MODULO(-8,-5) ! returns -3 Note: q=1
R= MODULO(7.285, 2.35) ! returns 0.2350001 Note: q=3
R= MODULO(7.285, -2.35) ! returns -2.115 Note: q=-4