David Brownlee | 29 May 2012 21:42
Gravatar

VAX FP: awk: floating point exception: Floating point overflow

Today's slice of VAX fun comes courtesy of this little fragment

echo 12345678911234567892123456789312345678941234567895123456 \
| awk '{split($0,a);print a[1]}'

On most machines this outputs:
12345678911234567892123456789312345678941234567895123456

On the VAX: "awk: floating point exception: Floating point overflow"

This is generated by awk's lib.c "is_number()" calling strtod()

        errno = 0;
        r = strtod(s, &ep);
        if (ep == s || errno == ERANGE)
                return 0;

which traps in strtod.c:526  "dval(&rv) *= bigtens[j];" when the
string passed is too big to represent as a double.

The attached strtod_test.c demonstrates this for anyone who cares :)

strtod() has some ifdef VAX "vax_ovfl_check" but obviously its not
catching this case.

So, is this an issue with the default SIGFPE generation logic, or
should strtod() be handing this case and avoiding the potential
overflow?
Attachment (strtod_test.c): text/x-csrc, 1510 bytes
(Continue reading)

Martin Husemann | 29 May 2012 21:47
Picon

Re: VAX FP: awk: floating point exception: Floating point overflow

On Tue, May 29, 2012 at 08:42:29PM +0100, David Brownlee wrote:
> So, is this an issue with the default SIGFPE generation logic, or
> should strtod() be handing this case and avoiding the potential
> overflow?

strtod should handle this and avoid the overflow.

Martin

Tom Ivar Helbekkmo | 29 May 2012 22:06
Picon
Gravatar

Re: VAX FP: awk: floating point exception: Floating point overflow

David Brownlee <abs <at> absd.org> writes:

> Today's slice of VAX fun comes courtesy of this little fragment
>
> echo 12345678911234567892123456789312345678941234567895123456 \
> | awk '{split($0,a);print a[1]}'

I don't have a VAX with NetBSD handy at the moment, but from memory,
this should be fun, too:

echo 'nanotubes' | awk '{print $1}'

-tih
--

-- 
"The market" is a bunch of 28-year-olds who don't know anything. --Paul Krugman

Jan-Benedict Glaw | 29 May 2012 22:11
Picon
Favicon

Re: VAX FP: awk: floating point exception: Floating point overflow

On Tue, 2012-05-29 22:06:01 +0200, Tom Ivar Helbekkmo <tih <at> hamartun.priv.no> wrote:
> David Brownlee <abs <at> absd.org> writes:
> 
> > Today's slice of VAX fun comes courtesy of this little fragment
> >
> > echo 12345678911234567892123456789312345678941234567895123456 \
> > | awk '{split($0,a);print a[1]}'
> 
> I don't have a VAX with NetBSD handy at the moment, but from memory,
> this should be fun, too:
> 
> echo 'nanotubes' | awk '{print $1}'
        ~~~

Sure: NaN-handling is a bit different :)

MfG, JBG

--

-- 
      Jan-Benedict Glaw      jbglaw <at> lug-owl.de              +49-172-7608481
Signature of: "Debugging is twice as hard as writing the code in the first place.
the second  :  Therefore, if you write the code as cleverly as possible, you are,
               by definition, not smart enough to debug it." - Brian W. Kernighan
David Brownlee | 29 May 2012 23:23
Gravatar

Re: VAX FP: awk: floating point exception: Floating point overflow

On 29 May 2012 21:11, Jan-Benedict Glaw <jbglaw <at> lug-owl.de> wrote:
> On Tue, 2012-05-29 22:06:01 +0200, Tom Ivar Helbekkmo <tih <at> hamartun.priv.no> wrote:
>> David Brownlee <abs <at> absd.org> writes:
>>
>> > Today's slice of VAX fun comes courtesy of this little fragment
>> >
>> > echo 12345678911234567892123456789312345678941234567895123456 \
>> > | awk '{split($0,a);print a[1]}'
>>
>> I don't have a VAX with NetBSD handy at the moment, but from memory,
>> this should be fun, too:
>>
>> echo 'nanotubes' | awk '{print $1}'
>        ~~~
>
> Sure: NaN-handling is a bit different :)

Looks like that one's been fixed :)

wopr# uname -srm ; awk -version ; echo 'nanotubes' | awk '{print $1}'
NetBSD 6.99.7 vax
awk version 20100523
nanotubes

David Brownlee | 31 May 2012 20:09
Gravatar

Re: VAX FP: awk: floating point exception: Floating point overflow

So, do we have a VAX FP guru in the audience? :)

For entertainment value I've put together a sample program which
includes the necessary files to build NetBSD's strtod.c, to make it
easy to debug without a full NetBSD source tree.

http://ftp.netbsd.org/pub/NetBSD/misc/abs/vax-sigfpe_test/

All it needs is a NetBSD/vax environment, real or virtual & someone
who wants to play...

(I'm more than happy to provide an ssh login to a 4000/90, just in case :)

David


Gmane