[comp.lang.fortran] fortran statement

smr@beta.lanl.gov (Shawn) (07/22/89)

Read the statement:

IF(MOD(N,2).EQ.0)THEN

I'm new at the language and was looking over a program written as an
example and became quite confused when I read MOD  what does it signify
in this statement there is no other reference to MOD...
Anyone who might be able to tell me would be appreciated.
thanks.

cdb@hpclcdb.HP.COM (Carl Burch) (07/31/89)

> IF(MOD(N,2).EQ.0)THEN

> I'm new at the language and was looking over a program written as an
> example and became quite confused when I read MOD  what does it signify
> in this statement there is no other reference to MOD...


     Short answer : This is FORTRAN 77 for (in Pascal) :

	  IF odd(N) THEN


     Longer answer :  MOD is the modulus (like remainder if all arguments
     are positive) function.  It is an intrinsic function in FORTRAN 77, so
     no other references are necessary.  The remainder of any even positive
     number divided by two is zero.  I hedge by restricting the above to 
     the positive case because what happens when either argument is negative
     is the subject of many theological arguments I do not desire to join.

						Carl Burch
						HP Data and Languages Division

BLUMBERG@BGUVM.BITNET (Dan Blumberg, Dept. Of Geog. Ben Gurion Univ. Israel) (07/31/89)

mod is the name of a two fimensional matrix sized I by J. MOd (n,2) is the
cell in matrix Mod with the coordinates of n,2(like geographical coordinates).
MOD 1 2 3 4 5
    2
    3
    .
    .
    n X          < mod(n,2) reffers to this cell
                                              good luck
                                                Fight the Fort ran
                                                  Danny

chidsey@smoke.BRL.MIL (Irving Chidsey ) (07/31/89)

In article <588BLUMBERG@BGUVM> BLUMBERG@BGUVM.BITNET (Dan Blumberg, Dept. Of Geog. Ben Gurion Univ. Israel) writes:
<mod is the name of a two fimensional matrix sized I by J. MOd (n,2) is the
<cell in matrix Mod with the coordinates of n,2(like geographical coordinates).
<MOD 1 2 3 4 5
<    2
<    3
<    .
<    .
<    n X          < mod(n,2) reffers to this cell
<                                              good luck
<                                                Fight the Fort ran
<                                                  Danny
Sorry, but mod( n, 2 ) is almost certainly Fortran for N modulo 2, which is
mathematics for n/2 with no fractional part.

I don't thinkit is standard fortran, but it is common fortran.

					Irv


-- 
I do not have signature authority.  I am not authorized to sign anything.
I am not authorized to commit the BRL, the DOA, the DOD, or the US Government
to anything, not even by implication.
			Irving L. Chidsey  <chidsey@brl.mil>

riley@batcomputer.tn.cornell.edu (Daniel S. Riley) (07/31/89)

In article <10632@smoke.BRL.MIL> chidsey@brl.arpa (Irving Chidsey (INF) <chidsey>) writes:
>In article <588BLUMBERG@BGUVM> BLUMBERG@BGUVM.BITNET (Dan Blumberg, Dept. Of Geog. Ben Gurion Univ. Israel) writes:
><mod is the name of a two fimensional matrix sized I by J. MOd (n,2) is the
><cell in matrix Mod with the coordinates of n,2(like geographical coordinates).

>Sorry, but mod( n, 2 ) is almost certainly Fortran for N modulo 2, which is
>mathematics for n/2 with no fractional part.
>
>I don't thinkit is standard fortran, but it is common fortran.

Ok, enough of this.

mod() is the remainder function.  mod(n, 2) returns the remainder when
n is divided by 2--this is the usual way to check for even or odd (or test 
the least significant bit, same thing).  It is a standard FORTRAN-77 
intrinsic.  The definition is something like

mod(n, m) = n - m*int(n/m)

mod() is really misnamed, since it returns the remainder, not the modulo.
(For those who care--the remainder takes the sign of the first argument,
the modulo takes the sign of the second.  mod(x, 2*pi) ought to return a
number between 0 and 2*pi, but in FORTRAN-77 it returns a number between
-2*pi and 2*pi, depending on the sign of x.)

As far as I know, you could declare an array named mod(), but this is
generally considered to be bad (and confusing) programming practice.

-Dan Riley (riley@tcgould.tn.cornell.edu, cornell!batcomputer!riley)
-Wilson Lab, Cornell U.

