Master the fundamental concepts of cpython internals through this focused micro-challenge.
Python integers are not fixed-width C `long` values. CPython stores them as `PyLongObject` with a digit array in base 2^30, defined in `longobject.c` and `longintrepr.h`.
Each limb is a `digit` (typically `uint32`) but only 30 bits are used so multiplication of two digits never overflows a 64-bit intermediate. A number like 2^60 splits into limbs `[0, 1]` because 2^60 = 1 * 2^30 + 0.
CPython also caches integers from -5 to 256:
For example, 1234567890123 requires multiple 30-bit limbs when stored in little-endian order.
```c typedef struct { PyObject_HEAD ssize_t ob_size; digit ob_digit[1]; } PyLongObject; ```
Arbitrary precision is not free: every large integer operation allocates and may carry across limbs. Profile hot loops that accidentally promote small ints to big ints when values exceed the machine word.
This exercise asks you to model `PyLongObject` layout in C. You will implement limb splitting for a 64-bit input and document the small-integer cache range that explains Python's identity quirks.
Write a C program documenting Python integer internals.
Requirements:
Three hints are available for this task, revealed one at a time inside the code workspace so you can struggle productively before seeing them.
All starter code and reference implementations are available for your local setup.
View on Github