This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
Re: GDB/libiberty support for IBM long double
- From: Luis Machado <luisgpm at linux dot vnet dot ibm dot com>
- To: gdb-patches at sourceware dot org
- Date: Thu, 27 Dec 2007 17:20:07 -0200
- Subject: Re: GDB/libiberty support for IBM long double
- References: <200711090107.lA917ZGs027733@d12av02.megacenter.de.ibm.com> <Pine.LNX.4.64.0711130038330.29493@digraph.polyomino.org.uk>
- Reply-to: luisgpm at linux dot vnet dot ibm dot com
Hi folks,
There appears to be a problem with the use of IBM long doubles. In
specific situations the values are being shown in a wrong way.
Follows an example of GDB HEAD:
(gdb) ptype ld0
type = long double
(gdb) p sizeof(ld0)
$8 = 16
(gdb) set ld0=1.2
(gdb) p ld0
$9 = 1.39999980921857059001922607421875
(gdb) printf "Long Double 128: %.30Lg \n",ld0
Long Double 128: 1.39999980921857059001922607422
(gdb) printf "Long Double 128: %.30Lg \n",1.2
Long Double 128: 1.19999999999999995559107901499
(gdb) printf "Long Double 128: %.30Lg \n",(long double)1.2
Long Double 128: 1.39999980921857059001922607422
(gdb)
The only correct value is when we don't have a value that is explicitly
a long double, in which case we have 1.19999999999999995559107901499.
I've tracked down the problem and it appears libiberty is doing wrong
calculations when we have a long double. In particular, this piece of
code from "floatformat_to_double:libiberty/floatformat.c:527":
===> code <====
if (exponent != 0)
exponent -= mant_bits;
===> code <====
We really need to be able to decrement EXPONENT (even if it's zero) to
get the right exponent value to call the ldexp(mant, exponent) function
for the next iteration, thus leading to a correct long double value.
Removing this condition fixes the problem, but i'm not sure this is 100%
safe as this condition must have a purpose.
Any ideas?
Best regards,
--
Luis Machado
Software Engineer
IBM Linux Technology Center