silvert@cs.dal.ca (Bill Silvert) (07/31/89)

In article <588BLUMBERG@BGUVM> BLUMBERG@BGUVM.BITNET (Dan Blumberg, Dept. Of Geog. Ben Gurion Univ. Israel) writes:
>mod is the name of a two fimensional matrix sized I by J. MOd (n,2) is the
>cell in matrix Mod with the coordinates of n,2(like geographical coordinates).

MOD(I, J) is the remainder when I is divided by J, like I % J in C.
It is defined at the top of p. 15-23 of the standard, and is technically
defined as I - INT(I/J)*J, which unfortunately is not an optimal choice
for negative numbers.

One of the advantages of having a standard is that questions can be
correctly answered on the basis of facat.  Dan, are you listening?

-- 
Bill Silvert, Habitat Ecology Division.
Bedford Institute of Oceanography, Dartmouth, NS, Canada B2Y 4A2
	UUCP: ...!{uunet,watmath}!dalcs!biomel!bill
	Internet: biomel@cs.dal.CA	BITNET: bs%dalcs@dalac.BITNET

johnl@esegue.uucp (John Levine) (07/31/89)

In article <10632@smoke.BRL.MIL> chidsey@brl.arpa (Irving Chidsey (INF) <chidsey>) writes:
>In article <588BLUMBERG@BGUVM> BLUMBERG@BGUVM.BITNET (Dan Blumberg, Dept. Of Geog. Ben Gurion Univ. Israel) writes:
><mod is the name of a two fimensional matrix sized I by J. MOd (n,2) is the...
>Sorry, but mod( n, 2 ) is almost certainly Fortran for N modulo 2, which is
>mathematics for n/2 with no fractional part.
>I don't thinkit is standard fortran, but it is common fortran.

Oh, for heavens' sakes.  MOD is the intrisic integer remainder function and
has been since about 1957 (when it was sometimes called MODF.)  I have never
seen a version of Fortran that doesn't have it, including the original
Fortran I.

If you have a simple question like this, it would be a kindness to the
200,000 people on the net if you spent a few minutes looking it up, rather
than blatting it all over the world.  (Not having a manual is no excuse --
it's certainly quicker to go out and find one than wait for the net to
answer.)

Grouchily,
-- 
John R. Levine, Segue Software, POB 349, Cambridge MA 02238, +1 617 492 3869
{ima|lotus}!esegue!johnl, johnl@ima.isc.com, Levine@YALE.something
Massachusetts has 64 licensed drivers who are over 100 years old.  -The Globe

sdry@vax5.CIT.CORNELL.EDU (07/31/89)

In article <588BLUMBERG@BGUVM> BLUMBERG@BGUVM.BITNET (Dan Blumberg, Dept. Of Geog. Ben Gurion Univ. Israel) writes:
>mod is the name of a two fimensional matrix sized I by J. MOd (n,2) is the
>cell in matrix Mod with the coordinates of n,2(like geographical coordinates).
>MOD 1 2 3 4 5
>    2
>    3
>    .
>    .
>    n X          < mod(n,2) reffers to this cell
>                                              good luck
>                                                Fight the Fort ran
>                                                  Danny

CDIR$ FLAME(MILD)	! Not a new CFT directive (in case you wondered)

This is only true if the program unit contains a DIMENSION or equivalent
declarative statement defining array MOD. Normally, MOD is an intrinsic
function ( MOD(I,J) returns the remainder of the division of I by J; thus,
IF (MOD(N,2).EQ.0) tests whether N is even. The original posting had just
such a statement.)
    As a general rule, an identifier followed by an argument list within
parentheses is interpreted as an external (or intrinsic) function call
unless it has been explicitly declared as an array.

CDIR$ FLAME(OFF)
					Sergio Gelato

jmlake@uicsrd.csrd.uiuc.edu (08/03/89)

MOD is the integer modulus function.  MOD(N, 2).eq.0 is testing to
see whether N is EVEN.


It is not a two-dimensional array, as a previous message indicated.



J. Michael Lake                Center for Supercomputer Research & Development
Graduate Research Assistant    305 Talbot Laboratory    104 South Wright St.
University of Illinois         Urbana  IL  61821        (217) 333-4168
jmlake@uiuc.edu                uxc.cso.uiuc.edu!uicsrd.csrd.uiuc.edu!jmlake