Math.min and Math.max

BlitzMax Forums/BlitzMax Programming/Math.min and Math.max

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.

Local blah:Int[] = [41,5125,4323,123,25,216,7547,8,101]
Local TestNum:Int
Local TimeCost:Int

TimeCost = MilliSecs()
For Local i:Int = 1 To 1000000
	TestNum = NewMax(blah)
Next

Print MilliSecs()-TimeCost

TimeCost = MilliSecs()
For Local t:Int = 1 To 1000000
	TestNum = nMax(blah)
Next

Print MilliSecs()-TimeCost

Function NewMin:Int(Nums:Int[])
	Local SelNum:Int=2147483647
	For Local i:Int = EachIn Nums
		If I < SelNum Then SelNum = I
	Next
	
	Return SelNum
End Function



Function NewMax:Int(Nums:Int[])
	Local SelNum:Int=-2147483646
	For Local i:Int = EachIn Nums
		If I > SelNum Then SelNum = I
	Next
	
	Return SelNum
End Function

Function nMax:Int(nums:Int[])
	Local tmp:Int[] = nums[..]
	tmp.sort()
	Return tmp[tmp.length-1]
End Function

Function nMin:Int(nums:Int[])
	Local tmp:Int[] = nums[..]
	tmp.sort()
	Return tmp[0]
End Function



I'm an optimization freak =P