Edit: I changed this page for arithmatic based modulo. Should be a bit faster. And I must note that as with all floating point operations, accuracy may vary.
Code:
/* forbidden operations */
forward operator%(Float:oper1, Float:oper2);
forward operator%(Float:oper1, oper2);
forward operator%(oper1, Float:oper2);
This is incorrect...
Assuming you only want to return unsigned values in the range [0, oper2)...
Code:
stock Float:operator%(Float:num, Float:modulo)
return num - modulo * floatround(num / modulo);
stock Float:operator%(Float:num, modulo)
return num % float(modulo);
stock Float:operator%(num, Float:modulo)
return float(num) % modulo;
Now, if you want 'simple' support for signed values, use this.
To get a signed byte, a range of [-128 to 12
*: a % -256.0
Code:
stock Float:operator%(Float:num, Float:modulo)
{
new Float:x = num / modulo;
if (modulo < 0) { //Act as though it's a wrapping value (signed)
return (x - floatround(x+0.5,floatround_floor)) * modulo
} //else:
return num - modulo * floatround(-x,floatround_floor);
}
stock Float:operator%(Float:num, modulo)
return num % float(modulo);
stock Float:operator%(num, Float:modulo)
return float(num) % modulo;
*: This is using mathematical notation for ranges, as in:
[a, b] denotes that the value can be anywhere between a and b, and also equal to a or b.
(a, b) denotes that the value can only be between a and b, not equal to either.
Thus, [-128, 12
means the value can be equal to -128, and anywhere between -128 and 128. It cannot be equal to 128, however. Also, floatround(127.5 % 256) would be equivalent to floatround(127.5) % 128.