@maruaudio/dsp/math/integer provides multiplyInt32(a, b), the signed low 32 bits of an integer product, equal to Math.imul(a, b). Maru compiler's Processor subset does not admit Math.imul, so the DSP node splits each operand into 16-bit halves; every partial product stays exactly representable in a double, and the result is folded back to a signed word with | 0.
import { multiplyInt32 } from "@maruaudio/dsp/math/integer"
multiplyInt32(0x9e3779b9, 0x85ebca6b) === Math.imul(0x9e3779b9, 0x85ebca6b) // trueFunctions
| Name | Inputs | Output | Domain as coded |
|---|---|---|---|
multiplyInt32 | a, b | signed 32-bit integer | Operands are read as 32-bit words (>>> 16, & 0xffff), so signed and unsigned words give the same result |
Lifecycle
None. A stateless function with no preparation or instance state.
When to use it
Integer hashing, linear congruential generators and other word arithmetic in code that must compile through Maru compiler as well as run in JavaScript. It is the multiply behind @maru/math-hash.
Limits
- Only the low 32 bits are returned; the high word of the product is discarded, as with
Math.imul. - Fractional or non-finite operands are converted by the bitwise operators (truncation, NaN to 0), not rejected.