ID:132738
 
round() currently goes to the nearest multiple of the multiple set, however I would like to see a round(num,mult,force) where force can be null, "up" or "down" depending on which way the programmer wishes to force a number.
You can round down by subtracting half a unit, and up by adding half a unit. IE: round(x+0.5, 1) rounds up.
In response to Garthor
Well that seems kind of inconvenient, It's a super basic C++ code called floor( float ).

A monkey could add that feature to BYOND. Just some simple math functions missing in BYOND which should already be there.

Now Garthor, it isn't required for you to post something negative everywhere(trolling). There's nothing wrong with "convenience" features. :)
Leur wrote:
round() currently goes to the nearest multiple of the multiple set, however I would like to see a round(num,mult,force) where force can be null, "up" or "down" depending on which way the programmer wishes to force a number.

round() without a second argument always rounds down to the mathematical floor, so if you want the floor or ceiling for a given multiple, it would be:

// round down to multiple of B (floor)
round(A/B) * B

// round up to multiple of B (ceiling)
round(-A/B) * B

// round towards 0 to multiple of B (integer part)
((A>=0) ? round(A/B) : -round(-A/B)) * B


Lummox JR
In response to Lummox JR
See, it's already in there and I didn't even know it. Now shew shew Garth go away! *Off Tekken goes to get his troll beating stick*.

:)
In response to Tekken
Tekken wrote:
See, it's already in there and I didn't even know it. Now shew shew Garth go away! *Off Tekken goes to get his troll beating stick*.

Garthor was actually only offering a suggestion, and not rudely at all. The method he suggested will work just fine, though I'm sure he was aware of the fact that round() already does a floor operation when only one argument is used. Either way is reasonable.

Lummox JR
In response to Lummox JR
oh, Thanks ;)
You ever check out my grid suggestion >.>
In response to Lummox JR
Oh fine fine, I'll be nice. It's hard to tell if someone is being a troll or not. Just dislike feature requests getting shot down over there being a work-around readily available. Convenience can always be really useful where it is available. Glad to know there are ways to round down and up already though. :)
In response to Lummox JR
Yes, though at the moment I just remembered that the ceiling mucks up on whole numbers. I'm trying to remember if there's a simple solution besides just leaving already-rounded numbers alone.
In response to Garthor
Garthor wrote:
Yes, though at the moment I just remembered that the ceiling mucks up on whole numbers. I'm trying to remember if there's a simple solution besides just leaving already-rounded numbers alone.

-round(-x) will never muck up on whole numbers.

Lummox JR
In response to Lummox JR
Ah, yes, that is the solution I couldn't think of. Though, in the general case, it would be ceil(x,y) = -round(-x-y/2, y).

Or, as a preprocessor macro:

#define ceil(X,Y) -round(-X-Y/2,Y)
#define floor(X,Y) round(X-Y/2,Y)