MODULO(3) - [NUMERIC] Modulo function
result = modulo(a, p)
elemental TYPE(kind=KIND) function modulo(a,p)TYPE(kind=KIND),intent(in) :: a TYPE(kind=KIND),intent(in) :: p
o A may be any kind of real or integer. o P is the same type and kind as A o The result and arguments are all of the same type and kind.
MODULO(3) computes the A modulo P.
o A : the value to take the MODULO of o P : The value to reduce A by till the remainder is <= P. 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 implicit none print *, modulo(17,3) ! yields 2 print *, modulo(17.5,5.5) ! yields 1.0Results:print *, 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
> 2 > 1.000000 > 1 > 4.500000 > -1 > -4.500000
Fortran 95
MOD(3)
Fortran intrinsic descriptions
Nemo Release 3.1 | modulo (3fortran) | November 02, 2024 |