bug-gnu-utils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Is this abug or feature?


From: Aharon Robbins
Subject: Re: Is this abug or feature?
Date: Thu, 3 May 2001 10:06:08 +0300

Hi Terry.

Thanks for your note.

The answer is "it's a feature."  All numbers in awk are double precision
floating point.  When using an octal or hexadecimal output format, if
the number is too big to fit into an unsigned long, gawk switches to %g
format so that the output at least makes sense as a number.  Most other
awks fall over and print weird results, as they tend to do something like

        printf("%20x", (unsigned long) val);

which isn't right if the value is out of range.

This is documented in the gawk manual, or at least in the one that's
about to be released with 3.1, although I'm pretty sure it's in the
current doc too.

Hope this helps.

Arnold

> From: "Haebich, Terry L" <address@hidden>
> To: "'address@hidden'" <address@hidden>
> Subject: Is this abug or feature?
> Date: Thu, 3 May 2001 13:52:20 +1000 
>
> I'm trying to convert decimal to hex using gawk but seemed to have reached a
> size limit
>
> cat dec2hex
> #!/bin/sh
> nice /usr/local/bin/gawk -v x=$1 '
>   BEGIN { printf("x = %20d decimal, %20x hex, %20o octal.\n",x,x,x); exit}
> '
>
>  ./dec2hex 4294967295
> x =           4294967295 decimal,             ffffffff hex,
> 37777777777 octal.
>
> ./dec2hex 4294967296
> x =          4.29497e+09 decimal,          4.29497e+09 hex,
> 4.29497e+09 octal.
>
>  gawk -W version
> GNU Awk 3.0.5
> Copyright (C) 1989, 1991-2000 Free Software Foundation.
>
> Am I doing something wrong or is this a problem? 
>
> I would like to be able to convert decimal numbers up to 20 digits long
>
> I have done a lot of searching on the web and cannot find an answer to this
>
> Thanks,
>             Terry



reply via email to

[Prev in Thread] Current Thread [Next in Thread]