Xref: utzoo comp.lang.perl:3246 unix-pc.general:6771 unix-pc.bugs:156 Path: utzoo!telly!eci386!ecicrl!clewis From: clewis@ecicrl.UUCP (Chris Lewis) Newsgroups: comp.lang.perl,unix-pc.general,unix-pc.bugs Subject: Re: Math error in Perl PL41 Message-ID: <989@ecicrl.UUCP> Date: 5 Dec 90 23:48:18 GMT References: <978@ecicrl.UUCP> Reply-To: clewis@ecicrl.UUCP (Chris Lewis) Followup-To: comp.lang.perl Organization: Elegant Communications Inc., Ottawa, Canada Lines: 47 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) Brought to you by Super Global Mega Corp .com