feature or a bug with long double (quad-precision) in gcc (6.2.1)
Vladimir Lomov
lomov.vl@gmail.com
Sat Dec 3 14:11:00 GMT 2016
Hello,
I faced strange problem with long double (C) in comparison with fortran
(gfortran) on my system:
Archlinux x86_64, gcc 6.2.1 20160830.
I prepared two small programs on C and Fortran (see attached files):
c-double-ldouble.c, gfortran-real-quad.f95.
For comparison I write to the file (in raw format) number 1/3 as double,
long double, real(kind=8) and real(kind=16), correspondingly files
'bin-double.bin', 'bin-ldouble.bin', 'bin-double.dat', bin-ldouble.dat.
Output of hexdump for double and real(kind=8) are identical
$ hexdump bin-double.bin
0000000 5555 5555 5555 3fd5
0000008
$ hexdump bin-double.dat
0000000 5555 5555 5555 3fd5
0000008
and in accordance with
https://en.wikipedia.org/wiki/Double-precision_floating-point_format
(except the order, but I suppose this is expected), but for long double
and real(kind=16) and different
$ hexdump bin-ldouble.bin
0000000 aaab aaaa aaaa aaaa 3ffd 99fb 7ffe 0000
0000010
$ hexdump bin-ldouble.dat
0000000 5555 5555 5555 5555 5555 5555 5555 3ffd
0000010
I suppose that hexdump for fortran case is correct, according to
https://en.wikipedia.org/wiki/Quadruple-precision_floating-point_format
so result of long double is wrong, besides it depends on options passed
to compiler.
Could someone shed a light on situation and that is the correct result?
I used the following lines to compile
$ gcc -Wall -Wextra -pedantic -o FILE FILE.c
$ gfortran -Wall -Wextra -pedantic -o FILE FILE.f95
Adding option -O2 to gcc changed content of raw file.
---
Vladimir Lomov
--
Q: What lies on the bottom of the ocean and twitches?
A: A nervous wreck.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: c-double-ldouble.c
Type: text/x-c
Size: 402 bytes
Desc: not available
URL: <https://gcc.gnu.org/pipermail/gcc-help/attachments/20161203/6a0304aa/attachment.bin>
-------------- next part --------------
program write_bin_data
implicit none
real(kind=8) :: fd, ad, bd
real(kind=16) :: fq, aq, bq
ad = 1.
bd = 3.
fd = ad/bd
open(unit=10,file="bin-double.dat", form="unformatted", access="stream", status="replace")
write(10) fd
close(10)
aq = 1.
bq = 3.
fq = aq/bq
open(unit=10,file="bin-ldouble.dat", form="unformatted", access="stream", status="replace")
write(10) fq
close(10)
end program write_bin_data
More information about the Gcc-help
mailing list