Difference between revisions of "User:PROXiCiDE/MathUtil"
Jump to navigation
Jump to search
imported>PROXiCiDE m |
imported>PROXiCiDE (Applied Optimizations by Cipscis) |
||
Line 1: | Line 1: | ||
<source lang="papyrus"> | <source lang="papyrus"> | ||
;================================================================================= | |||
; Math Functions | |||
; | |||
; Version History | |||
; 0.1 - Initial Release | |||
; 0.2 - Optimizations by Cipscis | |||
; IsNumberEven ,IsNumberOdd ,InRange | |||
;================================================================================= | |||
;================================================================================= | ;================================================================================= | ||
; MinInt() / MinFloat() | ; MinInt() / MinFloat() | ||
Line 50: | Line 59: | ||
;================================================================================= | ;================================================================================= | ||
Bool Function IsNumberEven (Int num) | Bool Function IsNumberEven (Int num) | ||
If Math.Floor(num % 2) | If Math.Floor(num % 2) | ||
Return | Return False | ||
Else | Else | ||
Return | Return True | ||
EndIf | EndIf | ||
EndFunction | EndFunction | ||
Line 62: | Line 71: | ||
; 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 | Bool Function IsNumberEven (Int num) | ||
If Math.Floor(num % 2) | If Math.Floor(num % 2) | ||
Return True | Return True | ||
Else | Else | ||
Return False | Return False | ||
EndIf | EndIf | ||
EndFunction | EndFunction | ||
Line 93: | Line 102: | ||
;================================================================================= | ;================================================================================= | ||
Bool Function InRange(Float x,Float min,Float max) | Bool Function InRange(Float x,Float min,Float max) | ||
Return (min <= x && x <= max) | |||
EndFunction | EndFunction | ||
</source> | </source> |
Revision as of 16:19, 10 February 2013
;=================================================================================
; Math Functions
;
; Version History
; 0.1 - Initial Release
; 0.2 - Optimizations by Cipscis
; IsNumberEven ,IsNumberOdd ,InRange
;=================================================================================
;=================================================================================
; 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)
Return False
Else
Return True
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 IsNumberEven (Int num)
If Math.Floor(num % 2)
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)
Return (min <= x && x <= max)
EndFunction