Extension methods for integer values.

Static variables

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

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

Static methods

staticinlineabs(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.

staticinlineclamp(v:Int, min:Int, max:Int):Int

clamp restricts a value within the specified range.

staticinlineclampSym(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.

staticinlineisEven(v:Int):Bool

isEven returns true if v is even, false otherwise.

staticinlineisOdd(v:Int):Bool

isOdd returns true if v is odd, false otherwise.

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

Returns the least common multiple

@:value({ pad : "0" })staticlpad(v:Int, pad:String = "0", len:Int):String

staticinlinemax(a:Int, b:Int):Int

It returns the maximum value between a and b.

staticinlinemin(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.

@:value({ min : 0 })staticinlinerandom(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);

@:value({ step : 1 })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.

@:value({ step : 1 })staticrangeIter(start:Int, ?stop:Int, step:Int = 1):Iterator<Int>

@:value({ pad : "0" })staticinlinerpad(v:Int, pad:String = "0", len:Int):String

staticinlinesign(value:Int):Int

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

staticinlinetoBase(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.

staticinlinetoBool(v:Int):Bool

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

staticinlinetoInt(s:String, ?base:Int):Int

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

statictoString(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.