View source

class thx.Ints

Available on all platforms

Extension methods for integer values.

Class Fields

static var monoid(default,null):Monoid<Int>

static var order(default,null):Ord<Int>

static inline function abs(v:Int):Int

abs returns the absolute integer value of the passed argument.

static function canParse(s:String):Bool

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

static inline function clamp(v:Int, min:Int, max:Int):Int

clamp restricts a value within the specified range.

static inline function 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.

static inline function compare(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.

static function gcd(m:Int, n:Int):Int

Returns the greater common denominator

static function interpolate(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.

static inline function isEven(v:Int):Bool

isEven returns true if v is even, false otherwise.

static inline function isOdd(v:Int):Bool

isOdd returns true if v is odd, false otherwise.

static function lcm(m:Int, n:Int):Int

Returns the least common multiple

static function lpad(v:Int, pad:String = "0", len:Int):String

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

It returns the maximum value between a and b.

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

It returns the minimum value between a and b.

static function parse(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.

static inline function 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);

static function range(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.

static function rangeIter(start:Int, ?stop:Int, step:Int = 1):Iterator<Int>

static inline function rpad(v:Int, pad:String = "0", len:Int):String

static inline function sign(value:Int):Int

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

static inline function 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.

static inline function toBool(v:Int):Bool

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

static inline function toInt(s:String, ?base:Int):Int

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

static function toString(value:Int, base:Int):String

Transform an Int value to a String using the specified base

static function wrapCircular(v:Int, max:Int):Int

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

Toggle inherited fields