Learn more  » Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Bower components Debian packages RPM packages NuGet packages

skava / exotic   js

Repository URL to install this package:

Version: 2.0.8 

/ src / types / primitive / number / cast / toInt32.ts

import { MAX_32_BIT } from '../../../NATIVE/CONSTANTS/NATIVE_SIZES'
import toInteger from './toInteger'

/**
 * ToInt32(argument)
 * >> 0 is shorthand for toInt32
 *
 * @name toInt32
 * @alias toSigned32
 * @alias toInteger32
 * @alias to32BitInteger
 * @alias to32Bit
 *
 * @param {number} x any number
 * @return {number} 32bit integer
 *
 * {@link http://2ality.com/2012/02/js-integers.html 2ality-integers}
 * {@link https://developer.mozilla.org/en-US/docs/Mozilla/Projects/SpiderMonkey/JSAPI_reference/JS::ToInt32 mozilla-toint32}
 * {@link https://tc39.github.io/ecma262/#sec-toint32 emca-toint32}
 * {@link https://github.com/facebook/immutable-js/blob/master/src/TrieUtils.js#L93 immutable-js-resolveindex}
 * @see {@link emca-toint32}
 * @see {@link immutable-js-resolveindex}
 * @see {@link 2ality-integers}
 *
 * @see native/MAX_32_BIT
 * @see cast/toInteger
 *
 * @example
 *
 *  toInt32(Math.pow(2,32))   //=> 0
 *  toInt32(Math.pow(2,32)+1) //=> 1
 *
 */
function toInt32(x: any): number {
  return toInteger(x) % MAX_32_BIT
}

export { toInt32 }
export default toInt32