bug-gawk
[Top][All Lists]
Advanced

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

Re: [bug-gawk] NUMCUR and NUMBER flag usage


From: Andrew J. Schorr
Subject: Re: [bug-gawk] NUMCUR and NUMBER flag usage
Date: Sat, 18 Apr 2015 17:22:31 -0400
User-agent: Mutt/1.5.23 (2014-03-12)

On Fri, Apr 17, 2015 at 03:24:35PM -0400, Andrew J. Schorr wrote:
> diff --git a/node.c b/node.c
> index 1741a13..cede9be 100644
> --- a/node.c
> +++ b/node.c
> @@ -139,11 +139,10 @@ r_force_number(NODE *n)
>       *cpend = save;
>  finish:
>       if (errno == 0) {
> -             if (ptr == cpend) {
> +             n->flags |= NUMCUR;
> +             if (ptr == cpend)
> +                     /* a purely numeric value with no trailing junk */
>                       n->flags |= newflags;
> -                     n->flags |= NUMCUR;
> -             }
> -             /* else keep the leading numeric value without updating flags */
>       } else {
>               errno = 0;
>               /*

On 2nd thought, I'm still confused about the meaning of NUMCUR.  The header
file says;

#               define  NUMCUR  0x0008       /* numeric value is current */

If that is true, then why would we ever return from r_force_number
without setting NUMCUR?  Even if the NODE has a string value of "banana",
shouldn't we set n->numbr to 0 and set the NUMCUR flag?  Otherwise,
it will do the conversion every time it tries to access this NODE
as a numeric value.

On the other hand, if we don't want to set NUMCUR when it is a purely 
string value, then my patch should say:

        if (ptr > cp) {
                n->flags |= NUMCUR
                if (ptr == cpend)
                        n->flags |= newflags;
        }

But what's the reason for not setting NUMCUR?  I'm really confused
about the way these flag values are handled.  Here's an example that
surprises me:

bash-4.2$ echo 3 | /bin/gawk --lint '{x = $0; print exp(x)}'
gawk: cmd. line:1: (FILENAME=- FNR=1) warning: exp: received non-numeric 
argument
20.0855

Why is that happening?  Compare to:

bash-4.2$ echo 3 | /bin/gawk --lint '{x = $0+0; print exp(x)}'
20.0855

bash-4.2$ echo 3 apple | /bin/gawk --lint '{x = $0+0; print exp(x)}'
20.0855

It strikes me that this may all be a bit of a mess...

Regards,
Andy



reply via email to

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