J3/00-325
To: J3
From: Malcolm Cohen
Subject: Interpretation request on MOD and MODULO intrinsic functions
Date: 27 November 2000
NUMBER: ?
TITLE: MOD and MODULO intrinsic functions with zero divisor
KEYWORDS: Intrinsic functions, MOD, MODULO
DEFECT TYPE: ?
STATUS: J3 consideration in progress
QUESTION:
Consider the programs:
PROGRAM example1
PRINT *,MODULO(3,0)
PRINT *,'Test succeeded'
END
PROGRAM example2
PRINT *,MOD(3,0)
PRINT *,'Test succeeded'
END
Are these programs standard-conforming, and should "Test succeeded" be
printed in each case?
Discussion:
13.14.74 says of MODULO: "If P=0, the result is processor dependent."
13.14.73 says of MOD: "If P=0, the result is processor dependent."
It appears that example1 and example2 are equally conforming.
Information:
Out of 7 Fortran 90/95 compilers, with
example1: 5 compiled it ok, 3 of these crashed it at runtime
example2: 2 compiled it ok, both of these crashed it at runtime
Out of 1 FORTRAN 77 compiler,
example2 did not compile (error message).
Note that section 7.1.7 [97:6-7] states
"The execution of any numeric operation whose result is not defined by
the arithmetic used by the processor is prohibited."
This would seem to be contradictory, at least in spirit, to the definitions
of MOD and MODULO.
ANSWER:
No, these programs were not intended to be standard-conforming.
The processor should be allowed to optimise assuming that P is not zero.
Edits are supplied to correct this mistake in the standard.
EDIT:
[257:32-33] Replace "If P = ... dependent" with "P shall not be zero".
[258:4] Ditto.
[258:6] Ditto.
SUBMITTED BY: Malcolm Cohen
HISTORY: J3/00-325 m155 Submitted
===END