Can we fast compute 1.0/x ? static public function recriprocal( value:Number ):Number { return 1.0/value; } So here some ideas, we already have a fast way to compute 1/sqrt(x), if you look at 1/x and 1/sqrt(x) , you will notice that both equations are pretty close, so it gives us a pretty good “first guess”. […]

~ read more ~## Posts in category Math

# Euclidean division

How to fast perform the euclidean division of two integers and compute the rest the of the division at the same time ? The naive approach is to simply get the result using the / and the % operator: q = i/j; r = i%j; As we know, modulo is very slow, so instead, we […]

~ read more ~# min max float in byteArray

In a previous post, I explored ways to compute the Math.min or Math.max for Numbers (http://guihaire.com/code/?p=550) What if we need to perform this operation when the floats are in a ByteArray ? Lets explore some interesting methods So our ByteArray contains a list of floats or numbers, the easiest way is to use the ternary […]

~ read more ~# Math.min Math.max float

In a previous post, I explored ways to accomplish Math.min and max for integers with some bit twiddling (http://guihaire.com/code/?p=549), Today, we are going to explore ways to find the min or the max of 2 Numbers without using the infamous Math class. Lets start with the min. So the basic: min = Math.min(i,j); One way […]

~ read more ~# Math.min Math.max integer tricks

Lets explore options today to fast get the min or the max of 2 integers values. Let’s start with the min, so we want to optimize: min = Math.min(i,j); One easy optimization is to use the ?: ternary operator to avoid the glue function call: min = (i<j)?i:j; we can replace the i<j by (i-j)>>31 […]

~ read more ~
## Recent Comments