Hi again ;)
I know that as2lib is not develop for specific
mathematics programming but there is a lack in MM Math
Class...
So some basic operations can be implemented in MathUtil
to fill this lack.
For exemple a "inverse" method
------------------------------------------------
public static function inverse(n:Number) : Number {
if(n==0) return 0;
return 1/n;
}
------------------------------------------------
A "nrt" method for returning any root of number (not
simply the square root).
------------------------------------------------
public static function
nrt(num:NaturalNumberIncludingZero, rt:NaturalNumber) :
Number {
if(arguments.length != 2)
throw new IllegalArgumentException("Wrong
parameters", eval("th"+"is"), arguments)
return Math.pow(num,1/rt);
}
------------------------------------------------
And another very useful when working on Number, stats,
etc...a "Mean" methods to calculate the mean of many
numbers.
I think about a an overloading implementation to give
possibility to pass an array or a TypedArray (with
Number type).
Indeed we can calculate mean only on Number variable ;)
I test it
------------------------------------------------
public static function mean(array) : Number {
var overload:Overload = new Overload(eval("th"+"is"));
overload.addHandler([Array], _meanWithArray);
overload.addHandler([TypedArray], _meanWithTypedArray);
return overload.forward(arguments);
}
private static function _meanWithArray(array:Array) :
Number {
var oTA:TypedArray = new TypedArray(Number);
var inc:Number = 0;
var l:Number = array.length;
for(var i:Number = 0; i < l; i++) oTA.push(array[i]);
for(var j:Number = 0; j < l; j++) inc += oTA[j];
return inc/l;
}
private static function
_meanWithTypedArray(array:Array) : Number {
//GetType method corresponding to the RFE 1114626 in
SourceForge ;)
if(array.getType() != Number)
throw new IllegalArgumentException("[" + array + "]
TypedArray is not a Number TypedArray",
eval("th"+"is"), arguments)
var inc:Number = 0;
var l:Number = array.length;
for(var i:Number = 0; i < l; i++) inc += array[i];
return inc/l;
}
------------------------------------------------
I make some tests or all seems to work well... ;)
What do you think about adding kind of method in as2lib
framework ? Useful for basic math manipulation no ?
thanls.
eRom.
Logged In: YES
user_id=901744
Reassigned to Christophe Herreman