Skip to content
DavisDevelopment edited this page Dec 30, 2014 · 2 revisions

class tannus.math.TMath

A set of numerical utility functions, most of which are inlined to minimize run-time function-calls when number-crunching.


Class Fields

static inline var INT_MAX : Int = 2147483647

Highest integer-value allowed in the ECMAScript spec

static inline var INT_MIN : Int = -2147483648

Lowest integer-value allowed in the ECMAScript spec


Class Methods

static function toRadians(degrees : Float):Float

Converts from degrees to radians

static function toDegrees(radians : Float):Float

Converts from radians to degrees

static function max(a:Int, b:Int):Int
static function max(a:Float, b:Float):Float

Returns the greater of a and b (if (a > b) a else b)

static function min(a:Int, b:Int):Int
static function min(a:Float, b:Float):Float

Returns the lesser of a and b (if (a < b) a else b)

static function average(nums : Array<Int>):Float
static function average(nums : Array<Float>):Float

Returns the average of all nums

static function clamp(value:Int, min:Int, max:Int):Int
static function clamp(value:Float, min:Float, max:Float):Float

if value < min, returns min
if value > max, returns max

static function sign(num : Float):Int

if num > 0, returns 1
if num < 0, returns -1
if num == 0, returns 0