
// Copyright © 2008. Wilbert Brants. All Rights Reserved.

package km.math {

/** The MathFn class contains math functions not available from the Math class.<br>
* The MathFn class should not be instantiated !
*/
final public class MathFn {

	/** Limit a value between a min and max value.
	* @param val Value to limit.
	* @param min Minimum allowed value.
	* @param max Maximum allowed value.
	* @return The result of the limit function.
	* @example
	* <listing>
	* import km.math.~~;
	*   
	* var v:int = 5;
	* v = MathFn.limit(v, 1, 4);
	* </listing>
	*/
	public static function limit(val:*, min:*, max:*):* {
		return val < min ? min : val > max ? max : val; 
	}

	/** Returns the sign of a value (-1, 0 or 1). */
	public static function sgn(val:*):int {
		return val > 0 ? 1 : val < 0 ? -1 : 0; 
	}

}
}