bug-gawk
[Top][All Lists]
Advanced

[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: Tue, 14 Apr 2015 11:21:21 -0400
User-agent: Mutt/1.5.23 (2014-03-12)

On Tue, Apr 14, 2015 at 10:35:27AM -0400, Andrew J. Schorr wrote:
> On Tue, Apr 14, 2015 at 04:00:46PM +0300, Aharon Robbins wrote:
> > > Regarding gawk, this does raise the question of whether 
> > > node.c:r_force_number
> > > should force the numeric value to zero when strtod sets errno.
> > 
> > I think it should.
> > 
> > Andy, do you want to do that in the stable branch and see if anything
> > breaks in the test suite?  If that's OK, please push, merge to master,
> > and push that as well.  I've done enough beating on gawk for one day...
> 
> The attached patch breaks two tests:
...

> diff --git a/node.c b/node.c
> index a5e06cd..113cc38 100644
> --- a/node.c
> +++ b/node.c
> @@ -143,6 +143,12 @@ finish:
>               n->flags |= NUMCUR;
>       } else {
>               errno = 0;
> +             /*
> +              * N.B. For subnormal values, strtod may return the
> +              * floating-point representation while setting errno to ERANGE.
> +              * We force the numeric value to 0 in such cases.
> +              */
> +             n->numbr = 0;
>       }
>  
>       return n;

Oops -- that was not the correct patch.  I think the correct patch
is attached.  If that looks good, I can push it.  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?
Also, the comment next to the NUMBER flag sets "assigned as number",
so we does r_force_number enable this flag?  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?

Also, should we not have a more explicit test that values with trailing
non-numeric stuff accept leading numeric values?  Finding such a problem only
through the array-sorting test seems a bit indirect...

Regards,
Andy

Attachment: subnormal.patch
Description: Text document


reply via email to

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