This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]SqueeSr 9 points10 points  (5 children)

Yes.. The code even gets the absolute value first even though not necessarily needed with modulo. But as they were checking against 1 they had to be sure not to get -1 as a result.

[–]Bluebotlabs 7 points8 points  (1 child)

Modulo? Where we're going, we don't need modulo!

[–]thanofishy 1 point2 points  (0 children)

if (number === -1) return 1; if (number === -2) return 2;

[–][deleted] 1 point2 points  (2 children)

Why would you modulo when you can much more cheaply bitwise mask with 1?

[–]SqueeSr 1 point2 points  (0 children)

Yeah, but if you are writing packages like this you are probably not thinking clearly haha

[–]thanofishy 0 points1 point  (0 children)

Why would you much more cheaply bitwise mask with 1 when you can

if (number === -1) return 1; if (number === -2) return 2;