User:PROXiCiDE/MathUtil
< User:PROXiCiDE
Revision as of 23:47, 9 February 2013 by imported>PROXiCiDE (Created page with "<source lang="papyrus"> ; Returns the smallest of X and Y ; If X is greater than Y, then Y is returned ; If both are equivalent X is returned Int Function MinInt(Int x,Int y) ...")
; Returns the smallest of X and Y
; If X is greater than Y, then Y is returned
; If both are equivalent X is returned
Int Function MinInt(Int x,Int y)
If x < y
Return x
Else
Return y
EndIf
EndFunction
Float Function MinFloat(Float x,Float y)
If x < y
Return x
Else
Return y
EndIf
EndFunction
; Returns the largest of X and Y
; If X is lesser than Y, then Y is returned
; If both are equivalent X is returned
Float Function MaxFloat(Float x,Float y)
If x > y
Return x
Else
Return y
EndIf
EndFunction
Int Function MaxInt(Int x,Int y)
If x > y
Return x
Else
Return y
EndIf
EndFunction
; Is the Number a Even Number?
; 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30
Bool Function IsNumberEven (Int num)
If Math.Floor(num % 2) == 0
Return True
Else
Return False
EndIf
EndFunction
; Is the Number a Odd Number?
; 1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31
Bool Function IsNumberOdd (Int num)
If Math.Floor(num % 2) == 1
Return True
Else
Return False
EndIf
EndFunction
; Clamps a Value with-in a given Min and Max Range
; If X is lesser than Min , Results = Min
; If X is greater than Max , Results = Max
; Otherwise Return X
Float Function ClampFloat(Float x,Float min,Float max)
Return MinFloat(MaxFloat(x,min),max)
EndFunction
Int Function ClampInt(Int x,Int min,Int max)
Return MinInt(MaxInt(x,min),max)
EndFunction
; Checks to see if Value is with-in a Range of Min and Max
; If X is greater than Max, Returns False
; If X is lesser than Min, Returns False
; Otherwise return True
Bool Function InRange(Float x,Float min,Float max)
If min <= x && x <= max
Return True
Else
Return False
EndIf
EndFunction