This is the latest docs version
Quick Links
  • -Overview
  • -Language Features
  • -JS Interop
  • -Build System
Documentation
Language Manual
Reference for all language features
ReScript & React
First class bindings for ReactJS
GenType
Seamless TypeScript integration
Reanalyze
Dead Code & Termination analysis
Exploration
Packages
Explore third party libraries and bindings
Syntax Lookup
Discover all syntax constructs
APIPlaygroundBlogCommunity
  • Playground
  • Blog
  • Twitter
  • GitHub
  • Forum
Core Module
Overview
Core
submodules
  • Array
  • ArrayBuffer
  • AsyncIterator
  • BigInt
  • BigInt64Array
    • Constants
    BigUint64Array
    • Constants
  • Console
  • DataView
  • Date
    • UTC
  • Dict
  • Error
    • URIError
    • TypeError
    • SyntaxError
    • ReferenceError
    • RangeError
    • EvalError
  • Exn
  • Float
    • Constants
    Float32Array
    • Constants
    Float64Array
    • Constants
    Int
    • Constants
    Int16Array
    • Constants
    Int32Array
    • Constants
    Int8Array
    • Constants
  • Internal
  • Intl
    • Segments
    • Segmenter
    • RelativeTimeFormat
    • PluralRules
    • NumberFormat
      • Grouping
    • Locale
    • ListFormat
    • DateTimeFormat
    • Collator
    • Common
  • Iterator
  • JSON
    • Decode
    • Encode
    • Classify
  • List
  • Map
  • MapperRt
  • Math
    • Int
      • v
        abs
      • v
        clz32
      • v
        imul
      • v
        min
      • v
        minMany
      • v
        max
      • v
        maxMany
      • v
        pow
      • v
        sign
      • v
        floor
      • v
        random
    • Constants
  • Null
  • Nullable
  • Object
  • Option
  • Ordering
  • Promise
  • Re
    • Result
    RegExp
    • Result
  • Result
  • Set
  • String
  • Symbol
  • Type
    • Classify
  • TypedArray
  • Uint16Array
    • Constants
    Uint32Array
    • Constants
    Uint8Array
    • Constants
    Uint8ClampedArray
    • Constants
  • WeakMap
  • WeakSet
  • API / Core / Math / Int

    Int

    Provide Math utilities for 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([])->Int.toFloat->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([])->Int.toFloat->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
    Types and values
    • v
      abs
    • v
      clz32
    • v
      imul
    • v
      min
    • v
      minMany
    • v
      max
    • v
      maxMany
    • v
      pow
    • v
      sign
    • v
      floor
    • v
      random

    © 2024 The ReScript Project

    Software and assets distribution powered by KeyCDN.

    About
    • Community
    • ReScript Association
    Find us on