How to use the long.UONE 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 interledgerjs / ilp-protocol-stream / src / util / long.ts View on Github external
if (rem.greaterThanOrEqual(c)) {
        quo = quo.add(Long.UONE)
        rem = rem.subtract(c)
      }
    }

    // Overflow.
    if (quo.lessThan(oldQuo)) {
      return { quo: Long.MAX_UNSIGNED_VALUE, rem: Long.UZERO }
    }

    a = a.shiftRightUnsigned(1)
    qn = qn.shiftLeft(1)
    rn = rn.shiftLeft(1)
    if (rn.greaterThanOrEqual(c)) {
      qn = qn.add(Long.UONE)
      rn = rn.subtract(c)
    }
  }
  return { quo, rem }
}
github interledgerjs / ilp-protocol-stream / src / util / long.ts View on Github external
export function multiplyDivide (a: Long, b: Long, c: Long): {
  quo: Long,
  rem: Long
} {
  let quo = Long.UZERO // quotient
  let rem = Long.UZERO // remainder
  let qn = b.divide(c)
  let rn = b.modulo(c)

  while (!a.isZero()) {
    let oldQuo = quo
    if (!a.and(Long.UONE).isZero()) {
      quo = quo.add(qn)
      rem = rem.add(rn)
      if (rem.greaterThanOrEqual(c)) {
        quo = quo.add(Long.UONE)
        rem = rem.subtract(c)
      }
    }

    // Overflow.
    if (quo.lessThan(oldQuo)) {
      return { quo: Long.MAX_UNSIGNED_VALUE, rem: Long.UZERO }
    }

    a = a.shiftRightUnsigned(1)
    qn = qn.shiftLeft(1)
    rn = rn.shiftLeft(1)
github interledgerjs / ilp-protocol-stream / src / util / rational.ts View on Github external
function power10 (n: number): Long {
  const ten = Long.fromNumber(10, true)
  let value = Long.UONE
  while (n--) value = value.multiply(ten)
  return value
}
github interledgerjs / ilp-protocol-stream / src / util / rational.ts View on Github external
import * as assert from 'assert'
import * as Long from 'long'
import {
  multiplyDivideFloor,
  multiplyDivideCeil,
  multiplyDivideRound
} from './long'

export default class Rational {
  static UZERO = new Rational(Long.UZERO, Long.UONE, true)

  private a: Long
  private b: Long
  public unsigned: boolean

  constructor (numer: Long, denom: Long, unsigned: boolean) {
    if (!unsigned) {
      throw new Error('signed rationals are not implemented')
    }
    assert.strictEqual(numer.unsigned, unsigned, 'numerator is incorrectly signed')
    assert.strictEqual(denom.unsigned, unsigned, 'denominator is incorrectly signed')
    assert(!denom.isZero(), 'denominator must be non-zero')
    this.a = numer
    this.b = denom
    this.unsigned = unsigned
  }