Re: [PATCH 6/9] fix printing of DWARF fixed-point type objects with format modifier

Simon Marchi
2020-11-10T22:50:55Z

On 2020-11-08 1:30 a.m., Joel Brobecker wrote:
> Consider a fixed-point type such the scaling factor is 1/16,
> as the following Ada code snippet would create:
>
> type FP1_Type is delta 0.1 range -1.0 .. +1.0;
> FP1_Var : FP1_Type := 0.25;
>
> Printing the value of this variable with a format modifier yields
> the wrong value. E.g.:
>
> (gdb) p /x fp1_var
> $6 = 0x4
>
> Since the real value is 0.25, we therefore expected...
>
> (gdb) p /x fp1_var
> $6 = 0x0

I find this behavior a bit strange and I wonder when this is useful.
Intuitively, I would think that /x would give me the underlying
representation, in hex, I think it is more likely to be useful.

But I see that this is how floating points work:

(gdb) ptype f
type = float
(gdb) p f
$1 = 1.23000002
(gdb) p/x f
$2 = 0x1

... so it makes sense to have the same behavior for fixed points.

Simon