Lahey/Fujitsu Fortran

MODULO Function

Description

The MODULO function returns the modulo of two numbers.

Syntax

MODULO (a, p)

Arguments

a is an INTENT(IN) scalar or array of type INTEGER or REAL.

p is INTENT(IN) and must be of the same type and kind as a. Its value must not be zero.

Result

The result is the same type and kind as a.

If a is a REAL, the result value is a-FLOOR(a/p)*p.

If a is an INTEGER, MODULO(a, p) has the value r such that a=q*p+r, where q is an INTEGER chosen so that r nearer to zero than p.

Example

r=modulo(23.4,4.0) ! r is assigned the value 3.4 i=modulo(-23,4) ! i is assigned the value 1 j=modulo(23,-4) ! j is assigned the value -1 k-modulo(-23,-4) ! k is assigned the value -3