blob: 191f475a938ec75dfb9012ce44c6058cce0d63dd [file]
<html lang="en">
<head>
<title>MOD - The GNU Fortran Compiler</title>
<meta http-equiv="Content-Type" content="text/html">
<meta name="description" content="The GNU Fortran Compiler">
<meta name="generator" content="makeinfo 4.13">
<link title="Top" rel="start" href="index.html#Top">
<link rel="up" href="Intrinsic-Procedures.html#Intrinsic-Procedures" title="Intrinsic Procedures">
<link rel="prev" href="MINVAL.html#MINVAL" title="MINVAL">
<link rel="next" href="MODULO.html#MODULO" title="MODULO">
<link href="http://www.gnu.org/software/texinfo/" rel="generator-home" title="Texinfo Homepage">
<!--
Copyright (C) 1999-2013 Free Software Foundation, Inc.
Permission is granted to copy, distribute and/or modify this document
under the terms of the GNU Free Documentation License, Version 1.3 or
any later version published by the Free Software Foundation; with the
Invariant Sections being ``Funding Free Software'', the Front-Cover
Texts being (a) (see below), and with the Back-Cover Texts being (b)
(see below). A copy of the license is included in the section entitled
``GNU Free Documentation License''.
(a) The FSF's Front-Cover Text is:
A GNU Manual
(b) The FSF's Back-Cover Text is:
You have freedom to copy and modify this GNU Manual, like GNU
software. Copies published by the Free Software Foundation raise
funds for GNU development.-->
<meta http-equiv="Content-Style-Type" content="text/css">
<style type="text/css"><!--
pre.display { font-family:inherit }
pre.format { font-family:inherit }
pre.smalldisplay { font-family:inherit; font-size:smaller }
pre.smallformat { font-family:inherit; font-size:smaller }
pre.smallexample { font-size:smaller }
pre.smalllisp { font-size:smaller }
span.sc { font-variant:small-caps }
span.roman { font-family:serif; font-weight:normal; }
span.sansserif { font-family:sans-serif; font-weight:normal; }
--></style>
</head>
<body>
<div class="node">
<a name="MOD"></a>
<p>
Next:&nbsp;<a rel="next" accesskey="n" href="MODULO.html#MODULO">MODULO</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="MINVAL.html#MINVAL">MINVAL</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="Intrinsic-Procedures.html#Intrinsic-Procedures">Intrinsic Procedures</a>
<hr>
</div>
<h3 class="section">8.177 <code>MOD</code> &mdash; Remainder function</h3>
<p><a name="index-MOD-893"></a><a name="index-AMOD-894"></a><a name="index-DMOD-895"></a><a name="index-remainder-896"></a><a name="index-division_002c-remainder-897"></a>
<dl>
<dt><em>Description</em>:<dd><code>MOD(A,P)</code> computes the remainder of the division of A by P.
<br><dt><em>Standard</em>:<dd>Fortran 77 and later
<br><dt><em>Class</em>:<dd>Elemental function
<br><dt><em>Syntax</em>:<dd><code>RESULT = MOD(A, P)</code>
<br><dt><em>Arguments</em>:<dd>
<p><table summary=""><tr align="left"><td valign="top" width="15%"><var>A</var> </td><td valign="top" width="70%">Shall be a scalar of type <code>INTEGER</code> or <code>REAL</code>.
<br></td></tr><tr align="left"><td valign="top" width="15%"><var>P</var> </td><td valign="top" width="70%">Shall be a scalar of the same type and kind as <var>A</var>
and not equal to zero.
<br></td></tr></table>
<br><dt><em>Return value</em>:<dd>The return value is the result of <code>A - (INT(A/P) * P)</code>. 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.
<br><dt><em>Example</em>:<dd>
<pre class="smallexample"> program test_mod
print *, mod(17,3)
print *, mod(17.5,5.5)
print *, mod(17.5d0,5.5)
print *, mod(17.5,5.5d0)
print *, mod(-17,3)
print *, mod(-17.5,5.5)
print *, mod(-17.5d0,5.5)
print *, mod(-17.5,5.5d0)
print *, mod(17,-3)
print *, mod(17.5,-5.5)
print *, mod(17.5d0,-5.5)
print *, mod(17.5,-5.5d0)
end program test_mod
</pre>
<br><dt><em>Specific names</em>:<dd>
<p><table summary=""><tr align="left"><td valign="top" width="20%">Name </td><td valign="top" width="20%">Arguments </td><td valign="top" width="20%">Return type </td><td valign="top" width="25%">Standard
<br></td></tr><tr align="left"><td valign="top" width="20%"><code>MOD(A,P)</code> </td><td valign="top" width="20%"><code>INTEGER A,P</code> </td><td valign="top" width="20%"><code>INTEGER</code> </td><td valign="top" width="25%">Fortran 95 and later
<br></td></tr><tr align="left"><td valign="top" width="20%"><code>AMOD(A,P)</code> </td><td valign="top" width="20%"><code>REAL(4) A,P</code> </td><td valign="top" width="20%"><code>REAL(4)</code> </td><td valign="top" width="25%">Fortran 95 and later
<br></td></tr><tr align="left"><td valign="top" width="20%"><code>DMOD(A,P)</code> </td><td valign="top" width="20%"><code>REAL(8) A,P</code> </td><td valign="top" width="20%"><code>REAL(8)</code> </td><td valign="top" width="25%">Fortran 95 and later
<br></td></tr></table>
<br><dt><em>See also</em>:<dd><a href="MODULO.html#MODULO">MODULO</a>
</dl>
</body></html>