ADR-0018: Log axis positions from a fixed-point logarithm of the written decimal
- Status: Proposed
- Date: 2026-12-01
Context
Section titled “Context”A chart’s log axis (chart.md) places each value at log10 of the value. Three requirements constrain how that logarithm is computed:
- Byte-identical output. Native and WASM renders of one spec must produce the same bytes (architecture.md). A position that differs in its last binary64 bit can print a different coordinate when it falls on a rounding boundary of the two-decimal SVG output.
- No dependencies. The core is
no_stdwith zero runtime dependencies (ADR-0002).corehas nof64::log10orf64::ln: those arestdmethods that call the platform’s libm, andwasm32-unknown-unknownhas no logarithm instruction. math.rs already implementssqrt,hypotandsin_cos_degin software for this reason. - Exact powers of ten. A tick at 1,000 and a value written
1000or1e3must share one position, and a tick at 10^k must sit exactly(k − e0) / (e1 − e0)along a plot from 10^e0 to 10^e1.0.001has no exact binary64 value, so a logarithm of the binary64 value cannot give exactly −3.
Decision
Section titled “Decision”A log position is computed from the value’s text as written, in integer arithmetic, and rounded once to binary64:
- The written decimal is split into its decade,
floor(log10), which is an exact integer, and its first 19 significant digits, au64from 10^18 to 10^19 − 1. log10of the significand comes frommath::log10_q64: the binary logarithm of the 64-bit mantissa by repeated squaring inu128, one bit per square, then scaled bylog10(2)held as a 64-bit fraction. The result counts in units of 2^-64 decade and is within 2^-59 decade of the exact value.- The fraction within the decade is measured from
log10_q64(10^18)and kept below one decade, so a power of ten has fraction 0 and a position never decreases as the value grows. - The decade times 2^64 plus the fraction is converted to binary64 decades by one correctly rounded
i128tof64conversion and an exact division by 2^64. - Ticks take their positions from the same function on their integer significand (1, 2 or 5) and exponent, and their labels from the same integers.
Options considered
Section titled “Options considered”| Option | Buys | Costs |
|---|---|---|
f64::log10 from std |
One call; within 1 ulp on common platforms | Not available in the no_std core. Results come from each platform’s libm, which may differ in the last bit between the native build and the WASM build’s compiled-in libm. log10(0.001) is the logarithm of a binary64 value near 0.001, so a tick and a value written as the same power can differ |
A port of a libm log10 (fdlibm, musl) in binary64 arithmetic |
Within 1 ulp; about 20 floating-point operations per value; deterministic because IEEE 754 arithmetic is | About 100 lines of reduction steps and polynomial coefficients to maintain. Monotone in practice but not by construction. Still the logarithm of a binary64 value, so 0.001 does not give exactly −3 |
| A double-double series in binary64 | About 106 bits of precision, enough to make the rounded result monotone | Dekker splitting, double-double division and a series; more code than integer arithmetic for the same guarantees. Still needs the decade split to make powers of ten exact |
| Fixed point on the written decimal | Integer operations only, identical on every target. Powers of ten exact by construction. Never decreases as the value grows, by construction. About 60 lines | Accuracy is absolute (2^-59 decade), not relative to the result. 64 u128 multiplications per value. Digits past the 19th are truncated |
Criteria
Section titled “Criteria”Byte-identical output across targets, exact positions for powers of ten, positions that never decrease, the zero-dependency rule, and the size of the code to maintain. The first two decided it: std fails both, and every binary64 logarithm fails the second unless it also splits off the decimal exponent, at which point the integer method is shorter.
Consequences
Section titled “Consequences”- Easier: tests compare tick positions with exact equality; a value written as a power of ten sits on its grid line to the last bit; WASM and native renders of a log chart share one digest.
- Harder: the position depends on the written text, so a layout reads each log value’s text again after resolving it. A 10,000-point line renders in 44 ms on a log axis against 26 ms on a linear one (release CLI, one machine, median of 15 runs).
math::log10_q64is the only logarithm in the core; another feature that needslnorlog2of a binary64 value builds on it or adds its own. - Expensive to reverse: every log chart’s bytes. Another method changes the last bits of positions and so the recorded digests.
- Unmeasured: the cost on the WASM build, and on charts with several log marks.