On writing negative zero - with or without sign
  Home FAQ Contact Sign in
comp.lang.fortran only
 
Advanced search
POPULAR GROUPS

more...

comp.lang.fortran Profile…
 Up
On writing negative zero - with or without sign         


Author: Jerry DeLisle
Date: Jul 8, 2007 13:14

Fortran 77 explicitly forbids output of a negative sign for a zero value.

Fortran 90/95 are intended to be compatible with F77 except where noted. The
f90/95 standards omit the statement about not outputting the negative sign for a
zero value.

I preparing a patch to gfortran to print the sign for zero values if the signbit
is set.

My question is: Should gfortran default behavior omit the negative sign and
only show it with a special compiler flag or should the default behavior be to
show the negative sign.?

Example code:
Show full article (0.90Kb)
118 Comments
Re: On writing negative zero - with or without sign         


Author: James Giles
Date: Jul 8, 2007 13:47

Just my opinion, but I'd recommend that you print the minus sign.
I don't even see a need to have an option to turn it off. It's not
like any old programs could be dependent on the behavior. And
*new* programs might very well depend on getting the sign right.

I the very old days (even before ANSI, the organization was
ASA - the American Standards Association), there was a minor
standard that specified the presentation of printed technical
information (I've got a copy somewhere). For whatever reason,
they decided that if all the displayed digits were zero a negative
sign should not be permitted - even if the value in question was
*not* zero, but the value merely underflowed the decimal
field in which the data was printed. Well, the first Fortran
standard chose that same rule in order to be consistent with
that other standard. It was always a bad idea.

The IEEE floating point standard recommends the opposite.
The display of a value, even if it does compare equal to zero,
should preserve the sign. An F2003 implementation consistent
with IEEE float must do that. So, if you plan to support that
part of F2003, you should keep the sign of zero.
Show full article (1.43Kb)
no comments
Re: On writing negative zero - with or without sign         


Author: glen herrmannsfeldt
Date: Jul 8, 2007 14:11

Jerry DeLisle wrote:
> Fortran 77 explicitly forbids output of a negative sign for a zero value.
> Fortran 90/95 are intended to be compatible with F77 except where
> noted. The f90/95 standards omit the statement about not outputting the
> negative sign for a zero value.

One Fortran system that I used in the Fortran 66 days printed a '+'
sign on a negative zero, and only on a negative zero. I don't
remember now why I found that out, but it was pretty surprising
at the time.

That would seem to satisfy even standard that prohibit a '-' sign.

-- glen
no comments
Re: On writing negative zero - with or without sign         


Author: Janne Blomqvist
Date: Jul 9, 2007 00:41

James Giles wrote:
> Just my opinion, but I'd recommend that you print the minus sign.
> I don't even see a need to have an option to turn it off. It's not
> like any old programs could be dependent on the behavior.

The NIST testsuite is, apparently. To which extent that is
representative of real F77 applications, I don't know.

--
Janne Blomqvist
no comments
Re: On writing negative zero - with or without sign         


Author: James Giles
Date: Jul 9, 2007 01:49

Janne Blomqvist wrote:
> James Giles wrote:
>> Just my opinion, but I'd recommend that you print the minus sign.
>> I don't even see a need to have an option to turn it off. It's not
>> like any old programs could be dependent on the behavior.
>
> The NIST testsuite is, apparently. To which extent that is
> representative of real F77 applications, I don't know.

Well, given that it's a test suite, it's dependency is probably
that it was deliberately written to test whether zero has a
negative sign printed with it. My guess is that it has no
further meaning than that.

The standard has already changed once. It used to be required
that an output of entirely zero digits must not have a minus sign.
And now (as of F95 I think) if the internal value is negative (other
than negative zero) the output field must have a minus sign - even
if the only digits actually output are zeros. Headway occurs slowly.
I can't find it quickly, but I think F2003 requires the minus sign if
the implementation is IEEE and the internal value is a negative zero.
Show full article (1.51Kb)
no comments
Re: On writing negative zero - with or without sign         


Author: Jerry DeLisle
Date: Jul 12, 2007 23:26

James Giles wrote:
> Janne Blomqvist wrote:
>> James Giles wrote:
>>> Just my opinion, but I'd recommend that you print the minus sign.
>>> I don't even see a need to have an option to turn it off. It's not
>>> like any old programs could be dependent on the behavior.
>> The NIST testsuite is, apparently. To which extent that is
>> representative of real F77 applications, I don't know.
>
>
> Well, given that it's a test suite, it's dependency is probably
> that it was deliberately written to test whether zero has a
> negative sign printed with it. My guess is that it has no
> further meaning than that.
>
> The standard has already changed once. It used to be required
> that an output of entirely zero digits must not have a minus sign.
> And now (as of F95 I think) if the internal value is negative (other
> than negative zero) the output field must have a minus sign - even
> if the only digits actually output are zeros. Headway occurs slowly. ...
Show full article (1.41Kb)
no comments
Re: On writing negative zero - with or without sign         


Date: Jul 15, 2007 19:15

On Jul 8, 1:14 pm, Jerry DeLisle verizon.net> wrote:
> Fortran 77 explicitly forbids output of a negative sign for a
> zero value.
>
> Fortran 90/95 are intended to be compatible with F77 except
> where noted. The f90/95 standards omit the statement about not
> outputting the negative sign for a zero value.

The statement to which I believe you are referring appeared in
FORTRAN 77, was retained in Fortran 90, and was dropped in
Fortran 95. That statement was not present in the FORTRAN 66
standard, but the FORTRAN committee interpreted the language of
that standard as forbidding prefixing the external representation
of a zero value with a minus sign. See interpretation #52 in
"Clarification of FORTRAN Standards - Second Report" by
C. Kerpelman, CACM 14, 10 (October 1971).
Show full article (4.63Kb)
no comments
Re: On writing negative zero - with or without sign         


Author: glen herrmannsfeldt
Date: Jul 15, 2007 20:47

robert.corbett@sun.com wrote:

(snip regarding printing of negative zero)
> Section 10.6.1 states
> (3) On output with I, F, E, EN, ES, D, and G editing,
> the representation of a positive or zero internal
> value in the field may be prefixed with a plus sign,
> as controlled by the S, SP, and SS edit descriptors
> or the processor. The representation of a negative
> internal value in the field shall be prefixed with
> a minus sign.
> That statement establishes that zero and positive values are
> treated the same for formatted output.
> How do members of J3 justify treating zero values as negative
> values, given the statements quoted above? One member of the
> committee has claimed that positive and negative zeros are not
> zero values, that they are positive values or negative values.
> That interpretation makes the statement cited from Section 4.4.2
> irrelevant.
Show full article (2.18Kb)
no comments
Re: On writing negative zero - with or without sign         


Author: nospam
Date: Jul 15, 2007 20:15

> Because the members of the committee
> do not want to rewrite the standard to say what they think it
> should mean, they choose to apply a remarkably contorted
> interpretations to the standard as written.

I disagree with the characterization of both the motives and the alleged
contortion.
> In any case, Section 4.4.2 of the Fortran 2003 states
...
> That statement establishes that there is a zero value and that
> processors may distinguish between positive and negative zeros.

Yes.
Show full article (6.08Kb)
no comments
Re: On writing negative zero - with or without sign         


Author: nospam
Date: Jul 15, 2007 20:28

glen herrmannsfeldt ugcs.caltech.edu> wrote:
> In a description regarding the ethernet standard, Rich Seifert
> (who is on the ethernet standards committee) indicates in one
> of his books that only "shall" statements actually mean anything,
> and that "may" is a synonym for "may not".

ISO, which is the organization responsible for the standards in
question, has a document that explicitly covers such terms. ISO
Directive 3, if I recall correctly, though I don't feel like dragging it
out to check.

It is quite specific about the use of such terms. "May" indicates
permission. That does have definite meaning in a standard; that's why
ISO lists it. I think that "may not" indicates prohibition, though I'd
have to drag out my copy to be sure.

The possible confusions there are why I prefer "might" instead of "may"
to indicate what could be more elaborately stated as "might or might
not".
Show full article (1.10Kb)
no comments

RELATED THREADS
SubjectArticles qty Group
Re: negative zero value for meancomp.softsys.sas ·
Re: No smoking signs - why not no stabbing signs too?uk.legal ·
1 2 3 4 5 6 7 8 9