Next: MOVE_ALLOC, Previous: MOD, Up: Intrinsic Procedures [Contents][Index]
MODULO
— Modulo functionMODULO(A,P)
computes the A modulo P.
Fortran 95 and later
Elemental function
RESULT = MODULO(A, P)
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. |
The type and kind of the result are those of the arguments.
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).
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.
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