How to use cuint - 10 common examples

To help you get started, we’ve selected a few cuint examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github commaai / cabana / src / models / can / dbc.js View on Github external
valueForInt64Signal(signalSpec, hexData) {
    const blen = hexData.length * 4;
    let value;
    let startBit;
    let dataBitPos;

    if (signalSpec.isLittleEndian) {
      value = UINT64(swapOrder(hexData, 16, 2), 16);
      startBit = signalSpec.startBit;
      dataBitPos = UINT64(startBit);
    } else {
      // big endian
      value = UINT64(hexData, 16);

      startBit = DbcUtils.bigEndianBitIndex(signalSpec.startBit);
      dataBitPos = UINT64(blen - (startBit + signalSpec.size));
    }
    if (dataBitPos < 0) {
      return null;
    }

    const rightHandAnd = UINT64(Math.pow(2, signalSpec.size) - 1);
    let ival = value
      .shiftr(dataBitPos)
      .and(rightHandAnd)
      .toNumber();

    if (signalSpec.isSigned && ival & Math.pow(2, signalSpec.size - 1)) {
      ival -= Math.pow(2, signalSpec.size);
    }
    ival = ival * signalSpec.factor + signalSpec.offset;
    return ival;
github onmyway133 / PushNotifications / node_modules / asar / lib / filesystem.js View on Github external
const handler = () => {
      const size = file.transformed ? file.transformed.stat.size : file.stat.size

      // JavaScript can not precisely present integers >= UINT32_MAX.
      if (size > 4294967295) {
        throw new Error(`${p}: file size can not be larger than 4.2GB`)
      }

      node.size = size
      node.offset = this.offset.toString()
      if (process.platform !== 'win32' && (file.stat.mode & 0o100)) {
        node.executable = true
      }
      this.offset.add(UINT64(size))

      return callback()
    }
github commaai / cabana / src / models / can / dbc.js View on Github external
if (signalSpec.isLittleEndian) {
      value = UINT64(swapOrder(hexData, 16, 2), 16);
      startBit = signalSpec.startBit;
      dataBitPos = UINT64(startBit);
    } else {
      // big endian
      value = UINT64(hexData, 16);

      startBit = DbcUtils.bigEndianBitIndex(signalSpec.startBit);
      dataBitPos = UINT64(blen - (startBit + signalSpec.size));
    }
    if (dataBitPos < 0) {
      return null;
    }

    const rightHandAnd = UINT64(Math.pow(2, signalSpec.size) - 1);
    let ival = value
      .shiftr(dataBitPos)
      .and(rightHandAnd)
      .toNumber();

    if (signalSpec.isSigned && ival & Math.pow(2, signalSpec.size - 1)) {
      ival -= Math.pow(2, signalSpec.size);
    }
    ival = ival * signalSpec.factor + signalSpec.offset;
    return ival;
  }
github electron / asar / lib / filesystem.js View on Github external
// JavaScript can not precisely present integers >= UINT32_MAX.
      if (size > UINT32_MAX) {
        const error = new Error(`${p}: file size can not be larger than 4.2GB`)
        if (reject) {
          return reject(error)
        } else {
          throw error
        }
      }

      node.size = size
      node.offset = this.offset.toString()
      if (process.platform !== 'win32' && (file.stat.mode & 0o100)) {
        node.executable = true
      }
      this.offset.add(UINT64(size))

      return resolve ? resolve() : Promise.resolve()
    }
