ID:161468
May 3 2008, 6:32 pm
|
|
Is there a way to force byond to do integer rounding, so you don't end up with a decimal number after a division? Rounding is kind of expensive.
|
In response to Darkmag1c1an11
|
|
I said rounding was expensive. Meaning I would rather avoid using that for something that has to run very frequently.
|
In response to Obs
|
|
Well, depending on what you're dividing by, integer division is possible. For example, if dividing by a power of 2, you can use bit-shifting:
64 >> 1 // 64 / 2 ...and so on. Otherwise, round() isn't overly expensive. Hiead |
In response to Obs
|
|
I don't think rounding is actually as expensive as you think; probably less so than the division itself. If you're running this extremely frequently and dividing by powers of 2, then bit-shifting will definitely help you.
Lummox JR |
In response to Hiead
|
|
ah I should have thought of that.
Good. I will make use of this |
round(22/7) returns 3.
Here's another example that's more practical: