Floats contains helper methods to work with Float values.

Static variables

staticinline read onlyEPSILON:Float = 1e-9

Constant value employed to see if two Float values are very close.

staticinline read onlyTOLERANCE:Float = 10e-5

staticread onlymonoid:Monoid<Float> = { zero : 0.0, append : function(a:Float, b:Float) return a + b }

staticread onlyorder:Ord<Float> = Ord.fromIntComparison(compare)

The ordering instance for floating-point values.

Static methods

staticangleDifference (a:Float, b:Float, turn:Float = 360.0):Float

Returns the angular distance between 2 angles.

staticcanParse (s:String):Bool

canParse checks if a string value can be safely converted into a Float value.

staticceilTo (f:Float, decimals:Int):Float

Rounds a number up to the specified number of decimals.

staticinline clamp (v:Float, min:Float, max:Float):Float

clamp restricts a value within the specified range.

trace(1.3.clamp(0, 1)); // prints 1
trace(0.8.clamp(0, 1)); // prints 0.8
trace(-0.5.clamp(0, 1)); // prints 0.0

staticinline clampSym (v:Float, max:Float):Float

Like clamp but you only pass one argument (max) that is used as the upper limit and the opposite (additive inverse or -max) as the lower limit.

staticinline compare (a:Float, b:Float):Int

It returns the comparison value (an integer number) between two float values.

staticfloorTo (f:Float, decimals:Int):Float

Rounds a number down to the specified number of decimals.

staticinline ftrunc (value:Float):Float

staticinterpolate (f:Float, a:Float, b:Float):Float

interpolate returns a value between a and b for any value of f between 0 and 1.

staticinterpolateAngle (f:Float, a:Float, b:Float, turn:Float = 360):Float

Interpolates values in a polar coordinate system looking for the narrowest delta angle.

It can be either clock-wise or counter-clock-wise.

staticinterpolateAngleCCW (f:Float, a:Float, b:Float, turn:Float = 360):Float

Interpolates values in a polar coordinate system always in counter-clock-wise direction.

staticinterpolateAngleCW (f:Float, a:Float, b:Float, turn:Float = 360):Float

Interpolates values in a polar coordinate system always in clock-wise direction.

staticinterpolateAngleWidest (f:Float, a:Float, b:Float, turn:Float = 360):Float

Interpolates values in a polar coordinate system looking for the wideset delta angle.

It can be either clock-wise or counter-clock-wise.

staticinline max<T> (a:T, b:T):T

Return the maximum value between two integers or floats.

staticinline min<T> (a:T, b:T):T

Return the minimum value between two integers or floats.

staticinline nearEqualAngles (a:Float, b:Float, turn:Float = 360.0, tollerance:Float = EPSILON):Bool

Float numbers can sometime introduce tiny errors even for simple operations. nearEqualAngles compares two angles (default is 360deg) using a tiny tollerance (last optional argument). By default the tollerance is defined as EPSILON.

staticnearEquals (a:Float, b:Float, tollerance:Float = EPSILON):Bool

Float numbers can sometime introduce tiny errors even for simple operations. nearEquals compares two floats using a tiny tollerance (last optional argument). By default it is defined as EPSILON.

staticinline nearZero (n:Float, tollerance:Float = EPSILON):Bool

nearZero finds if the passed number is zero or very close to it. By default EPSILON is used as the tollerance value.

staticinline normalize (v:Float):Float

normalize clamps the passwed value between 0 and 1.

staticparse (s:String):Float

parse can parse a string and tranform it into a Float value.

staticinline root (base:Float, index:Float):Float

Computes the nth root (index) of base.

staticroundTo (f:Float, decimals:Int):Float

Rounds a number to the specified number of decimals.

staticinline sign<T> (value:T):Int

sign returns -1 if value is a negative number, 1 otherwise.

staticinline toFloat (s:String):Float

Alias for parse, mainly for disambiguation with other parses using mega Thx.

staticinline toString (v:Float):String

staticinline trunc (value:Float):Int

staticwrap (v:Float, min:Float, max:Float):Float

Passed two boundaries values (min, max), wrap ensures that the passed value v will be included in the boundaries. If the value exceeds max, the value is reduced by min repeatedely until it falls within the range. Similar and inverted treatment is performed if the value is below min.

staticwrapCircular (v:Float, max:Float):Float

Similar to wrap, it works for numbers between 0 and max.