(j3.2006) is MOD (INT_MIN, -1) legal?
Michael Ingrassia
michaeli
Mon Oct 27 18:12:49 EDT 2008
Interesting question!
>MOD(A,P) is interpreted as A - INT ( A / P) * P
That's not what I read in 13.7.80. There's no explicit or implicit
claim that the MOD intrinsic is "interpreted". Rather, it has a value
which is mathematically given as A-INT (A/P) * P. Sounds fussy, but I
think it matters here.
>This expression applied on MOD(INT_MIN, -1) ... overflows.
The reason it matters is that mathematical expressions might not overflow nearly
so often as computational expressions.
If "v" is a valuation function which takes Fortran expressions and
produces mathematical values (say, leftover from some denotational semantics
paper), then it makes sense that
v(A - INT(A/P)*P) = v(A) - v(INT(A/P)*P)
= v(A) - v(INT(A/P))*v(P)
= v(A) - v(A/P)*v(P) ! 13.7.53 case (i)
and for A equal to INT_MIN and P equal to (-1), the Fortran expression
A/P does overflow on my processor and it might be that mathematically
v(overflow-expression) is some sort of Infinite value. At this point
we need to know the range of the valuation function v. For integers,
we haven't blessed any particular model with an Infinity, so I think we're
stuck concluding that the standard has cunningly failed to specify a
value for MOD in this case.
Some ways out:
1) we only claim to specify models for inputs that can be described in
terms of the Integer model. On the edges, you're on your own.
2) we really didn't mean to make the value depend on whether A/P overflowed.
we should come up with a better definition.
3) we really did mean that MOD can overflow if A/P overflows. We could add
a NOTE that says so.
--Michael I.
More information about the J3
mailing list