Modulo (%) operator?

Started by MachineElf, Wed 16/07/2003 23:21:27

Previous topic - Next topic

MachineElf

Isn't the modulo operator (% in C and C++) implented in AGS? Why? Even if most people will probably never use it but I think it would be useful.

(Sorry for posting so much here the last few hours, but I've just gotten around doing a little advanced stuff with AGS again...)
There are 10 kinds of people in the world: Those who understand binary and those who don't.

Gilbert

I think that's just because it's a game environment, not a full programming package. If many people find it useful, I think this can go into the list, as it's not a difficult thing after all. Currently you can do this via:

modx = y - ((y/x)*x);

to get say y mod x .

MachineElf

So that actually works in the engine? This would mean the engine treats the y/x division as a float, which AGS normally doesn't support, right?
There are 10 kinds of people in the world: Those who understand binary and those who don't.

Pumaman

No, the reason it works is because it's not treated as a float.

For example, 5 mod 3 (which equals 2).

modx = 5 - ((5 / 3) * 3)
= 5 - (1 * 3)
= 5 - 3
= 2

MachineElf

Ah! Of course! *epiphany*
Thanks!
There are 10 kinds of people in the world: Those who understand binary and those who don't.

SMF spam blocked by CleanTalk