Port-vax archive

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

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?
/*
  cc -Wall -g -o strtod_test strtod_test.c && ./strtod_test 
  results:
    NetBSD 6 BETA2 amd64: A-E Valid,  F Not Valid
    NetBSD 6 BETA2 vax:   A Valid,  B-D Not Valid,  E SIGFPU
*/

#include <stdlib.h>
#include <stdio.h>
#include <errno.h>

int main()
{
    const char *list[] = {
/* A */ "123456789012345678901234567890123456789",
/* B */ "1234567890123456789012345678901234567890",
/* C */ "1234567890123456789012345678901234567890123456789012345",
/* D */ "12345678901234567890123456789012345678901234567890123456",
        "12345678901234567890123456789012345678901234567890"
        "12345678901234567890123456789012345678901234567890"
        "12345678901234567890123456789012345678901234567890"
        "12345678901234567890123456789012345678901234567890"
        "12345678901234567890123456789012345678901234567890"
        "12345678901234567890123456789012345678901234567890"
        "123456789",
/* E */ "12345678901234567890123456789012345678901234567890"
        "12345678901234567890123456789012345678901234567890"
        "12345678901234567890123456789012345678901234567890"
        "12345678901234567890123456789012345678901234567890"
        "12345678901234567890123456789012345678901234567890"
        "12345678901234567890123456789012345678901234567890"
        "1234567890",
        ""
    };
    const char **s;
    char *ep;
    double d;

    for ( s = list; **s ; ++s) {
        errno = 0;
        printf("%s: ", *s);
        d = strtod(*s, &ep);
        if (ep == *s || errno == ERANGE)
            puts("Not a valid number");
        else
            puts("Valid number");
    }
    return 0;
}



Home | Main Index | Thread Index | Old Index