How to use the long.ZERO function in long

To help you get started, weā€™ve selected a few long 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 olegabu / fabric-starter-rest / gost-deps / fabric-client / lib / utils.js View on Github external
module.exports.convertToLong = (value) => {
	let result;
	if (Long.isLong(value)) {
		result = value; // already a long
	} else if (typeof value !== 'undefined' && value !== null) {
		result = Long.fromValue(value);
		// Long will return a zero for invalid strings so make sure we did
		// not get a real zero as the incoming value
		if (result.equals(Long.ZERO)) {
			if (Number.isInteger(value) || value === '0') {
				// all good
			} else {
				// anything else must be a string that is not a valid number
				throw new Error(util.format('value:%s is not a valid number ', value));
			}
		}
	} else {
		throw new Error('value parameter is missing');
	}

	return result;
};
github datastax / nodejs-driver / lib / types / duration.js View on Github external
function numberOfLeadingZeros(value) {
    if (value.equals(Long.ZERO)) {
      return 64;
    }
    let n = 1;
    let x = value.getHighBits();
    if (x === 0) {
      n += 32;
      x = value.getLowBits();
    }
    if (x >>> 16 === 0) {
      n += 16;
      x <<= 16;
    }
    if (x >>> 24 === 0) {
      n += 8;
      x <<= 8;
    }
github node-modules / node-biginteger / lib / common.js View on Github external
exports.longString = function (i, radix) {
  if (radix < 2 || radix > 36)
    radix = 10;
  if (radix === 10)
    return i.toString();
  var buf = new Array(65);
  var charPos = 64;
  var negative = i.compare(Long.ZERO) < 0;

  if (!negative) {
    i = i.negate();
  }
  radix = Long.fromInt(radix);
  var _radix = radix.negate();
  while (i.compare(_radix) <= 0) {
    var rem = i.subtract(i.div(radix).multiply(radix));
    buf[charPos--] = Integer.digits[rem.negate().low];
    i = i.div(radix);
  }
  buf[charPos] = Integer.digits[i.negate().low];

  if (negative) {
    buf[--charPos] = '-';
  }
github node-modules / node-biginteger / lib / BigInteger.js View on Github external
function multiplyToLen(x, xlen, y, ylen, z) {
  var xstart = xlen - 1;
  var ystart = ylen - 1;

  if (z == null || z.length < (xlen+ ylen))
    z = Common.intArray(xlen+ylen);

  var carry = Long.ZERO;
  for (var j = ystart, k = ystart + 1 + xstart; j >= 0; j--, k--) {
    var product = Long.fromNumber(y[j] >>> 32).multiply(Long.fromNumber(x[xstart] >>> 32)).add(carry);
    z[k] = product.low;
    carry = product.shiftRightUnsigned(32);
  }
  z[xstart] = carry.low;

  for (var i = xstart-1; i >= 0; i--) {
    carry = Long.ZERO;
    for (var j = ystart, k = ystart + 1 + i; j >= 0; j--, k--) {
        var product = Long.fromNumber(y[j] >>> 32).multiply(Long.fromNumber(x[i] >>> 32)).add(Long.fromNumber(z[k] >>> 32)).add(carry);
        z[k] = product.low;
        carry = product.shiftRightUnsigned(32);
    }
    z[i] = carry.low;
  }
github jtorhoff / flier / src / tg / TL / TLMessage.ts View on Github external
serialized(): Uint8Array {
        const content = this.content.serialized();

        const authKeyId = new TLLong(Long.ZERO).serialized();
        const messageId = this.messageId.serialized();
        const length = new TLInt(content.length).serialized();

        return concat(authKeyId, messageId, length, content);
    }
github gridgain / gridgain / modules / platforms / nodejs / lib / internal / ClientSocket.js View on Github external
constructor(endpoint, config, onSocketDisconnect) {
        ArgumentChecker.notEmpty(endpoint, 'endpoints');
        this._endpoint = endpoint;
        this._parseEndpoint(endpoint);
        this._config = config;
        this._state = STATE.INITIAL;
        this._socket = null;
        this._requestId = Long.ZERO;
        this._handshakeRequestId = null;
        this._protocolVersion = null;
        this._requests = new Map();
        this._onSocketDisconnect = onSocketDisconnect;
        this._error = null;
        this._wasConnected = false;
        this._buffer = null;
        this._offset = 0;
    }
github cloudstateio / cloudstate / node-support / src / crdts / gcounter.js View on Github external
this.increment = function (increment) {
    if (Long.ZERO.comp(increment) === 1) {
      throw new Error("Cannot decrement a GCounter");
    }
    currentValue = currentValue.add(increment);
    delta = delta.add(increment);
    return this;
  };
github Azure / azure-sdk-for-js / sdk / servicebus / service-bus / src / core / managementClient.ts View on Github external
*/
  entityPath: string;
  /**
   * @property {string} replyTo The reply to Guid for the management client.
   */
  replyTo: string = generate_uuid();
  /**
   * @property $management sender, receiver on the same session.
   * @private
   */
  private _mgmtReqResLink?: RequestResponseLink;
  /**
   * @property _lastPeekedSequenceNumber Provides the sequence number of the last peeked message.
   * @private
   */
  private _lastPeekedSequenceNumber: Long = Long.ZERO;

  /**
   * @constructor
   * Instantiates the management client.
   * @param {ClientEntityContext} context The client entity context.
   * @param {ManagementClientOptions} [options] Options to be provided for creating the
   * "$management" client.
   */
  constructor(context: ClientEntityContext, options?: ManagementClientOptions) {
    super(`${context.entityPath}/$management`, context, {
      address: options && options.address ? options.address : Constants.management,
      audience:
        options && options.audience
          ? options.audience
          : `${context.namespace.config.endpoint}${context.entityPath}/$management`
    });
github node-modules / node-biginteger / lib / BigInteger.js View on Github external
var xstart = xlen - 1;
  var ystart = ylen - 1;

  if (z == null || z.length < (xlen+ ylen))
    z = Common.intArray(xlen+ylen);

  var carry = Long.ZERO;
  for (var j = ystart, k = ystart + 1 + xstart; j >= 0; j--, k--) {
    var product = Long.fromNumber(y[j] >>> 32).multiply(Long.fromNumber(x[xstart] >>> 32)).add(carry);
    z[k] = product.low;
    carry = product.shiftRightUnsigned(32);
  }
  z[xstart] = carry.low;

  for (var i = xstart-1; i >= 0; i--) {
    carry = Long.ZERO;
    for (var j = ystart, k = ystart + 1 + i; j >= 0; j--, k--) {
        var product = Long.fromNumber(y[j] >>> 32).multiply(Long.fromNumber(x[i] >>> 32)).add(Long.fromNumber(z[k] >>> 32)).add(carry);
        z[k] = product.low;
        carry = product.shiftRightUnsigned(32);
    }
    z[i] = carry.low;
  }
  return z;
}
github cloudstateio / cloudstate / node-support / src / crdts / pncounter.js View on Github external
function PNCounter() {
  let currentValue = Long.ZERO;
  let delta = Long.ZERO;

  /**
   * The value as a long.
   *
   * @name module:cloudstate.crdt.PNCounter#longValue
   * @type {Long}
   * @readonly
   */
  Object.defineProperty(this, "longValue", {
    get: function () {
      return currentValue;
    }
  });

  /**