How would I find the Inverse of this equation?
because I don’t know how to inverse the “math.floor” part.
local n = RandomWholeNumberInput
math.floor((n) / 4 + 0.5) * 4
How would I find the Inverse of this equation?
because I don’t know how to inverse the “math.floor” part.
local n = RandomWholeNumberInput
math.floor((n) / 4 + 0.5) * 4
The inverse of a floor operation would require you to know the remainder so you can add it to the answer.
i.e, math.floor(n) is equivalent to:
n - n%1
So if you can find n%1, you can add it to the above to make the - n%1 cancel out and end up with n again.
To put it into perspective, you’re doing something like this:
n = n/4 + 0.5
local floor = n - n%1
local result = floor * 4
-- altogether
((n/4 + 0.5) - (n/4 + 0.5)%1) * 4
So you would have to do something like this to revert it:
result = result / 4
result = result + (n/4 + 0.5)%1
result = result - 0.5
result = result * 4
With augmented ops:
result /= 4
result += (n/4 + 0.5)%1
result -= 0.5
result *= 4
I have no Idea what “%” means. regarding roblox math functions
math.floor is a non-injective function, meaning there can be multiple inputs that will give you the same output. Which means there is no complete inverse. If you have an equation like math.floor(x) = 3, there would be no way to know what x was, since it could be something like 3.1, 3.5, or even just 3.
At best you can only predict the range of the input, e.g. if floor(x) = 3, then 3 <= x < 4
OMG THANKS SOO MUCH!!! I’ve been trying to do this for ages. you have no idea how helpful this is.
% is the modulo operator, which gives you the remainder of a value if you divided it by the right number.
n % 1 gives you only the fractional part of n,n % 2 tells you whether n is even or odd,n % 10 gives you the right-most digit of n.It is actually a very common operator that can be found in nearly any programming language, so you can just google it.