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.
(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.
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."
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
Fixed on trunk.