News for hackers. Stuff that matters.
Re:Low Level Bit Hacks You Absolutely Must Know by LandR on Friday May 11, 2018 @03:05AM (#17045470)
In C# this would be wrong

     (-123 % 2 == 1).Dump();
Prints False.

% in C# is the remainder operator, not canonical modulus.

Re:Low Level Bit Hacks You Absolutely Must Know by tonyarkles on Friday May 11, 2018 @01:32PM (#17049249)
Javascript as well:

    >> -2 % 2
    -0
    >> -3 % 2
    -1
Edit: well, at least in Firefox JS. I have no idea if that's actually standard-mandated behaviour or if it's an implementation quirk. The -0 is especially weird (I had written odd but...)
Re:Low Level Bit Hacks You Absolutely Must Know by justin66 on Friday May 11, 2018 @01:40PM (#17049312)
This is pretty interesting. I don't use js but I took a quick look and apparently (x % 2) == 0 as a test for even integers should still work properly there, since a comparison of -0 and 0 will consider them equivalent.
Re:Low Level Bit Hacks You Absolutely Must Know by craftyguy on Friday May 11, 2018 @12:25PM (#17048615)
Well that's not confusing at all. Why would C# change the definition of a common operator character?
Re:Low Level Bit Hacks You Absolutely Must Know by bjoli on Friday May 11, 2018 @01:52PM (#17049417)
I think you would be surprised if you started looking around to see how how % is handled.