Closed p5pRT closed 21 years ago
Hey all\,
The following snippet just appeared on c.l.p.misc\, and I think it unveils a bug (at least on 5.005_03):
\#\!/usr/bin/perl \-w use strict; my $x = my $y = my $z = 0; vec\($x\, 0\, 1\) = 1; vec\($y\, 1\, 1\) = 1; $z = $x | $y; print "$x $y $z\\n"; \_\_END\_\_
The above prints:
1 2 0
The values of $x and $y are fine\, but $z should be 3\, no? If you explicitly set $x to 1 and $y to 2 (without using vec())\, then you get the expected result for $z.
Anybody with a good explanation? I don't have 5.6 handy. Anybody can try it there?
% perl -we 'for (qw(0 "0" "@" "A" "")\, q(" ")) { my $x = eval $_; die if $@; vec($x\,0\,1)=1; print qq($_ => "$x"\, )\, ($x == 1 ? "yes" : "no")\, "\n"; }' 0 => "1"\, no "0" => "1"\, yes Argument "A" isn't numeric in eq at -e line 1. "@" => "A"\, no Argument "A" isn't numeric in eq at -e line 1. "A" => "A"\, no Argument "^A" isn't numeric in eq at -e line 1. "" => ""\, no Argument "!" isn't numeric in eq at -e line 1. " " => "!"\, no
It appears that after C\<$x = 0; vec($x\,0\,1)=1;>\, $x is numeric (no warning) is not numerically equal to 1\, but is the string "1".
Robin
I have a patch for this:
Hey all\,
The following snippet just appeared on c.l.p.misc\, and I think it unveils a bug (at least on 5.005_03):
\#\!/usr/bin/perl \-w use strict; my $x = my $y = my $z = 0; vec\($x\, 0\, 1\) = 1; vec\($y\, 1\, 1\) = 1; $z = $x | $y; print "$x $y $z\\n"; \_\_END\_\_
The above prints:
1 2 0
The values of $x and $y are fine\, but $z should be 3\, no? If you explicitly set $x to 1 and $y to 2 (without using vec())\, then you get the expected result for $z.
Anybody with a good explanation? I don't have 5.6 handy. Anybody can try it there?
% perl -we 'for (qw(0 "0" "@" "A" "")\, q(" ")) { my $x = eval $_; die if $@; vec($x\,0\,1)=1; print qq($_ => "$x"\, )\, ($x == 1 ? "yes" : "no")\, "\n"; }' 0 => "1"\, no "0" => "1"\, yes Argument "A" isn't numeric in eq at -e line 1. "@" => "A"\, no Argument "A" isn't numeric in eq at -e line 1. "A" => "A"\, no Argument "^A" isn't numeric in eq at -e line 1. "" => ""\, no Argument "!" isn't numeric in eq at -e line 1. " " => "!"\, no
It appears that after C\<$x = 0; vec($x\,0\,1)=1;>\, $x is numeric (no warning) is not numerically equal to 1\, but is the string "1".
Robin
Perl-Friends: To unsubscribe\, mail \perl\-friends\-unsubscribe@​perlsupport\.com
With my patch the original script prints "1 2 3" and my script print "yes".
Robin
--- doop.c 2000/05/11 12:55:39 1.1 +++ doop.c 2000/05/11 13:30:41 1.2 @@ -897\,6 +897\,7 @@ } #endif } + SvNIOK_off(targ); /* see t/op/vec.t test 16 */ SvSETMAGIC(targ); }
Patch: --- t/op/vec.t 2000/05/11 13:18:33 1.1 +++ t/op/vec.t 2000/05/11 13:30:41 1.2 @@ -4\,5 +4\,5 @@
-print "1..15\n"; +print "1..16\n";
print vec($foo\,0\,1) == 0 ? "ok 1\n" : "not ok 1\n"; print length($foo) == 0 ? "ok 2\n" : "not ok 2\n"; @@ -24\,4 +24\,6 @@ vec($Vec\, 0\, 32) = 0xbaddacab; print $Vec eq "\xba\xdd\xac\xab" ? "ok 14\n" : "not ok 14\n"; print vec($Vec\, 0\, 32) == 3135089835 ? "ok 15\n" : "not ok 15\n"; +vec($foo = 0\,0\,1) = 1; # ensure $foo forgets its original numerical value +print $foo == 1 ? "ok 16\n" : "not ok 16\n";
End of patch
On Thu\, May 11\, 2000 at 03:35:41PM +0100\, Robin Barker wrote:
--- doop.c 2000/05/11 12:55:39 1.1 +++ doop.c 2000/05/11 13:30:41 1.2 @@ -897\,6 +897\,7 @@ } #endif } + SvNIOK_off(targ); /* see t/op/vec.t test 16 */
That comment won't make sense if the tests are changed around. It would be better to put a real comment here.
SvSETMAGIC\(targ\);
}
Ronald
Fixed by patch supplied by Robin Barker\, the additional test (t/op/vec.t #16) is still in the test suite.
rmb1@cise.npl.co.uk - Status changed from 'open' to 'resolved'
Migrated from rt.perl.org#3223 (status was 'resolved')
Searchable as RT3223$