Extension methods for integer values.

Static variables

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

staticread onlyorder:Ord<Int> = function(i0, i1) { return if (i0 > i1) GT else if (i0 == i1) EQ else LT; }

Static methods

staticinline abs (v:Int):Int

abs returns the absolute integer value of the passed argument.

staticcanParse (s:String):Bool

canParse takes a string and return a boolean indicating if the argument can be safely transformed into a valid integer value.

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

clamp restricts a value within the specified range.

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

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.

staticcompare (a:Int, b:Int):Int

Return a comparison value between a and b. The number is negative if a is greater than b, positive if a is lesser than b or zero if a and b are equals.

staticgcd (m:Int, n:Int):Int

Returns the greater common denominator

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

Given a value t between 0 and 1, it interpolates that value in the range between a and b.

The returned value is a rounded integer.

staticinline isEven (v:Int):Bool

isEven returns true if v is even, false otherwise.

staticinline isOdd (v:Int):Bool

isOdd returns true if v is odd, false otherwise.

staticlcm (m:Int, n:Int):Int

Returns the least common multiple

staticlpad (v:Int, pad:String = "0", len:Int):String

staticinline max (a:Int, b:Int):Int

It returns the maximum value between a and b.

staticinline min (a:Int, b:Int):Int

It returns the minimum value between a and b.

staticparse (s:String, ?base:Int):Null<Int>

Parses a string into an Int value using the provided base. Default base is 16 for strings that begin with 0x (after optional sign) or 10 otherwise.

staticinline random (min:Int = 0, max:Int):Int

Integer random function that includes both upper and lower limits. A roll on a die with 6 sides would be the equivalent to the following:

var d6 = Ints.random(1, 6);

staticrange (start:Int, ?stop:Int, step:Int = 1):Array<Int>

range creates an array of integer containing values between start (included) and stop (excluded) with a progression set by step. A negative value for step can be used but in that case start will need to be a greater value than stop.

staticrangeIter (start:Int, ?stop:Int, step:Int = 1):Iterator<Int>

staticinline rpad (v:Int, pad:String = "0", len:Int):String

staticinline sign (value:Int):Int

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

staticinline toBase (value:Int, base:Int):String

Alias for toString, mainly for disambig. with standard toString using mega Thx. Should toString just be renamed to this? At least with this, existing code doesn't break.

staticinline toBool (v:Int):Bool

Converts an integer value into a boolean. Any value different from 0 will evaluate to true.

staticinline toInt (s:String, ?base:Int):Int

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

staticinline toString (value:Int, base:Int):String

Transform an Int value to a String using the specified base

staticwrapCircular (v:Int, max:Int):Int

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