API / Core / Math / Int

Int

abs

RESCRIPT
let abs: int => int

abs(v) returns absolute value of v. See Math.abs on MDN.

Examples

RESCRIPT
Math.Int.abs(-2) // 2 Math.Int.abs(3) // 3

clz32

RESCRIPT
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

RESCRIPT
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

RESCRIPT
Math.Int.imul(3, 4) // 12 Math.Int.imul(-5, 12) // 60

min

RESCRIPT
let min: (int, int) => int

min(a, b) returns the minimum of its two integer arguments. See Math.min on MDN.

Examples

RESCRIPT
Math.Int.min(1, 2) // 1 Math.Int.min(-1, -2) // -2

minMany

RESCRIPT
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

RESCRIPT
Math.Int.minMany([1, 2]) // 1 Math.Int.minMany([-1, -2]) // -2 Math.Int.minMany([])->Float.isFinite // false

max

RESCRIPT
let max: (int, int) => int

max(a, b) returns the maximum of its two integer arguments. See Math.max on MDN.

Examples

RESCRIPT
Math.Int.max(1, 2) // 2 Math.Int.max(-1, -2) // -1

maxMany

RESCRIPT
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

RESCRIPT
Math.Int.maxMany([1, 2]) // 2 Math.Int.maxMany([-1, -2]) // -1 Math.Int.maxMany([])->Float.isFinite // false

pow

RESCRIPT
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

RESCRIPT
Math.Int.pow(2, ~exp=4) // 16 Math.Int.pow(3, ~exp=4) // 81

sign

RESCRIPT
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

RESCRIPT
Math.Int.sign(3) // 1 Math.Int.sign(-3) // 1 Math.Int.sign(0) // 0

floor

RESCRIPT
let floor: float => int

floor(v) returns the largest int less than or equal to the argument; the result is pinned to the range of the int data type: -2147483648 to 2147483647. See Math.floor on MDN.

Examples

RESCRIPT
Math.Int.floor(3.7) == 3 Math.Int.floor(3.0) == 3 Math.Int.floor(-3.1) == -4 Math.Int.floor(-1.0e15) == -2147483648 Math.Int.floor(1.0e15) == 2147483647

random

RESCRIPT
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

RESCRIPT
Math.Int.random(2, 5) == 4 Math.Int.random(505, 2000) == 1276 Math.Int.random(-7, -2) == -4