From: Richard Maine on
Ron Shepard <ron-shepard(a)NOSPAM.comcast.net> wrote:

> In article <1jk2u5c.1xwzsq21ou64e8N%nospam(a)see.signature>,
> nospam(a)see.signature (Richard Maine) wrote:
>
> > Even if the code was manually reordered, and
> > parens used to force that ordering, as
> >
> > print *, (a-a)+1
> >
> > that would not change the answer. It is not any reordering that is at
> > issue here; it is whether "a-a" is necessarily 0.
>
> Isn't the issue whether (a-a) is allowed to be eliminated during the
> evaluation of the expression? I would think this would satisfy the
> "mathematically equivalent" requirement in the standard.

I was thinking it didn't satisy that requirement for the "mathematics"
that includes NaNs, but then that whole definition of "mathematically
equivalent" is sort of vague, so perhaps I can't definitively claim that
sfter all. I get the impression that whoever wrote that requirement in
the standard had a narrow understanding of what counted as mathematics;
if it wasn't the stuff they learned in grade school, it wasn't
mathematics. I suspect the reasoning was that everybody "knows" what
those rules are, so one doesn't need to define them.

I learned more that any self-consistent system could count as
mathematics. Some systems are more useful than others, but there is no
unique divinely ordained set of rules that inherently have claim to
being the one and only one true mathematics.

--
Richard Maine | Good judgment comes from experience;
email: last name at domain . net | experience comes from bad judgment.
domain: summertriangle | -- Mark Twain
From: robin on
glen herrmannsfeldt wrote in message ...
>Ron Shepard <ron-shepard(a)nospam.comcast.net> wrote:

>> So I think the issue is whether the expression "(a-a)+1" is
>> mathematically equivalent to the expression "1", and how
>> support of IEEE arithmetic might affect that answer.
>
>One might ask why anyone would write such an expression.


It occurs daily in the case of (a-b) + 1
where the values of A and B are equal.

>In the case of:
>
> if(x.ne.x) ...
>
>It is hard to see why one would write that, other than as
>a potential test for NaN.

It occurs normally as the expression IF (A .NE. B) ...
where the vbalues of A and B are equal.


From: ttw6687 on
I suppose that one (The Committee) could define the "Algebra of
Fortran" so that there would be no ambiguity. I do not know if this
would be a good idea. Then such items as the reordering of a+1-a (sans
parentheses) could be required to be exactly 1 or perhaps even be
dependent on the value of "a" in some cases. Cases like x/x could also
be covered. The "could" rather than "shall" is important. The algebra
of Fortran need not describe the actual arithmetic of any computer,
merely how the compiler should treat expressions. Absent overflow,
underflow, division by zero, production of NaNs, etc., I think the
Fortran Standard does implicitly have such an algebra.

From: steve on
On Jun 15, 12:52 pm, glen herrmannsfeldt <g...(a)ugcs.caltech.edu>
wrote:
> Ron Shepard <ron-shep...(a)nospam.comcast.net> wrote:
>
> (snip, someone wrote)
>
> >>   print *, (a-a)+1
>
> (snip)
>
> > Isn't the issue whether (a-a) is allowed to be eliminated during the
> > evaluation of the expression?  I would think this would satisfy the
> > "mathematically equivalent" requirement in the standard.  
>
> I agree.  And since IEEE is not (yet) a requirement of Fortran...
>
> > Of course
> > IEEE arithmetic with its NAN, INF, -ZERO, and so on complicates
> > these issues, but if IEEE is not supported by some compiler (or if
> > it has been disabled with compiler options), then I would think that
> > (a-a) could in fact be eliminated from the expression (at the
> > symbolic code level) and never explicitly evaluated (to 0.0 or NAN
> > or any other possible value).
>
> One may want this optimization, and yet be able to do other
> IEEE tests.  For example, as in a previous post, one might want
> the ability to set and test for NaN, but still want the
> optimizer to optimize expressions.
>
> > So I think the issue is whether the expression "(a-a)+1" is
> > mathematically equivalent to the expression "1", and how
> > support of IEEE arithmetic might affect that answer.
>
> One might ask why anyone would write such an expression.
>

See any text that discussions the difference between a
quiet NaN and a signaling NaN for an answer.

--
steve
From: robert.corbett on
On Jun 14, 12:40 pm, Thomas Koenig <tkoe...(a)netcologne.de> wrote:
> Hello world,
>
> assume a is a REAL and contains a NaN.
>
> What could
>
> print *, a + 1 - a
>
> output?  NaN would (obviously) be OK, but would 1 also permitted?
>
> What if all intrinsic IEEE modules are used?

If none of the IEEE_* modules are USEd, the expression may be
simplified to the constant 1.0. If all of the IEEE_* modules
are used, the expression still may be simplified to the
constant 1.0. See Fortran standard interpretation F03/00078.

Bob Corbett