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 ~## Posts tagged ieee

# sqrt trick

To compute the sqrt, we can use the Newton-Raphson method to converge to a sqrt. Newton serie is: x_(i+1) = x_i – f(x_i)/f’(x_i) for the sqrt we have: sqrt(n) = x or n = x^2 our newton function f(x) becomes: f(x) = x^2 – n. and first derivative: f’(x) = 2x; with our particular f(x), […]

~ read more ~# Number to int conversion tricks !

How to quickly perform a number to int conversion ? So we have a var:n:Number;, to convert our Number to an int, the simple way is: var i:int = int(n); another way, is to just let the compiler do the conversion var i:int = n; or force an integer conversion by performing a degenerated operation: […]

~ read more ~# Math.round to Integer is slow!

here few tricks to speed up things that are really slow when using the Math Object: i = Math.round(a); Assuming you know the minimum possible value of a in your code, lets say -4096, you can do that instead: i = int(a+4096.5)-4096; to perform Math.floor() i = int(a+4096)-4096 the reason we have to do +value […]

~ read more ~# Number no fractional part detection trick!

how to easily know that a Number doesn’t have a fractional part ? I found that first trick when reading http://jacksondunstan.com/ var a:Number = 3.5; if(a is int) {trace(“no fraction”);} little problem, its really slow, and here a faster approach: if(a == int(a)) {trace(“no fraction”);} Note: those 2 Methods only work if ‘a’ is within […]

~ read more ~
## Recent Comments