Kyahx's Avatar
Files 6
Downloads 28,314
Favorites 376
My AddOns
View Bug Report
Not quite a bug... Rounding code
Bug #: 1883
File: FreeRefills
Date: 08-17-06 12:53 PM
By: Cogwheel
Status: Unconfirmed
Your current rounding code is rather inefficient. First, the number is converted to a string, then it's formatted, then converted back to a number. It doesn't necessarily cause a problem for FreeRefills, but if you ever use it in something where performance is an issue, it definitely needs to be changed.

First, you should be aware of the standard math function, math.floor. This returns the nearest integer less than or equal to the number passed to it. Examples (I believe WoW lets you use them without the math. but i can't check at the time of this writing):

Code:
math.floor(1) == 1
math.floor(1.9) == 1
Essentially, math.floor(num) is identical to FreeRefills:RoundNumberDown(num). Now, as far as FreeRefills:RoundNumberUp, here is how it would be written using floor:

Code:
math.floor(num + 0.5)
Simple, eh? ;)

I'll leave it as an exercise for you to understand how that works.

RSS 2.0 Feed for Bug CommentsNotes Sort Options
By: Kyahx - 08-17-06 02:09 PM
Thanks Cogwheel, I'll play around with this later tonight.
By: Cogwheel - 09-07-06 09:34 AM
Hmmm.... it seems there *is* a slight bug with the rounding code. When I am tracking 20 Alterac Swiss (comes in stacks of 5, stacks in lots of 20), If I have 1, 6, 11, or 16 in my inventory, it will buy an extra 5 leaving me with 21. (I have turned off overstock so this shouldn't happen). It works fine with all other amounts.

I actually had to deal with the same situation in BuyEmAll. You might look there for some inspiration if I don't have time to come up with a fix.