A small practical example where Lua’s % behavior is better than C’s

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

A small practical example where Lua’s % behavior is better than C’s

Hisham
I just wrote this, and thought that some of you might enjoy.

http://hisham.hm/2015/04/18/a-small-practical-example-where-luas-behavior-is-better-than-cs/

-- Hisham

Reply | Threaded
Open this post in threaded view
|

Re: A small practical example where Lua’s % behavior is better than C’s

Lourival Vieira Neto
On Sat, Apr 18, 2015 at 7:38 PM, Hisham <[hidden email]> wrote:
> I just wrote this, and thought that some of you might enjoy.
>
> http://hisham.hm/2015/04/18/a-small-practical-example-where-luas-behavior-is-better-than-cs/

Indeed! I often expect the Lua's % behavior while writing C code;
usually, it takes me a few minutes to realize that the universe is not
a nice place =/.

--
Lourival Vieira Neto

Reply | Threaded
Open this post in threaded view
|

Re: A small practical example where Lua’s % behavior is better than C’s

Tangent 128
In reply to this post by Hisham
On 04/18/2015 06:38 PM, Hisham wrote:
> I just wrote this, and thought that some of you might enjoy.
>
> http://hisham.hm/2015/04/18/a-small-practical-example-where-luas-behavior-is-better-than-cs/
>
> -- Hisham
>

Indeed, I once spent hours at a game jam debugging that exact same issue
while trying to wrap sprites.

At least in my usage, % is used for "wrapping" an array at least ten
times as often as getting the mathematical modulo.

And floored modulo just plain graphs tidier:
https://en.wikipedia.org/wiki/File:Divmod.svg

~Joseph Wallace