ID:132738   Nov 23 2009, 7:09 pm 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.
 #1 Nov 23 2009, 7:15 pm You can round down by subtracting half a unit, and up by adding half a unit. IE: round(x+0.5, 1) rounds up.
 #2 Nov 23 2009, 7:23 pm In response to Garthor (#1) 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
 #4 Nov 23 2009, 7:29 pm In response to Lummox JR (#3) 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*. :)
 #5 Nov 23 2009, 7:36 pm In response to Tekken (#4) 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
 #6 Nov 23 2009, 7:38 pm In response to Lummox JR (#3) oh, Thanks ;) You ever check out my grid suggestion >.>
 #7 Nov 23 2009, 7:41 pm In response to Lummox JR (#5) 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. :)
 #8 Nov 23 2009, 11:31 pm In response to Lummox JR (#5) 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.
 #9 Nov 24 2009, 7:01 am In response to Garthor (#8) 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 (#9)
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) ```