Thread: Table Iteration
View Single Post
03-30-13, 12:24 PM   #7
Sharparam
A Flamescale Wyrmkin
 
Sharparam's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2011
Posts: 102
Originally Posted by Clamsoda View Post
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:
  1. local value = 100
  2. value = value * 1.6
  3. value = value * 1.4
  4. print(value) -- 224
  5. value = 100
  6. value = value * 1.4
  7. value = value * 1.6
  8. print(value) -- 224
  9.  
  10. -- Since (a * b) * c == a * b * c == a * (b * c) == a * k where k = (b * c)

Originally Posted by Clamsoda View Post
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.

Last edited by Sharparam : 03-30-13 at 12:28 PM.
  Reply With Quote