Manual Reference Pages  - mod (3fortran)

NAME

MOD(3) - [NUMERIC] Remainder function

SYNOPSIS

result = mod(a, p)

         elemental type(TYPE(kind=KIND)) function mod(a,p)

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

CHARACTERISTICS

o The result and arguments are all of the same type and kind.
o The type may be any kind of real or integer.

DESCRIPTION

MOD(3) computes the remainder of the division of A by P.

In mathematics, the remainder is the amount "left over" after performing some computation. In arithmetic, the remainder is the integer "left over" after dividing one integer by another to produce an integer quotient (integer division). In algebra of polynomials, the remainder is the polynomial "left over" after dividing one polynomial by another. The modulo operation is the operation that produces such a remainder when given a dividend and divisor.
o (remainder). (2022, October 10). In Wikipedia. https://en.wikipedia.org/wiki/Remainder

OPTIONS

o A : The dividend
o P : the divisor (not equal to zero).

RESULT

The return value is the result of A - (INT(A/P) * P).

As can be seen by the formula the sign of P is canceled out. Therefore the returned value always has the sign of A.

Of course, the magnitude of the result will be less than the magnitude of P, as the result has been reduced by all multiples of P.

EXAMPLES

Sample program:

    program demo_mod
    implicit none

! basics print *, mod( -17, 3 ), modulo( -17, 3 ) print *, mod( 17, -3 ), modulo( 17, -3 ) print *, mod( 17, 3 ), modulo( 17, 3 ) print *, mod( -17, -3 ), modulo( -17, -3 )

print *, mod(-17.5, 5.2), modulo(-17.5, 5.2) print *, mod( 17.5,-5.2), modulo( 17.5,-5.2) print *, mod( 17.5, 5.2), modulo( 17.5, 5.2) print *, mod(-17.5,-5.2), modulo(-17.5,-5.2)

! with a divisor of 1 the fractional part is returned print *, mod(-17.5, 1.0), modulo(-17.5, 1.0) print *, mod( 17.5,-1.0), modulo( 17.5,-1.0) print *, mod( 17.5, 1.0), modulo( 17.5, 1.0) print *, mod(-17.5,-1.0), modulo(-17.5,-1.0)

end program demo_mod

Results:

      >          -2           1
      >           2          -1
      >           2           2
      >          -2          -2
      >  -1.900001       3.299999
      >   1.900001      -3.299999
      >   1.900001       1.900001
      >  -1.900001      -1.900001
      > -0.5000000      0.5000000
      >  0.5000000     -0.5000000
      >  0.5000000      0.5000000
      > -0.5000000     -0.5000000

STANDARD

FORTRAN 77

SEE ALSO

o MODULO(3) - Modulo function
o AINT(3) - truncate toward zero to a whole real number
o INT(3) - truncate toward zero to a whole integer number
o ANINT(3) - real nearest whole number
o NINT(3) - integer nearest whole number
Fortran intrinsic descriptions (license: MIT) @urbanjost


Nemo Release 3.1 mod (3fortran) November 02, 2024
Generated by manServer 1.08 from 011dd201-db2c-42e9-bd3a-98a791174d39 using man macros.