I cannot manage to make GDB print correctly some C-style hexadecimal floating-point numbers, see:
GNU gdb (Ubuntu 7.7.1-0ubuntu5~14.04.2) 7.7.1
Copyright (C) 2014 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word".
(gdb) p 0xa.0p-4
$1 = 6
Here $1
should be 0.625
but my GDB seems to see 0xa.0p
as decimal 10
and does a subsequent addition with -4
.
What is wrong with what I ask GDB to print?
I could not find any relevant documentation on how GDB handles hexadecimal floats.
What is wrong with what I ask GDB to print?
Apparently it's a bug with gdb.
Hexadecimal floating point constants with a negative exponent give a wrong result with gdb.
I tried with the latest source release gdb 7.9 (Feb 20, 2015) on Linux and hexadecimal floating point constants with a positive exponent are supported:
(gdb) p/f 0x00.1p0
$1 = 0.0625
(gdb) p/f 0x00.1p1
$2 = 0.125
but if the exponent is negative, then the result is wrong:
(gdb) p/f 0x00.1p-1
$3 = -0.9375
The right and expected result is 0.031250
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With