Int(entional) ?
BlitzMax Forums/BlitzMax Module Tweaks/Int(entional) ?
| ||
Local entional:Float = 0.51 Print Int(entional) '?Shouldn't Int() round a float to the nearest whole number? And if it shouldn't maybe a Round() function would come in handy... |
| ||
No it just cuts of everything after the . (only the old blitz are behaving against the common behavior) For having the old Blitz behavior, you can just do: Print Int(entional + 0.5) which is the same as a rounding function :-) |
| ||
Except if entional is negative :) It's not a big issue, but a native Round function would be handy. |
| ||
BlitzMax really should have a Round() function. The +0.5 trick doesn't work for negative numbers. |
| ||
Function Round(value!) Return value! + (0.5 * Sgn(value!)) End Function ...Or... Adding... Rem bbdoc: Nearest integral value to @x End Rem Function Round:Double( x:Double )="bbRound" End Extern...to 'mod/brl/math/math.bmx' ...and... double bbRound( double x ){ return nearbyint( x ); //Should this be rint()? }...to 'mod/brl/math/math.c'. Seems to work (returns a double to stay consistent with floor() and ceil()). |
| ||
Now, it just needs to be added to the official release :) As far as I understand rint() will work as either floor or ceil depending on the rounding mode used, so it doesn't round to the nearest integral value. |