modulo(3f) - [FORTRAN:INTRINSIC:NUMERIC] Modulo function
Syntax
Description
Arguments
Return Value
Example
Standard
Class
See Also
result = modulo(a, p)
modulo(a,p) computes the A modulo 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.
The returned value has the same sign as P and a magnitude less than the magnitude of P.
o If A and P are of type INTEGER: modulo(a,p) has the value of a - floor (real(a) / real(p)) * p. o If A and P are of type REAL: modulo(a,p) has the value of a - floor (a / p) * p.
Sample program:
program demo_modulo print *, modulo(17,3) ! yields 2 print *, modulo(17.5,5.5) ! yields 1.0print *, modulo(-17,3) ! yields 1 print *, modulo(-17.5,5.5) ! yields 4.5
print *, modulo(17,-3) ! yields -1 print *, modulo(17.5,-5.5) ! yields -4.5 end program demo_modulo
[[Fortran 95]] and later
[[Elemental procedure|Elemental function]]
[[mod]]
modulo (3) | March 18, 2019 |