Manual Reference Pages  - modulo (3fortran)

NAME

MODULO(3) - [NUMERIC] Modulo function

SYNOPSIS

result = modulo(a, p)

         elemental TYPE(kind=KIND) function modulo(a,p)

TYPE(kind=KIND),intent(in) :: a TYPE(kind=KIND),intent(in) :: p

CHARACTERISTICS

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.

DESCRIPTION

MODULO(3) computes the A modulo P.

OPTIONS

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.

RESULT

The type and kind of the result are those of the arguments.
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.
The returned value has the same sign as P and a magnitude less than the magnitude of P.

EXAMPLES

Sample program:

    program demo_modulo
    implicit none
         print *, modulo(17,3)        ! yields 2
         print *, modulo(17.5,5.5)    ! yields 1.0

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

Results:

     >            2
     >    1.000000
     >            1
     >    4.500000
     >           -1
     >   -4.500000

STANDARD

Fortran 95

SEE ALSO

MOD(3)

fortran-lang intrinsic descriptions


Nemo Release 3.1 modulo (3fortran) April 28, 2024
Generated by manServer 1.08 from 2caec0bb-06b6-4d43-aa69-7c6aed96874d using man macros.