Difference between revisions of "User:PROXiCiDE/MathUtil"
Jump to navigation
Jump to search
m
added function: Round
imported>PROXiCiDE m |
imported>PROXiCiDE m (added function: Round) |
||
Line 103: | Line 103: | ||
Bool Function InRange(Float x,Float min,Float max) | Bool Function InRange(Float x,Float min,Float max) | ||
Return (min <= x && x <= max) | Return (min <= x && x <= max) | ||
EndFunction | |||
;================================================================================= | |||
; Round() | |||
; Float : afValue - number to round | |||
; Int : iMult - Multiplier default is 10 | |||
; Int : iMode - Mode type for rounding | |||
; 0 - Default | |||
; 1 - Up | |||
; 2 - Down | |||
;================================================================================= | |||
Int Function Round(Float afValue, Int iMult = 10, Int iMode = 0) | |||
Int iResults = 0 | |||
If iMode == 1 ; Round Up | |||
Return Math.Ceiling(afValue / iMult) * iMult | |||
ElseIf iMode == 2; Round Down | |||
Return Math.Floor(afValue / iMult) * iMult | |||
Else | |||
Return Math.Floor((afValue * iMult) + 0.5) / iMult | |||
EndIf | |||
EndFunction | EndFunction | ||
</source> | </source> |