Bug 49188 - Mismatch between -fsign-zero documentation and formatted output
Summary: Mismatch between -fsign-zero documentation and formatted output
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: libfortran (show other bugs)
Version: 4.7.0
: P3 minor
Target Milestone: 4.7.0
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-05-27 10:49 UTC by Thomas Henlich
Modified: 2011-11-07 22:24 UTC (History)
3 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Thomas Henlich 2011-05-27 10:49:58 UTC
The documentation of the -fsign-zero option mentions "floating point numbers of value zero with the sign bit set":

"When enabled, floating point numbers of value zero with the sign bit set are written as negative number in formatted output and treated as negative in the SIGN intrinsic. fno-sign-zero does not print the negative sign of zero values and regards zero as positive number in the SIGN intrinsic for compatibility with F77. Default behavior is to show the negative sign."

However the flag also affects the output of numbers with a value other than zero, which have their non-zero digits truncated due to formatting.

E.g.:
    print "(rc,f4.1)", -0.04
-fsign-zero:
-0.0
-fno-sign-zero:
 0.0

This fno-sign-zero behaviour is not according to the Fortran standard ("a minus sign if the internal value is negative") including F77 which is explicitly mentioned in the documentation. (Or is this referring to a specific, possibly non-Fortran77-compliant compiler named F77?)

The only sense this would make is if this option would be restricted to actually do what it says in the documentation, regarding a zero with the sign bit set as a mathematical zero, a non-negative value.

In my opinion the formatting routines for real numbers should be changed to only affect zero values.

Additionally, the last sentence ("Default behavior is to show the negative sign.") should be made more precise (e.g. "The option is enabled by default") to reflect that the SIGN intrinsic is also affected by the default setting.
Comment 1 Tobias Burnus 2011-05-27 12:31:21 UTC
(In reply to comment #0)
> This fno-sign-zero behaviour is not according to the Fortran standard

Well, -fno-sign-zero is definitely not according to the Fortran 90+ standard as one there has signed zero. Fortran 77 does not really say anything about signed zeros, thus, some programs assume that there is only one zero, which is positive. However, I think according to the Fortran 77 standard, a negative zero is also a valid implementation choice.

> ("a minus sign if the internal value is negative") including F77 which is
> explicitly mentioned in the documentation.

For cross-reference the quote is from "13.5.9.2.1  F_Editing" at
  ftp://ftp.nag.co.uk/sc22wg5/ARCHIVE/Fortran77.html


I think the current behavior is OK. For programs, which do not handle negative zeros, one should never print a minus - independent whether the internal value is exactly zero or only after truncation. If I run your program (w/o "rc,") with g77, I get:
 0.0
Ditto with ifort (w/ and w/o "rc,", unless "-assume minus0"), pathf95 and pgf90.

There are really programs - Fortran programs or post-processing programs, which rely on not printing "-0.0" and on the non-conforming SIGN behavior (with regards to negative zeros). Thus, it does not really matter whether -fno-sign-zero breaks the Fortran standard or not, if programs rely on it and if gfortran conforms to the standard by default.
Comment 2 Thomas Henlich 2011-05-27 18:41:38 UTC
In this case a more precise documentation should be something like:

"When enabled, floating point numbers with the sign bit set are always written with a negative sign even if the formatted output contains no other digits than zero. In addition, floating point numbers of value zero with the sign bit set are treated as negative in the SIGN intrinsic. fno-sign-zero does not print the negative sign of such values and regards zero as positive number in the SIGN intrinsic for compatibility with g77. fsign-zero is the default."
Comment 3 Francois-Xavier Coudert 2011-11-07 22:22:02 UTC
Author: fxcoudert
Date: Mon Nov  7 22:21:54 2011
New Revision: 181127

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=181127
Log:
	PR libfortran/49188
	PR libfortran/49336
	* invoke.texi: Fix documentation of fsign-zero option. Remove
	contractions.
	* intrinsic.texi: Fix ATAN2 documentation for signed zeros.
	Remove contractions.
	* gfortran.texi: Remove contractions.

Modified:
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/gfortran.texi
    trunk/gcc/fortran/intrinsic.texi
    trunk/gcc/fortran/invoke.texi
Comment 4 Francois-Xavier Coudert 2011-11-07 22:24:38 UTC
Fixed on trunk.