[unix-pc.bugs] Math error in Perl PL41

clewis@ecicrl.UUCP (Chris Lewis) (12/06/90)

In article <978@ecicrl.UUCP> clewis@ecicrl.UUCP (Chris Lewis) writes:
>Complement of 0 doesn't work as expected (Perl 3, PL41, AT&T 3b1, 3.5.1.4).

>    $foo = 0;
>    printf "%o, %x, %o\n", 0666, ~$foo, 0666 & ~$foo;

>prints:

>    666, 80000000, 0

Sigh.  Problem found.  3b1 C compiler has a bug in it regarding
complement and unsigned long.  Vis, the following code:

main() {
    double f;
    long l;
    l = (unsigned long) 0.0;
    f = (double) ~l;
    printf("%x %f\n", l, f);
    /* similar to eval.c code expression under O_COMPLEMENT */
    f = (double) ~(unsigned long) 0.0;
    printf("%f %x\n", f, (unsigned long) f);
}

Which produces:

    0 -1.000000
    4294967295.000000 80000000

H'm, the first line is correct, and the second is not.  I've checked
this also with unary negate, but this doesn't happen.  (yeah, I know
this doesn't pass lint... but on a 68010 that wouldn't cause a problem)

Even more interesting, when I turn the "long l" into "unsigned long l",
it buggers up again.

I'm going to get around this by introducing a signed long variable
ala l.  (I don't want to fool around with the U_L() stuff).

Other 3b1 owners may want to check their compilers if they
aren't 3.5.1.4, and 3b1 "support" (if such still exists) may want to
take note of this bug.  3b1 gcc appears to not have this problem.
-- 
Chris Lewis, Phone: (613) 832-0541
UUCP: uunet!utai!lsuc!ecicrl!clewis
Moderator of the Ferret Mailing List (ferret-request@eci386)
Psroff mailing list (psroff-request@eci386)