[Fortran] PR 34482: RFC and patch: BOZ to real/complex conversion for some systems

Tobias Burnus burnus@net-b.de
Mon Dec 17 08:13:00 GMT 2007


Assume for the following that 4 is the default integer/real kind and 8
the largest integer kind. In DATA
    z'FFFFFFFF'
is has the largest integer kind and is thus identically to
    z'00000000FFFFFFFF'
If one now transfers this to a default-kind real, i.e.
    real(z'FFFFFFFF')
one transfers an 8 to a 4 byte variable. Depending on the system only
the zeros (00000000) or the ones (FFFFFFFF) are transferred.

I think everyone would expect in this case that the ones/FFFFFFFF are
bit-wise transferred, which the attached patch does by converting the
BOZ to the smallest possible kind; for the example this is 4. This fixes
the PR.


However, I am not sure it does the right thing on all systems for:
    real(z'00000000FFFFFFFF',kind=8)
If one converts this to kind 4 ("z'FFFFFFFF'") and transfers it then,
one might get FFFFFFFF00000000 on some sytems instead of
00000000FFFFFFFF. -- Or not?

Jerry, can you check that the patch does the right thing on such
platforms and  real(z'00000000FFFFFFFF',kind=8) ?


The attached patch has been built and regression tested on x86-64-linux.
It has also been tested by Jerry for nan_4.f90 on a PowerPC.

If it does not have the issue I outlined above: OK for the trunk?

If it does, one needs to store the number of bits including significant
prefixing zeros. Or should one use MAX(boz_bit_size, lhs_bit_size)? 
(The result of the two conversions is not the same!)

I think the Fortran standard does not say at all what is supposed to
happen here. (For integer, gfortran simply assigns the integer and the
conversion to integer is done via GMP; thus  z'00000000FFFFFFFF' and
z'FFFFFFFF' are equivalent.)

Tobias
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: nan-fix.diff
URL: <http://gcc.gnu.org/pipermail/fortran/attachments/20071217/97e39a27/attachment.ksh>


More information about the Fortran mailing list