Packagesandy.util
Classpublic class NumberUtil

Utility class for useful numeric constants and number manipulation.



Public Properties
 PropertyDefined by
  HALF_PI : Number
[static][read-only] Math constant pi/2.
NumberUtil
  PI : Number
[static][read-only] Math constant pi.
NumberUtil
  TO_DEGREE : Number
[static][read-only] Constant used to convert angle from radians to degrees.
NumberUtil
  TOL : Number = 0.00001
[static] Value used to compare numbers with.
NumberUtil
  TO_RADIAN : Number
[static][read-only] Constant used to convert degrees to radians.
NumberUtil
  TWO_PI : Number
[static][read-only] Math constant pi*2.
NumberUtil
Public Methods
 MethodDefined by
  
areEqual(p_nN:Number, p_nM:Number):Boolean
[static] Compares two numbers and determines if they are equal.
NumberUtil
  
constrain(p_nN:Number, p_nMin:Number, p_nMax:Number):Number
[static] Constrains a number to a given interval.
NumberUtil
  
isZero(p_nN:Number):Boolean
[static] Determines if a number is regarded as zero.
NumberUtil
  
roundTo(p_nN:Number, p_nRoundToInterval:Number = 0):Number
[static] Rounds a number to specified accuracy.
NumberUtil
  
toDegree(p_nRad:Number):Number
[static] Converts an angle from radians to degrees
NumberUtil
  
toRadian(p_nDeg:Number):Number
[static] Converts an angle from degrees to radians.
NumberUtil
Property detail
HALF_PIproperty
HALF_PI:Number  [read-only]

Math constant pi/2.

Implementation
    public static function get HALF_PI():Number
PIproperty 
PI:Number  [read-only]

Math constant pi.

Implementation
    public static function get PI():Number
TO_DEGREEproperty 
TO_DEGREE:Number  [read-only]

Constant used to convert angle from radians to degrees.

Implementation
    public static function get TO_DEGREE():Number
TOLproperty 
public static var TOL:Number = 0.00001

Value used to compare numbers with.

Basically used to say if a number is zero or not.
Adjust this number with regard to the precision of your application

TO_RADIANproperty 
TO_RADIAN:Number  [read-only]

Constant used to convert degrees to radians.

Implementation
    public static function get TO_RADIAN():Number
TWO_PIproperty 
TWO_PI:Number  [read-only]

Math constant pi*2.

Implementation
    public static function get TWO_PI():Number
Method detail
areEqual()method
public static function areEqual(p_nN:Number, p_nM:Number):Boolean

Compares two numbers and determines if they are equal.

Adjust the TOL property depending on the precision of your application.

Parameters
p_nN:Number — The first number.
 
p_nM:Number — The second number.

Returns
Boolean — Whether the numbers are regarded as equal.
constrain()method 
public static function constrain(p_nN:Number, p_nMin:Number, p_nMax:Number):Number

Constrains a number to a given interval.

Parameters
p_nN:Number — The number to constrain.
 
p_nMin:Number — The minimal valid value.
 
p_nMax:Number — The maximal valid value.

Returns
Number — The constrained number.
isZero()method 
public static function isZero(p_nN:Number):Boolean

Determines if a number is regarded as zero.

Adjust the TOL property depending on the precision of your application.

Parameters
p_nN:Number — The number to compare to zero.

Returns
Boolean — Whether the number is to be regarded as zero.
roundTo()method 
public static function roundTo(p_nN:Number, p_nRoundToInterval:Number = 0):Number

Rounds a number to specified accuracy.

To round off the number to 2 decimals, set the the accuracy to 0.01

Parameters
p_nN:Number — The number to round.
 
p_nRoundToInterval:Number (default = 0) — The accuracy to which to round.

Returns
Number — The rounded number.
toDegree()method 
public static function toDegree(p_nRad:Number):Number

Converts an angle from radians to degrees

Parameters
p_nRad:Number — A number representing the angle in radians.

Returns
Number — The angle in degrees.
toRadian()method 
public static function toRadian(p_nDeg:Number):Number

Converts an angle from degrees to radians.

Parameters
p_nDeg:Number — A number representing the angle in dregrees.

Returns
Number — The angle in radians.