How to use @xtuc/long - 10 common examples

To help you get started, we’ve selected a few @xtuc/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 xtuc / webassemblyjs / packages / helper-testsuite-runner / src / asserts.js View on Github external
case "f32": {
      const actuali32 = actual.value.reinterpret();
      const expectedi32 = Long.fromString(expected.value).toInt();

      assert(
        actuali32.toNumber() === expectedi32,
        `Expected value ${expectedi32}, got ${actuali32.toString()}`
      );

      break;
    }

    case "f64": {
      const actuali32 = actual.value.reinterpret();
      const expectedi32 = Long.fromString(expected.value).toNumber();

      assert(
        actuali32.toNumber() === expectedi32,
        `Expected value ${expectedi32}, got ${actuali32.toString()}`
      );

      break;
    }

    case "i64": {
      console.warn("eq with i64 is unsupported");
      // const actuali64 = actual.value.toString();
      // const expectedi64 = Long.fromString(expected.value)
      //   .toSigned()
      //   .toString();
github xtuc / webassemblyjs / packages / helper-testsuite-runner / src / asserts.js View on Github external
function eq(actual: StackLocal, expected: Object) {
  // check type
  assert(
    actual.type === expected.type,
    `type mismatch; expected ${expected.type}, given ${actual.type}`
  );

  // check value
  switch (expected.type) {
    case "i32": {
      const i32Value = Long.fromString(expected.value).toInt();

      assert(
        actual.value.toString() === i32Value.toString(),
        `Expected value ${i32Value}, got ${actual.value.toString()}`
      );
      break;
    }

    case "f32": {
      const actuali32 = actual.value.reinterpret();
      const expectedi32 = Long.fromString(expected.value).toInt();

      assert(
        actuali32.toNumber() === expectedi32,
        `Expected value ${expectedi32}, got ${actuali32.toString()}`
      );
github xtuc / webassemblyjs / packages / webassemblyjs / src / interpreter / runtime / values / i64.js View on Github external
static fromArrayBuffer(
    buffer: ArrayBuffer,
    ptr: number,
    extend: number,
    signed: boolean
  ): i64 {
    const slice = buffer.slice(ptr, ptr + 8);
    const value = new Int32Array(slice);
    let longVal = new Long(value[0], value[1]);
    // shift left, then shift right by the same number of bits, using
    // signed or unsigned shifts
    longVal = longVal.shiftLeft(extend);
    return new i64(
      signed ? longVal.shiftRight(extend) : longVal.shiftRightUnsigned(extend)
    );
  }
}
github xtuc / webassemblyjs / packages / webassemblyjs / src / interpreter / kernel / exec.js View on Github external
* https://webassembly.github.io/spec/core/exec/runtime.html#administrative-instructions
       */
      case "unreachable":
      // https://webassembly.github.io/spec/core/exec/instructions.html#exec-unreachable
      case "trap": {
        // signalling abrupt termination
        // https://webassembly.github.io/spec/core/exec/runtime.html#syntax-trap
        throw createTrap();
      }

      case "local": {
        // $FlowIgnore
        const [valtype] = instruction.args;

        if (valtype.name === "i64") {
          const init = castIntoStackLocalOfType(valtype.name, new Long(0, 0));
          frame.locals.push(init);
        } else {
          // $FlowIgnore
          const init = castIntoStackLocalOfType(valtype.name, 0);
          frame.locals.push(init);
        }

        // $FlowIgnore
        trace("new local " + valtype.name);

        break;
      }

      /**
       * Memory Instructions
       *
github xtuc / webassemblyjs / packages / webassemblyjs / src / interpreter / runtime / values / i32.js View on Github external
mul(operand: i32): i32 {
    // https://webassembly.github.io/spec/core/exec/numerics.html#op-imul
    return new i32(
      Long.fromNumber(this._value)
        .mul(Long.fromNumber(operand._value))
        .mod(Math.pow(2, bits))
        .toNumber()
    );
  }
github xtuc / webassemblyjs / packages / webassemblyjs / src / interpreter / runtime / values / i32.js View on Github external
mul(operand: i32): i32 {
    // https://webassembly.github.io/spec/core/exec/numerics.html#op-imul
    return new i32(
      Long.fromNumber(this._value)
        .mul(Long.fromNumber(operand._value))
        .mod(Math.pow(2, bits))
        .toNumber()
    );
  }
github xtuc / webassemblyjs / packages / helper-testsuite-runner / src / asserts.js View on Github external
const compatibleArgs = args.map(x => {
      if (x.type === "i64") {
        return new Long.fromString(x.value);
      }

      return x.value;
    });
github zc910704 / Vue.js-personal-note / www / day6.1.webpack的url-loader与babel / node_modules / @webassemblyjs / wast-printer / esm / index.js View on Github external
function printLongNumberLiteral(n) {
  if (typeof n.raw === "string") {
    return n.raw;
  }

  var _n$value = n.value,
      low = _n$value.low,
      high = _n$value.high;
  var v = new Long(low, high);
  return v.toString();
}
github flaviuse / mern-authentication / client / node_modules / @webassemblyjs / wast-printer / esm / index.js View on Github external
function printLongNumberLiteral(n) {
  if (typeof n.raw === "string") {
    return n.raw;
  }

  var _n$value = n.value,
      low = _n$value.low,
      high = _n$value.high;
  var v = new Long(low, high);
  return v.toString();
}
github xtuc / webassemblyjs / packages / webassemblyjs / src / interpreter / runtime / values / i64.js View on Github external
clz(): i64 {
    let lead = 0;
    const str = this._value.toUnsigned().toString(2);

    for (let i = 0, len = str.length; i < len; i++) {
      if (str[i] !== "0") {
        break;
      }

      lead++;
    }

    return new i64(new Long(lead));
  }

@xtuc/long

A Long class for representing a 64-bit two's-complement integer value.

Apache-2.0
Latest version published 6 years ago

Package Health Score

70 / 100
Full package analysis