Hyperlinkv0.8.0-beta.28

BigInt

BigInt.gcdconsteffect/BigInt.ts:625
(that: bigint): (self: bigint) => bigint
(self: bigint, that: bigint): bigint

Determines the greatest common divisor of two bigints.

When to use

Use to compute the greatest common divisor of two integer values.

Example (Calculating greatest common divisors)

import { BigInt } from "effect"
import * as assert from "node:assert"

assert.deepStrictEqual(BigInt.gcd(2n, 3n), 1n)
assert.deepStrictEqual(BigInt.gcd(2n, 4n), 2n)
assert.deepStrictEqual(BigInt.gcd(16n, 24n), 8n)
mathlcm
Source effect/BigInt.ts:62511 lines
export const gcd: {
  (that: bigint): (self: bigint) => bigint
  (self: bigint, that: bigint): bigint
} = dual(2, (self: bigint, that: bigint): bigint => {
  while (that !== bigint0) {
    const t = that
    that = self % that
    self = t
  }
  return self
})
Referenced by 1 symbols