bug-gawk
[Top][All Lists]
Advanced

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

Re: [bug-gawk] Overflow to Infinity


From: Andrew J. Schorr
Subject: Re: [bug-gawk] Overflow to Infinity
Date: Fri, 22 Jun 2018 11:55:23 -0400
User-agent: Mutt/1.5.21 (2010-09-15)

Hi,

On Fri, Jun 22, 2018 at 03:15:16AM -0600, address@hidden wrote:
> > So gawk sets the numeric value to zero and decides that the input is
> > actually a string, not a number.
> 
> Yes.
> 
> > I'm not sure about the language lawyering on this topic. Perhaps one could
> > argue that an exception should be made for ERANGE.
> 
> This thread had brought up two issues. Input is not getting converted
> "correctly", and gawk can output "inf" and/or "nan" since it relies on
> the output of the C library printf in such cases.

I don't follow. As I understand it, the two issues both relate to input, not
output:

1. Huge numeric values that cause strtod to overflow to inf or -inf were
returning ERANGE, and gawk was treating this as an error and forcing the
value to zero. 

2. String values of "inf" and "infinity" are converted to zero when
not running with --posix, in contrast to +inf, -inf, +infinity, and -infinity,
which are converted to inf or -inf as expected.

> > diff --git a/node.c b/node.c
> > index fcd2bf3..b879e64 100644
> > --- a/node.c
> > +++ b/node.c
> > @@ -140,7 +140,7 @@ r_force_number(NODE *n)
> >             *cpend = save;
> >     }
> >  
> > -   if (errno == 0) {
> > +   if (errno == 0 || errno == ERANGE){
> 
> You need a space between the close paren and the open brace.
> 
> > Note: I'm not sure whether this patch is ideal, since it neglects to
> > reset errno to zero, as happens in the "else" clause. I don't know whether
> > that errno reset is actually needed...
> 
> Reseting errno won't hurt and should probably be done.

I modified this to set errno = 0 in that case. Or do you prefer to have
separate logic for 'errno == 0' and 'errno == ERANGE'? It now needlessly
sets errno to 0 in the 'errno == 0' case, but that seemed less horrible
than duplicating the other logic.

> Andy, please update your patch and go ahead and push it to gawk-4.2-stable.
> Let's use Daniel's code as a new test case also, once you've added in
> your patch.  Can you handle that for me?

I pushed it just now.

> I want to think some more about handling output.

One of us is confued. I think this is an input issue, not an output issue. It's
a question of how to convert "inf" and "infinity" in input -- are they strings
which have a numeric value of 0, or are they IEEE infinity values? 

Regards,
Andy



reply via email to

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