How to use the long.fromNumber 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 node-modules / node-biginteger / lib / MutableBigInteger.js View on Github external
qhat = nChunk.div(dhLong).low;
        qrem = nChunk.subtract(Long.fromNumber(qhat).multiply(dhLong)).low;
      } else {
        this.divWord(qWord, nChunk, dh);
        qhat = qWord[0];
        qrem = qWord[1];
      }
    }

    if (qhat == 0)
      continue;

    if (!skipCorrection) { // Correct qhat
      var nl = Long.fromNumber(rem.value[j + 2 + rem.offset] >>> 32);
      var rs = Long.fromNumber(qrem >>> 32).shiftLeft(32).or(nl);
      var estProduct = Long.fromNumber(dl >>> 32).multiply(Long.fromNumber(qhat >>> 32));

      if (this.unsignedLongCompare(estProduct, rs)) {
        qhat--;
        var qrem = Long.fromNumber(qrem >>> 32).add(dhLong).low;
        if (Long.fromNumber(qrem >>> 32).compare(dhLong) >= 0) {
          estProduct = estProduct.subtract(Long.fromNumber(dl >>> 32));
          rs = Long.fromNumber(qrem >>> 32).shiftLeft(32).or(nl);
          if (this.unsignedLongCompare(estProduct, rs)) {
            qhat--;
          }
        }

      }
    }

    // D4 Multiply and subtract
