Showing posts with label Flash AS3 Optimization Functions. Show all posts
Showing posts with label Flash AS3 Optimization Functions. Show all posts

Wednesday, December 2, 2009

Simple Optimization Functions.

Here are some functions I came up with for various purposes, I'm sure there are more efficient versions out there. If you have any ideas on how to optimize these functions more please comment. If anyone has the time to test these out against their Math.function versions, please let me know the results. Thanks ahead of time.

Faster Rounding (Needs to be tested):
function round (ax:Number):int
{
if (ax>=0){
return int(ax+.5)
} else {
return int(ax-.5)
}
}

Faster Ceiling (Needs to be tested):
function ceil (ax:Number):int
{
if (ax>0){
return int(ax+1)
} else {
return int(ax)
}
}

Faster Flooring (Needs to be tested):
function floor (ax:Number):int
{
if (ax>=0){
return int(ax)
} else {
return int(ax-1)
}
}


Faster Absolute Value (Needs to be tested):
function abs (ax:Number):Number{
if (ax>=0){
return ax
} else {
return -ax
}
}