Originally Posted by Clamsoda
Because the order in which you multiply, when dealing with percents, affects the out-come? Increasing an amount by 60%, then 40% yields a different answer than increasing an amount by 40%, then 60%.
|
lua Code:
local value = 100
value = value * 1.6
value = value * 1.4
print(value) -- 224
value = 100
value = value * 1.4
value = value * 1.6
print(value) -- 224
-- Since (a * b) * c == a * b * c == a * (b * c) == a * k where k = (b * c)
Originally Posted by Clamsoda
I guess you could say that code is performance critical.
|
Does it run very often (like in an OnUpdate script or CLEU)? If not, I think it would be pretty safe to say a few milliseconds extra won't matter too much. Or possibly you could cache the results somewhere(?) and use that in OnUpdate/CLEU.