MCPcopy Create free account
hub / github.com/Effect-TS/effect / add32

Function add32

packages/effect/src/Random.ts:538–551  ·  view source on GitHub ↗

* 32-bit addition with overflow handling (JavaScript numbers are 53-bit). * * Example: add32(0xFFFFFFFF, 0x00000001) = 0x00000000 (wraps around)

(x: number, y: number)

Source from the content-addressed store, hash-verified

536 * Example: add32(0xFFFFFFFF, 0x00000001) = 0x00000000 (wraps around)
537 */
538function add32(x: number, y: number): number {
539 // Add lower 16 bits separately to handle carry
540 // Example: x=0x12345678, y=0xABCDEF01
541 // lsb = (0x5678 + 0xEF01) = 0x14579
542 const lsb = (x & 0xffff) + (y & 0xffff)
543
544 // Add upper 16 bits + carry from lower addition
545 // msb = (0x1234 + 0xABCD + (0x14579 >>> 16)) = (0x1234 + 0xABCD + 0x1) = 0xBE02
546 const msb = (x >>> 16) + (y >>> 16) + (lsb >>> 16)
547
548 // Combine: upper 16 bits | lower 16 bits (masked to prevent double carry)
549 // return (0xBE02 << 16) | (0x14579 & 0xffff) = 0xBE024579
550 return (msb << 16) | (lsb & 0xffff)
551}
552
553const seedEncoder = new TextEncoder()
554

Callers 3

mixFunction · 0.85
seedFunction · 0.85
pnrgFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected