Re: Documentation and output of pretty_print()

new topic     » goto parent     » topic index » view thread      » older message » newer message

On Mon, 13 Sep 2004 08:08:02 +0200, Juergen Luethje <j.lue at gmx.de>
wrote:

>I just realized that both Eu's printf() and pretty_print() also lose the
>'-' sign.
Yup.
>The problem arises with negative numbers. Currently, the '-' sign is
>lost, I think that's a bug.
Maybe it is a bug, maybe it is not. Technically, if the number has a
sign, then the hex just needs to show a set bit where the sign bit is.
One of the reasons I previously went with signed 32-bit numbers only
was to make the hex output unambiguous:

printf(1,"%x %x",{4294967295,-1})


will output "FFFFFFFF FFFFFFFF". That is why the previous version
restricted integers from #80000000 (-2147483648) to #7FFFFFFF
(+2147483647), with the sign implied from the hex, if you see what I
mean. I suppose that technically it now prints 33-bit numbers blink
Anyway, the last version had

elsif cl<0 then
		txt='-'&sprintf(ppp_IntFmt,-cl)


which makes pp({4294967295,-1}) output {#FFFFFFFF,-#1}.
(assuming of course that pp_IntFmt is "%x")

> But when the minus sign wil be included in
>the output, using the suggested format, then there will be output
>strings such as
>}}}
<eucode>
>#-FF
></eucode>
{{{

The code above causes "-#FF" to be printed (for -255).
I can accept someone might expect #FFFFFF01 instead.
I feel another option coming on to enable/disable the two lines of
code for negative integer handling above, and/or limit the integer
range to avoid ambiguity... I will probably wait until someone asks
for it though blink)

<snip>
>fmt = "%x\n"
I trust you don't normally put \n's in pp_IntFmt or pp_FltFmt as they
completely mangle the output. Pretty much the whole point of ppp.e is
to automatically put in \n's in the right places for you!
<snip>
>This raises the error "hex number not formed correctly".
>So what to do now?
If you want machine-readable output, I suggest you avoid hex formats;
%d (the default) will do just as well. What exactly is it that must be
nicely formatted for human consumption and also machine readable?

Regards,
Pete

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu