CPython's float Implementation in C: A double and a Freelist
A float is 24 bytes holding one IEEE-754 double. Arithmetic converts both sides to double and boxes the result, and repr always uses 17 significant digits with a trailing .0.
All posts published on this site.
Everything published here, newest first.
A float is 24 bytes holding one IEEE-754 double. Arithmetic converts both sides to double and boxes the result, and repr always uses 17 significant digits with a trailing .0.
A CPython frame is really two structs: the compact _PyInterpreterFrame the VM runs on, and the heap PyFrameObject Python code only ever sees — created lazily, and copied if it …
A Python function is a PyFunctionObject — a shared code object bolted to a globals dict, a tuple of defaults, and a tuple of closure cells — and every call goes through vectorcall.
Generators, coroutines, and async generators share one struct: an _PyInterpreterFrame embedded directly in the object, so a paused function is a single heap allocation.
int is a PyObject with a tag word packing sign and digit count plus a little-endian array of 30-bit digits — and every value in -5..1024 is an immortal singleton.