I was thinking about that! Convert to a string, and look to see if the first char is a "-" to determine sign. I don't think your routine works, though.
sub re {
my $i=0; /-(?{$i=$i+1})/ for @_; $i=~/0|2/;
}
given the same test cases as before,
x | y | xorNeg() | spaceship() | mult() | anchor() | re() |
1 | 1 | | 1 | 1 | 1 | 1 |
-1 | 1 | | | | 0 | 1 |
1 | -1 | | | | 0 | 1 |
-1 | -1 | | 1 | 1 | 1 | 1 |
And actually, its only twice as slow...
unit square | spaceship | multiply | logic | re |
spaceship | -------- | worse 21.74% | worse 12.21% | better 86.26% |
multiply | better 21.74% | -------- | better 10.86% | better 89.25% |
logic | better 12.21% | worse 10.86% | -------- | better 87.94% |
reg exp | worse 86.26% | worse 89.25% | worse 87.94% | -------- |