Tag: maths

Some Uses for the Modulos Operator (%)

Posted on March 21, 2011 in Tutorials

I've been learning about a few of the awesome things you can do with the modulos operator lately. For those who don't know, the modulos operator (the percent symbol in code) gives the remainder of dividing two numbers. Therefore, 10 % 4 equals 2, because 4 goes into 10 two times, and what we have left is the number 2. Now let's get into what we can do (note, I'll be using Ruby code here,...

Read more...

Simulate Bitwise Shift Operators in Lua

Posted on March 21, 2011 in Tutorials

EDIT: Here's a couple functions which will do the shift operations that I've put in gist #938502. The fact that Lua doesn't have bitwise operators is a pain. There are pure Lua implementations out there, such as LuaBit, but I find these to be a little slow (I think LuaBit using tables or something like that). I've found a way to simulate both the left-shift and right-shift operator by using some simple mathematics. Left-Shift By...

Read more...