Cosmic Zoom
Big Numbers
A number growing from one to a quintillion — nanometres to the cosmos — swept across a
logarithmic ruler on a Super
Nintendo. The scale is a 64-bit integer, and placing it on the ruler means converting it to a
floating-point number: (float)scale. That 64-bit-integer-to-float conversion — and
the trip back — is the point. Exponential growth becomes a steady linear sweep. Runs on its own;
no joypad needed. Written in C and compiled with the
llvm-mos-based 65816 toolchain
(+mos-a16, 16-bit accumulator mode).
Self-running demo — the bar sweeps as the scale climbs the powers of ten.
Click the screen to focus, then watch. Tab away and it pauses.
What it is
Computers store whole numbers and floating-point numbers very differently, and converting between them is real work — a routine, not a single instruction, especially for 64-bit integers on an 8/16-bit CPU:
uint64_t scale = ...; // grows through the powers of ten float f = (float)scale; // __floatundisf : 64-bit int -> float position = log_ruler(f); // place it on a log scale uint64_t back = (uint64_t)f; // __fixunssfdi : float -> 64-bit int
The ruler is logarithmic, so each power of ten is an equal step and the exponentially-growing scale slides across at a constant pace. The conversion to float is exactly how its position is found. It stays bit-exact across every codegen mode.
Compiler stress-test
| Item | What it exercises |
|---|---|
| 64-bit int to float | Turning a 64-bit integer into a floating-point number is a library routine (__floatundisf); turning it back is another (__fixunssfdi). Two earlier float demos only ever converted 32-bit integers — the 64-bit versions are a separate set of routines exercised here for the first time. |
| correctly rounded | These conversions are required by the IEEE standard to round to the nearest representable value, so the host and the console must agree to the bit. That makes them a sharp differential test. |
| log ruler | A scale growing by a fixed percentage each step is exponential; plotting its logarithm turns that into a steady linear sweep. Converting the 64-bit scale to float is how the log position is computed. |
| no overflow | The scale is kept below 10^18 so that rounding it to float can never push it past the 64-bit range on the way back — which would be undefined behaviour. A small discipline that keeps the round-trip well-defined. |
Written in C with the llvm-mos 65816 toolchain and verified against bsnes-jg
(and MAME where the SPC700 IPL is present). Hit Verify fidelity to reproduce the build
gate's WRAM assert (gate CRC 0x502F — a fold of ruler positions and 64-bit ⇄ float
round-trips over all eighteen decades) live in this tab. No far pointers — the same source passes
every way: host == default == +mos-a16 == +mos-xy16 == bsnes-jg,
-verify clean.