#
Fortran Wiki

modulo

## Description

`modulo(a,p)`

computes the `a`

modulo `p`

.

## Standard

Fortran 95 and later

## Class

Elemental function

## Syntax

`result = modulo(a, p)`

## Arguments

`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.

## Return value

The type and kind of the result are those of the arguments.

- If
`a`

and `p`

are of type `integer`

: `modulo(a,p)`

has the value of `a - floor (real(a) / real(p)) * p`

.
- 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`

.

## Example

```
program test_modulo
print *, modulo(17,3)
print *, modulo(17.5,5.5)
print *, modulo(-17,3)
print *, modulo(-17.5,5.5)
print *, modulo(17,-3)
print *, modulo(17.5,-5.5)
end program
```

## See also

mod

Revised on April 4, 2016 14:35:48
by

Jason Blevins
(128.146.137.52)
(1272 characters / 0.0 pages)