5 ms·
In C# this would be wrong (-123 % 2 == 1).Dump(); Prints False. % in C# is the remainder operator, not canonical modulus.
by LandR 8y ago
In C# this would be wrong
(-123 % 2 == 1).Dump();
Prints False.
% in C# is the remainder operator, not canonical modulus.
- deleted 8y ago[deleted]
- craftyguy 8y agoWell that's not confusing at all. Why would C# change the definition of a common operator character?
- bjoli 8y agoI think you would be surprised if you started looking around to see how how % is handled.
- tonyarkles 8y agoJavascript 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...)
- justin66 8y agoThis 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.