[Bug libfortran/117820] Formatted output gives wrong result.

jvdelisle at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Fri Nov 29 21:17:49 GMT 2024


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=117820

--- Comment #5 from Jerry DeLisle <jvdelisle at gcc dot gnu.org> ---
Back to the Standard

>From the standard, the relevent text is: 13.7.2.4 B, O, and Z editing
 ---
The value of m shall not exceed the value of w, except when w is zero. If m is
zero and the internal value consists of all zero bits, the output field
consists of only blank characters. When m and w are both zero, and the internal
value consists of all zero bits, one blank character is produced.
 ---

As see with this example:

program test
  integer(8) :: x
  x = -huge(x) - 1_8

  print '("-huge -1   = <",B64.64,">")', x
  print '("    zero   = <",B64.64,">")', 0_8
  print *,"-------"
  print '("-huge -1   = <",B64.0,">")', x
  print '("    zero   = <",B64.0,">")', 0_8
  print *,"-------"
  print '("-huge -1   = <",B0.0,">")', x
  print '("    zero   = <",B0.0,">")', 0_8
end program

We interpret the "internal value" to not include the sign bit.

$ ./a.out 
-huge -1   = <1000000000000000000000000000000000000000000000000000000000000000>
    zero   = <0000000000000000000000000000000000000000000000000000000000000000>
 -------
-huge -1   = <                                                                >
    zero   = <                                                                >
 -------
-huge -1   = < >
    zero   = < >

I have not found anything in the standard to interpret this otherwise.


More information about the Gcc-bugs mailing list