github node-modules / node-biginteger / lib / BigInteger.js View on Github external
var len = x.length;
  var product = Long.ZERO;
  var carry = 0;
  for (var i = len-1; i >= 0; i--) {
    
    product = ylong.multiply( Long.fromNumber(x[i] >>> 32) ).add(Long.fromInt(carry));
    x[i] = product.low;
    carry = product.high;
  }
  // Perform the addition
  var sum = (x[len - 1] >>> 32) + zlong;
  sum = Long.fromNumber(sum);
  x[len-1] = sum.low;
  carry = sum.high;
  for (var i = len - 2 ; i >= 0; i--) {
    sum = Long.fromNumber((x[i] >>> 32) + carry);
    x[i] = sum.low;
    carry = sum.high;
  }

};
github cockroachdb / cockroach-gen / pkg / ui / src / views / shared / containers / metricDataProvider / metricDataProvider.spec.tsx View on Github external
describe("", function () {
  let spy: sinon.SinonSpy;
  const timespan1: QueryTimeInfo = {
    start: Long.fromNumber(0),
    end: Long.fromNumber(100),
    sampleDuration: Long.fromNumber(300),
  };
  const timespan2: QueryTimeInfo = {
    start: Long.fromNumber(100),
    end: Long.fromNumber(200),
    sampleDuration: Long.fromNumber(300),
  };
  const graphid = "testgraph";

  beforeEach(function () {
    spy = sinon.spy();
  });

  describe("refresh", function () {
    it("refreshes query data when mounted", function () {
      makeDataProvider(graphid, null, timespan1, spy);
      assert.isTrue(spy.called);
      assert.isTrue(spy.calledWith(graphid, makeMetricsRequest(timespan1)));
    });

    it("does nothing when mounted if current request fulfilled", function () {
github cockroachdb / cockroach-gen / pkg / ui / cluster-ui / src / sessions / sessionsPage.fixture.ts View on Github external
toJSON: () => ({}),
  },
};

export const activeSession: SessionInfo = {
  session: {
    node_id: 1,
    username: "root",
    client_address: "127.0.0.1:57632",
    application_name: "$ cockroach sql",
    active_queries: [
      {
        id: "16290b41dddca4600000000000000001",
        sql: "SELECT pg_sleep(1000)",
        start: {
          seconds: Long.fromNumber(1596819920),
          nanos: 402524000,
        },
        phase: Phase.EXECUTING,
        txn_id: toUuid("e8NTvpOvScO1tSMreygtcg=="),
        sql_anon: "SELECT pg_sleep(_)",
      },
    ],
    start: {
      seconds: Long.fromNumber(1596816675),
      nanos: 652814000,
    },
    last_active_query: "SHOW database",
    id: toUuid("FikITmO2BQAAAAAAAAAAAQ=="),
    alloc_bytes: Long.fromNumber(10240),
    max_alloc_bytes: Long.fromNumber(10240),
    active_txn: {
github iov-one / iov-core / packages / iov-types / src / examples / transactions.ts View on Github external
import Long from "long";

import { Algorithm, PublicKeyBundle } from "../types/keys";
import {
  ChainID,
  Nonce,
  SendTx,
  TokenTicker,
  TransactionKind,
  TTLBytes,
  TTLString,
  UnsignedTransaction,
} from "../types/transactions";
import { addressBytes, publicKeyBytes } from "./keys";

export const nonce: Nonce = Long.fromNumber(123) as Nonce;

export const iov: TokenTicker = "IOV" as TokenTicker;

export const sender: PublicKeyBundle = {
  algo: Algorithm.ED25519,
  data: publicKeyBytes,
};

export const sendTx: SendTx = {
  amount: { whole: 123, fractional: 0, tokenTicker: iov },
  chainId: "bns-testnet-01" as ChainID,
  fee: { whole: 0, fractional: 100, tokenTicker: iov },
  kind: TransactionKind.SEND,
  recipient: addressBytes,
  signer: sender,
};
github discordjs / discord.js / src / util / TransformSearchOptions.js View on Github external
module.exports = function TransformSearchOptions(options, client) {
  if (options.before) {
    if (!(options.before instanceof Date)) options.before = new Date(options.before);
    options.maxID = long.fromNumber(options.before.getTime() - 14200704e5).shiftLeft(22).toString();
  }

  if (options.after) {
    if (!(options.after instanceof Date)) options.after = new Date(options.after);
    options.minID = long.fromNumber(options.after.getTime() - 14200704e5).shiftLeft(22).toString();
  }

  if (options.during) {
    if (!(options.during instanceof Date)) options.during = new Date(options.during);
    const t = options.during.getTime() - 14200704e5;
    options.minID = long.fromNumber(t).shiftLeft(22).toString();
    options.maxID = long.fromNumber(t + 86400000).shift(222).toString();
  }

  if (options.channel) options.channel = client.resolver.resolveChannelID(options.channel);

  if (options.author) options.author = client.resolver.resolveUserID(options.author);

  if (options.mentions) options.mentions = client.resolver.resolveUserID(options.options.mentions);

  return {
    content: options.content,
    max_id: options.maxID,
    min_id: options.minID,
    has: options.has,
    channel_id: options.channel,
    author_id: options.author,
github node-modules / node-biginteger / lib / MutableBigInteger.js View on Github external
MutableBigInteger.prototype.mulsub = function (q, a, x, len, offset) {
  var xLong = Long.fromNumber(x >>> 32);
  var carry = Long.fromNumber(0);
  offset += len;
  for (var j = len - 1; j >= 0; j--) {
    var product = Long.fromNumber(a[j] >>> 32).multiply(xLong).add(carry);
    var difference = Long.fromNumber(q[offset]).subtract(product);
    q[offset--] = difference.low;
    carry = product.shiftRightUnsigned(32).add(
      Long.fromNumber(difference.low >>>32).compare(Long.fromNumber(~product.low >>> 32)) > 0 ? Long.fromInt(1) : Long.fromInt(0)
    );
  }

  return carry.low;
}
github Yosee / flocon / bench / flocon-long.js View on Github external
Flocon.prototype.snow = function() {
  var time = Date.now() - this.epoch;

  if (this.current < time) {
    this.current = time;
    this.count = 0;
  }

  var id = new Long(0x0, 0x0, true);
  id = id.or(Long.fromNumber(time));
  id = id.shiftLeft(10);
  id = id.or(Long.fromNumber(process.pid % 1024));
  id = id.shiftLeft(13);
  id = id.or(Long.fromNumber(++this.count));

  return id.toString();
};
github calvinmetcalf / fileGDB.js / lib / dataType.js View on Github external
function makeLong(n) {
  return Long.fromNumber(n, true);
}
github nlf / protobuf.js / index.js View on Github external
value = Number(!!item);
                } else if (fields[key].type === 'sint32') {
                    value = varint.zigzag(item);
                } else {
                    value = item;
                }

                position += varint.write(result, fields[key].tag << 3, position);
                position += varint.write(result, value, position);
                break;

            case 'int64':
            case 'uint64':
            case 'sint64':
                if (typeof item === 'number') {
                    value = long.fromNumber(item, fields[key].type === 'uint64');
                } else if (typeof item === 'string') {
                    value = long.fromString(item, fields[key].type === 'uint64');
                } else {
                    value = item;
                }

                if (fields[key].type === 'sint64') {
                    value = varint.zigzag64(value);
                }

                position += varint.write(result, fields[key].tag << 3, position);
                position += varint.write64(result, value, position);
                break;

            case 'fixed64':
            case 'sfixed64':