Int
Provide Math utilities for int
abs
let abs: int => int
abs(v)
returns absolute value of v
.
See Math.abs
on MDN.
Examples
RESCRIPTMath.Int.abs(-2) // 2
Math.Int.abs(3) // 3
clz32
let clz32: int => int
clz32(v)
returns the number of leading zero bits of the argument's 32 bit
int representation.
See Math.clz32
on MDN.
Examples
RESCRIPT// 00000000000000000000000000000001
Math.Int.clz32(1) // 31
// 00000000000000000000000000000100
Math.Int.clz32(4) // 29
imul
let imul: (int, int) => int
imul(a, b)
returns 32-bit integer multiplication. Use this only when you
need to optimize performance of multiplication of numbers stored as 32-bit
integers.
See Math.imul
on MDN.
Examples
RESCRIPTMath.Int.imul(3, 4) // 12
Math.Int.imul(-5, 12) // 60
min
let min: (int, int) => int
min(a, b)
returns the minimum of its two integer arguments.
See Math.min
on MDN.
Examples
RESCRIPTMath.Int.min(1, 2) // 1
Math.Int.min(-1, -2) // -2
minMany
let minMany: array<int> => int
minMany(arr)
returns the minimum of the integers in the given array arr
.
Returns Infinity
if arr
is empty.
See Math.min
on MDN.
Examples
RESCRIPTMath.Int.minMany([1, 2]) // 1
Math.Int.minMany([-1, -2]) // -2
Math.Int.minMany([])->Int.toFloat->Float.isFinite // false
max
let max: (int, int) => int
max(a, b)
returns the maximum of its two integer arguments.
See Math.max
on MDN.
Examples
RESCRIPTMath.Int.max(1, 2) // 2
Math.Int.max(-1, -2) // -1
maxMany
let maxMany: array<int> => int
maxMany(arr)
returns the maximum of the integers in the given array arr
.
Returns Infinity
if arr
is empty.
See Math.max
on MDN.
Examples
RESCRIPTMath.Int.maxMany([1, 2]) // 2
Math.Int.maxMany([-1, -2]) // -1
Math.Int.maxMany([])->Int.toFloat->Float.isFinite // false
pow
let pow: (int, ~exp: int) => int
pow(a, ~exp)
raises the given base a
to the given exponent exp
.
See Math.pow
on MDN.
Examples
RESCRIPTMath.Int.pow(2, ~exp=4) // 16
Math.Int.pow(3, ~exp=4) // 81
sign
let sign: int => int
sign(v)
returns the sign of its integer argument: -1
if negative, 0
if
zero, 1
if positive.
See Math.sign
on MDN.
Examples
RESCRIPTMath.Int.sign(3) // 1
Math.Int.sign(-3) // 1
Math.Int.sign(0) // 0
floor
let floor: float => int
floor(v) returns the largest int
less than or equal to the argument;
See Math.floor
on MDN.
Examples
RESCRIPTMath.Int.floor(3.7) == 3
Math.Int.floor(3.0) == 3
Math.Int.floor(-3.1) == -4
ceil
let ceil: float => int
ceil(v) returns the smallest int
greater than or equal to the argument;
See Math.floor
on MDN.
Examples
RESCRIPTMath.Int.ceil(3.7) == 4
Math.Int.ceil(3.0) == 3
Math.Int.ceil(-3.1) == -3
random
let random: (int, int) => int
random(minVal, maxVal)
returns a random integer number in the half-closed interval [minVal, maxVal).
See Math.random
on MDN.
Examples
RESCRIPTMath.Int.random(2, 5) == 4
Math.Int.random(505, 2000) == 1276
Math.Int.random(-7, -2) == -4