(j3.2006) is MOD (INT_MIN, -1) legal?
Mon Oct 27 23:12:14 EDT 2008
Jim Xia wrote:
> j3-bounces at j3-fortran.org wrote on 10/27/2008 04:50:33 PM:
> > >
> > > This discussion originally came from C community on INT_MIN % (-1).
> > > Say you have a minimum integer value, INT_MIN (e.g. -HUGE(1) - 1),
> > > then is it a legal Fortran code to compute MOD(INT_MIN, -1)?
> > Is INT_MIN the same as -huge( 0) ?
> > Is mod() the same as % ?
> > >
> > >
> > > Based on the text in 13.7.80 of F03, MOD(A,P) is interpreted as A -
> > > INT ( A / P) * P. This expression applied on MOD(INT_MIN, -1) will
> > > result in a computation of INT_MIN / (-1), which overflows.
> > Does is overflow as per the standard,
> > or just in some implementations?
> OK, let me try to rephrase the question: in MOD(A,P) the standard says:
> "Result Value. The value of the result is A?INT (A/P) * P."
> The question is: does this mean that any restrictions apply to
> expression "A?INT (A/P) * P" also apply to intrinsic MOD()?
The Fortran 2003 standard is not as restrictive as you seem to think
it is. The mathmatical equivalence rule (22.214.171.124) allows any
numeric expression to be replaced with a mathematically equivalent
expression. A processor is allowed to substitute the expression
A - INT(A/P)*P for MOD(A, P). It could also substitute
(A + HUGE(0)) - INT(A/P)*P - HUGE(0)
When the committee has responded to this class of question before,
it has called them quality-of-implementation (QoI) issues. As such,
they are not covered by the standard.
More information about the J3