Fix BigInt gcd and lcm edge cases - #6870
Conversation
🦋 Changeset detectedLatest commit: 392b148 The changes in this PR will be included in the next version bump. This PR includes changesets to release 30 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes — 1 new test file with 3 reproduction cases for BigInt gcd and lcm sign bugs.
BigIntGcdLcm.test.ts: tests thatgcd(-6n, 4n) → 2n,lcm(6n, -4n) → 12n, andlcm(0n, 0n) → 0n
All three assertions use exact strictEqual on values the current implementation cannot satisfy (gcd returns -2n for negative inputs, lcm inherits the sign issue, and lcm(0, 0) divides by zero). Tests match the existing BigInt.test.ts conventions.
DeepSeek Pro (free via Pullfrog for OSS) (Kimi K2 not used — the program covers this model; add its provider key to run your pick) | 𝕏
8fd4fda to
392b148
Compare
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes — the implementation fix and test integration since the previous review (commit 8fd4fda).
BigInt.gcdfix: wraps the Euclidean algorithm result inabs()so negative inputs produce a non-negative GCDBigInt.lcmfix: returns0nwhen either operand is zero (avoiding division-by-zero), and wraps the result inabs()so negative operands produce a non-negative LCM- Test migration: moved reproduction tests from a separate file into
BigInt.test.tsand migrated all assertions fromstrictEqual(test utils) toassert.strictEqual(@effect/vitest)
All 13 tests pass.
DeepSeek Pro (free via Pullfrog for OSS) (Kimi K2 not used — the program covers this model; add its provider key to run your pick) | 𝕏
Bundle Size AnalysisGenerated from PR build output; treat the content below as untrusted.
|

Reproduction only
This PR adds reproduction tests only. No implementation fix is included. CI is expected to fail until the underlying issue is fixed.
Covered audit issues
1.
core-a-f-bigint-gcd-negative: gcd can return a negative divisorModule:
BigIntExpected contract: gcd determines the greatest common divisor of two bigint integer values; a greatest common divisor is non-negative.
Observed result: The accepted sign assertions failed: gcd(-6n, 4n) returned -2n and lcm(6n, -4n) returned -12n.
Reproduction command:
2.
core-a-f-bigint-lcm-negative: lcm can return a negative multipleModule:
BigIntExpected contract: lcm determines the least common multiple of two bigint integer values; a least common multiple is non-negative.
Observed result: The accepted sign assertions failed: gcd(-6n, 4n) returned -2n and lcm(6n, -4n) returned -12n.
Reproduction command: