This site is version 0.0.1. Most of the code on this site is drafted by an agent and needs review. I apologize for the AI-speak, we are working on rewriting it!
viv-lang.org

Notebooks · lib/nprandom/bits

Unsigned 32- and 64-bit arithmetic on doubles, for NumPy's generators

This module computes in doubles, which hold an integer exactly up to 2^53. NumPy's generators compute with unsigned 32-, 64- and 128-bit integers that wrap around on overflow. This module holds the pieces that keep that arithmetic exact:

  • a 32-bit word is a double in [0, 2^32); band, bor, bxor, shl, shr are Viv builtins that read and return such words;
  • npr_mul32(a, b) is a * b mod 2^32, computed from 16-bit halves so no product passes 2^48;
  • a 64-bit number is an Int, its unsigned arithmetic the builtins wrap_add, wrap_mul, umulhi and ult; a 128-bit one is two Ints.

Used by the other files of lib/nprandom.

Look inside this program

  • Atlas

    The program’s map: every function and which calls which.

  • There’s no recorded run of this program yet.

Shift+Enter in a cell runs it and moves to the next. Running a cell runs every cell above it too, as one program.

[1]lines 19–65