Skip to content

multiplyUnsigned hangs for multiplier >= 2^31 (>>= sign-extends) #2232

Open

Description

@devladpopov
multiplyUnsigned(1, 0xFFFFFFFF);  // never returns
multiplyUnsigned(0, 2 ** 31);     // never returns

src/algorithms/math/bits/multiplyUnsigned.js:39 uses multiplier >>= 1. Bitwise ops treat the value as signed 32-bit, so once the top bit is set the arithmetic shift keeps it, and multiplier gets stuck at -1. The function is documented as unsigned multiplication. Fix: multiplier >>>= 1.


Found during an independent property-based audit of this repo (full report and reproducible harness: https://github.com/devladpopov/algorithm-autopsy/tree/main/autopsy-02).

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions