GDB/libiberty support for IBM long double

Luis Machado
Fri Dec 28 01:20:00 GMT 2007

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

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

More information about the Gdb-patches mailing list