[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [bug-gawk] gawk erroneous comparison with large negative exponents
From: |
Andrew J. Schorr |
Subject: |
Re: [bug-gawk] gawk erroneous comparison with large negative exponents |
Date: |
Thu, 16 Apr 2015 12:54:29 -0400 |
User-agent: |
Mutt/1.5.23 (2014-03-12) |
Hi,
On Thu, Apr 16, 2015 at 01:23:30PM +0300, Aharon Robbins wrote:
> It looks good to me. Please pull & merge and then push to gawk-4.1-stable
> and from thence merge to master.
Done.
> > But I must confess that I'm a bit confused about the flag usage.
> > The problem with the previous patch was that values where the leading
> > part is numeric should ignore trailing alpha junk. So "3D" should be
> > converted to a numeric value of 3. When that conversion occurs, why do
> > we not set the NUMCUR flag?
>
> We do. I don't understand your question.
When (ptr != cpend), i.e. there is trailing unconverted junk, the flags
are not updated. So NUMCUR is not set. As a result, it will be converted
each time a numeric value is needed.
>
> > Also, the comment next to the NUMBER flag sets "assigned as number",
> > so we does r_force_number enable this flag?
>
> It doesn't, not anywhere that I can use. It uses NUMCUR everywhere.
It may set the NUMBER flag in a couple of places:
} else if (n->stlen == 4 && is_ieee_magic_val(n->stptr)) {
if ((n->flags & MAYBE_NUM) != 0)
n->flags &= ~MAYBE_NUM;
n->flags |= NUMBER|NUMCUR;
n->numbr = get_ieee_magic_val(n->stptr);
...
if ((n->flags & MAYBE_NUM) != 0) {
newflags = NUMBER;
n->flags &= ~MAYBE_NUM;
> > It seems to me that r_force_number
> > can be called when it was not actually assigned as a number. I'm
> > interpreting "assigned as number" to mean something like
> > x = 3
> > Is that not what it means?
>
> Yes, but r_force_number uses NUMCUR, not NUMBER.
It sets NUMBER in some cases, but mostly when MAYBE_NUM was set.
That might be the right thing to do. I haven't dug into it.
> Can you show a real test case that shows a problem? In particular where
> gawk is different from BWK awk and/or mawk?
>
> $ git branch
> ....
> * gawk-4.1-stable
> ...
> $ ./gawk 'BEGIN { x = "3 and a half" ; print x + 2 }'
> 5
At the moment, I'm concerned that we don't set NUMCUR in this case.
With the attached debug patch, I see this:
bash-4.2$ ./gawk 'BEGIN { x = "3 and a half" ; print x + 2; print x+3 }'
debug: r_force_number(3 and a half) started with flags 0x7
debug: r_force_number(3 and a half) finished with flags 0x7
5
debug: r_force_number(3 and a half) started with flags 0x7
debug: r_force_number(3 and a half) finished with flags 0x7
6
Contrast to:
bash-4.2$ ./gawk 'BEGIN { x = "23" ; print x + 2; print x+3 }'
debug: r_force_number(23) started with flags 0x7
debug: r_force_number(23) finished with flags 0xf
25
26
Note that my (committed) patch did not change this aspect of the logic.
Regards,
Andy
debug.patch
Description: Text document
- [bug-gawk] gawk erroneous comparison with large negative exponents, Sol Katzman, 2015/04/09
- Re: [bug-gawk] gawk erroneous comparison with large negative exponents, Aharon Robbins, 2015/04/13
- Re: [bug-gawk] gawk erroneous comparison with large negative exponents, Andrew J. Schorr, 2015/04/13
- Re: [bug-gawk] gawk erroneous comparison with large negative exponents, Aharon Robbins, 2015/04/14
- Re: [bug-gawk] gawk erroneous comparison with large negative exponents, Andrew J. Schorr, 2015/04/14
- Re: [bug-gawk] gawk erroneous comparison with large negative exponents, Andrew J. Schorr, 2015/04/14
- Re: [bug-gawk] gawk erroneous comparison with large negative exponents, Aharon Robbins, 2015/04/16
- Re: [bug-gawk] gawk erroneous comparison with large negative exponents,
Andrew J. Schorr <=
- Re: [bug-gawk] gawk erroneous comparison with large negative exponents, Aharon Robbins, 2015/04/16
- Re: [bug-gawk] gawk erroneous comparison with large negative exponents, Andrew J. Schorr, 2015/04/17
- Re: [bug-gawk] gawk erroneous comparison with large negative exponents, Andrew J. Schorr, 2015/04/17
- Re: [bug-gawk] NUMCUR and NUMBER flag usage, Andrew J. Schorr, 2015/04/18