github commaai / cabana / src / models / can / dbc.js View on Github external
valueForInt64Signal(signalSpec, hexData) {
    const blen = hexData.length * 4;
    let value;
    let startBit;
    let dataBitPos;

    if (signalSpec.isLittleEndian) {
      value = UINT64(swapOrder(hexData, 16, 2), 16);
      startBit = signalSpec.startBit;
      dataBitPos = UINT64(startBit);
    } else {
      // big endian
      value = UINT64(hexData, 16);

      startBit = DbcUtils.bigEndianBitIndex(signalSpec.startBit);
      dataBitPos = UINT64(blen - (startBit + signalSpec.size));
    }
    if (dataBitPos < 0) {
      return null;
    }

    const rightHandAnd = UINT64(Math.pow(2, signalSpec.size) - 1);
    let ival = value
      .shiftr(dataBitPos)
      .and(rightHandAnd)
      .toNumber();

    if (signalSpec.isSigned && ival & Math.pow(2, signalSpec.size - 1)) {
      ival -= Math.pow(2, signalSpec.size);
github pierrec / js-xxhash / lib / xxhash.js View on Github external
c00 = a00 * b00
	c16 = c00 >>> 16

	c16 += a16 * b00
	c16 &= 0xFFFF		// Not required but improves performance
	c16 += a00 * b16

	this._low = c00 & 0xFFFF
	this._high = c16 & 0xFFFF
}

/*
 * Constants
 */
var PRIME32_1 = UINT32( '2654435761' )
var PRIME32_2 = UINT32( '2246822519' )
var PRIME32_3 = UINT32( '3266489917' )
var PRIME32_4 = UINT32(  '668265263' )
var PRIME32_5 = UINT32(  '374761393' )

/**
* Convert string to proper UTF-8 array
* @param str Input string
* @returns {Uint8Array} UTF8 array is returned as uint8 array
*/
function toUTF8Array (str) {
	var utf8 = []
	for (var i=0, n=str.length; i < n; i++) {
		var charcode = str.charCodeAt(i)
		if (charcode < 0x80) utf8.push(charcode)
		else if (charcode < 0x800) {
github pierrec / js-xxhash / lib / xxhash.js View on Github external
c00 = a00 * b00
	c16 = c00 >>> 16

	c16 += a16 * b00
	c16 &= 0xFFFF		// Not required but improves performance
	c16 += a00 * b16

	this._low = c00 & 0xFFFF
	this._high = c16 & 0xFFFF
}

/*
 * Constants
 */
var PRIME32_1 = UINT32( '2654435761' )
var PRIME32_2 = UINT32( '2246822519' )
var PRIME32_3 = UINT32( '3266489917' )
var PRIME32_4 = UINT32(  '668265263' )
var PRIME32_5 = UINT32(  '374761393' )

/**
* Convert string to proper UTF-8 array
* @param str Input string
* @returns {Uint8Array} UTF8 array is returned as uint8 array
*/
function toUTF8Array (str) {
	var utf8 = []
	for (var i=0, n=str.length; i < n; i++) {
		var charcode = str.charCodeAt(i)
		if (charcode < 0x80) utf8.push(charcode)
		else if (charcode < 0x800) {
			utf8.push(0xc0 | (charcode >> 6),
github pierrec / js-xxhash / lib / xxhash.js View on Github external
c16 += a16 * b00
	c16 &= 0xFFFF		// Not required but improves performance
	c16 += a00 * b16

	this._low = c00 & 0xFFFF
	this._high = c16 & 0xFFFF
}

/*
 * Constants
 */
var PRIME32_1 = UINT32( '2654435761' )
var PRIME32_2 = UINT32( '2246822519' )
var PRIME32_3 = UINT32( '3266489917' )
var PRIME32_4 = UINT32(  '668265263' )
var PRIME32_5 = UINT32(  '374761393' )

/**
* Convert string to proper UTF-8 array
* @param str Input string
* @returns {Uint8Array} UTF8 array is returned as uint8 array
*/
function toUTF8Array (str) {
	var utf8 = []
	for (var i=0, n=str.length; i < n; i++) {
		var charcode = str.charCodeAt(i)
		if (charcode < 0x80) utf8.push(charcode)
		else if (charcode < 0x800) {
			utf8.push(0xc0 | (charcode >> 6),
			0x80 | (charcode & 0x3f))
		}
		else if (charcode < 0xd800 || charcode >= 0xe000) {
github pierrec / node-lz4 / lib / binding.js View on Github external
function compressBlock (src, dst, pos, hashTable, sIdx, eIdx) {
	var Hash = uint32() // Reusable unsigned 32 bits integer
	var dpos = sIdx
	var dlen = eIdx - sIdx
	var anchor = 0

	if (src.length >= maxInputSize) throw new Error("input too large")

	// Minimum of input bytes for compression (LZ4 specs)
	if (src.length > mfLimit) {
		var n = exports.compressBound(src.length)
		if ( dlen < n ) throw Error("output too small: " + dlen + " < " + n)

		var 
			step  = 1
		,	findMatchAttempts = (1 << skipStrength) + 3
		// Keep last few bytes incompressible (LZ4 specs):
		// last 5 bytes must be literals
github pierrec / node-lz4 / lib / binding.js View on Github external
// uint32() optimization
,	hashLog			= 16
,	hashShift		= (minMatch * 8) - hashLog
,	hashSize		= 1 << hashLog

,	copyLength		= 8
,	lastLiterals	= 5
,	mfLimit			= copyLength + minMatch
,	skipStrength	= 6

,	mlBits  		= 4
,	mlMask  		= (1 << mlBits) - 1
,	runBits 		= 8 - mlBits
,	runMask 		= (1 << runBits) - 1

,	hasher 			= uint32(2654435761)

// CompressBound returns the maximum length of a lz4 block, given it's uncompressed length
exports.compressBound = function (isize) {
	return isize > maxInputSize
		? 0
		: (isize + (isize/255) + 16) | 0
}

exports.compressHC = exports.compress

exports.compress = function (src, dst, sIdx, eIdx) {
	// V8 optimization: non sparse array with integers
	var hashTable = new Array(hashSize)
	for (var i = 0; i < hashSize; i++) {
		hashTable[i] = 0
	}

cuint

Unsigned integers for Javascript

MIT
Latest version published 8 years ago

Package Health Score

50 / 100
Full package analysis