[Bug libfortran/41711] [F2008] BOZ format does not support reading large kind reals
jvdelisle at gcc dot gnu dot org
gcc-bugzilla@gcc.gnu.org
Mon Dec 7 01:35:00 GMT 2009
------- Comment #17 from jvdelisle at gcc dot gnu dot org 2009-12-07 01:35 -------
I found the thread on this:
http://www.rhinocerus.net/forum/lang-fortran/585916-printing-64-bit-binary-number-gfortran-4-1-2-a.html
Richard Maine says:
" from the thread
> program test_acos
>
> implicit none
> real*8 :: x
> integer*8 :: i
> equivalence (i,x)
> i = z'3FE826E143045DBE'
> x = acos(x)
> write(*,1400) x
> 1400 format(B64)
> end program test_acos
....
> Fortran runtime error: Expected INTEGER for item 2 in formatted
> transfer, got REAL
That is correct. The B edit descriptor is only for integers.
> However, when I asked to print a 16-digit HEX by changing line 9 to
> 1400 format(Z16)
> it worked.
That is a nonstandard feature, probably for compatibility with some
existing codes that used a similar extension from before when the Z edit
descriptor was added to the standard. The standard only allows the Z
edit descriptor for integers, just like the B edit descriptor.
> How can I print the value of x at the end in binary?
Use the TRANSFER intrinsic to transfer the bits in x to integer type
before printing. Alternatively, you could use an equivalence. Such use
of equivalence is technically nonstandard, but that's a pretty fine
point of nitpicking; it will work. The TRANSFER solution is fully
standard conforming.
I note as an aside that your line
> i = z'3FE826E143045DBE'
also violates the standard. The standard allows hex constants only in
*VERY* limited contexts. In fact, for f95, it is allowed only in a DATA
statement; f2003 adds a few other places, but not many and not this one.
Although this usage is moderately common extension, the provision of the
standard that it violates is a constraint. This means that the compiler
is required to be able to diagnose the usage. Did you use the compiler's
option to check for violations of the standard. If not, I suggest doing
so. If you did and the compiler still did not complaint, than that would
count as a compiler bug and should be so reported."
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=41711
More information about the Gcc-bugs
mailing list