On Fri, 17 Jan 2020, ToddAndMargo via perl6-users wrote:
> Hi All,
> 
> https://docs.raku.org/routine/+$CIRCUMFLEX_ACCENT
> 
> (Operators) infix +^ยง
> 
> multi sub infix:<+^>($a, $b --> Int:D)
> 
> Integer bitwise XOR operator: Coerces both arguments to Int and does a
> bitwise XOR (exclusive OR) operation.
> 
> 
> $ p6 'my uint8 $x=0b0101_0111; my uint8 $y = 0b0000_1111; my uint8 $z =
> +^($x, $y ); say "0", $x.base(2); say "0000", $y.base(2); say $z.base(2);'
> 
> 01010111
> 00001111
> 11111101
> 
> 
> XOR
> A  B   A xor B
> 0  0      0
> 1  0      1
> 0  1      1
> 1  1      0
> 
> That s not what I am seeing above.
> 
> What am I doing wrong this time?
> 
> And who set the high bit making $z negative?
> 

As was already mentioned, if you want to use the &infix:<+^> operator,
you have to either call it by its full name as a sub:

  &infix:<+^>($x, $y)

or you have to use it according to its syntax category, as an infix:

  $x +^ $y

When you write +^($x,$y), its cousin &prefix:<+^> is called instead,
because now you use +^ as a prefix operator. That one performs bitwise
negation on its argument coerced to Int, and since you pass it a list
of length two, you actually evaluate +^2. And that's how you get the
high bit and a value of -3.

Regards,
Tobias

-- 
"There's an old saying: Don't change anything... ever!" -- Mr. Monk

Reply via email to