Secret Perl Operators

You're viewing a comment by Eric TF Bat and its responses.

I couldn't figure out the inchworm-on-a-stick either (I learned Forth in my free time during university and got a High Distinction in Discrete Mathematics 1 because it enabled me to grok how stuff like two's complement arithmetic works). But the trick is that it's not the same as \$x-- or --\$x or \$x-1: it's much weirder than that. Take a look at the output from this:

```foreach my \$x ((1,2,3,-1,-2,-3,0,1.5,2.5,3.1,4.9)) {
printf qq/%+2.2f %+25.2f\n/, \$x, ~-\$x;
}

+1.00                     +0.00
+2.00                     +1.00
+3.00                     +2.00
-1.00  +18446744073709551616.00
-2.00  +18446744073709551616.00
-3.00  +18446744073709551616.00
+0.00  +18446744073709551616.00
+1.50                     +0.00
+2.50                     +1.00
+3.10                     +2.00
+4.90                     +3.00```

Very odd indeed, especially when you replace the second %...f with %d, and then you get this:

```+1.00 +0
+2.00 +1
+3.00 +2
-1.00 -2
-2.00 -3
-3.00 -4
+0.00 -1
+1.50 +0
+2.50 +1
+3.10 +2
+4.90 +3```

What I don't know is what good it would be. I mean, if \$x is non-negative, then it's the same as int(\$x)-1, but the weird result for negative \$x confuses me...

Comment Responses

"What I don't know is what good it would be. I mean, if \$x is non-negative, then it's the same as int(\$x)-1, but the weird result for negative \$x confuses me..."

If something looks weird at sight, it will always have some weird use too.

Have you figured out what this number is or how it came? +18446744073709551616.00

Personally, i think these are good, not for corporate coding, 90% wont understand if you code like this. :D

Things like these are good for people who love to tear down every bit and do maximum exploitation of the language (in a constructive way).

Thank you.