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