Clicky

Fortran Wiki
mod

Skip the Navigation Links | Home Page | All Pages | Recently Revised | Authors | Feeds | Export |

Description

mod(a,p) computes the remainder of the division of a by p.

Standard

FORTRAN 77 and later

Class

Elemental function

Syntax

result = mod(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 and not equal to zero.

Return value

The return value is the result of a - (int(a/p) * p). The type and kind of the return value is the same as that of the arguments. The returned value has the same sign as a and a magnitude less than the magnitude of p.

Example

program test_mod
 print *, mod(17,3) ! yields 2
 print *, mod(17.5,5.5) ! yields 1.0
 print *, mod(17.5d0,5.5) ! yields 1.0d0
 print *, mod(17.5,5.5d0) ! yields 1.0d0
 print *, mod(-17,3) ! yields -2
 print *, mod(-17.5,5.5) ! yields -1.0
 print *, mod(-17.5d0,5.5) ! yields -1.0d0
 print *, mod(-17.5,5.5d0) ! yields -1.0d0
 print *, mod(17,-3) ! yields 2
 print *, mod(17.5,-5.5) ! yields 1.0
 print *, mod(17.5d0,-5.5) ! yields 1.0d0
 print *, mod(17.5,-5.5d0) ! yields 1.0d0
end program test_mod

See also

modulo

category: intrinsics

Revised on April 4, 2016 14:40:24 by Jason Blevins (128.146.137.52) (1418 characters / 0.0 pages)
Edit | Back in time (2 revisions) | See changes | History | Views: Print | TeX | Source | Linked from: Intrinsic procedures, modulo

AltStyle によって変換されたページ (->オリジナル) /