Skip to main content

logicaffeine_data/
fmt.rs

1//! The ONE float-display path.
2//!
3//! Every engine that renders a LOGOS `Float` — the tree-walker, the bytecode
4//! VM, the AOT-compiled binary, and the direct-WASM host — must agree on the
5//! decimal string for the same `f64`, or the same program prints different
6//! answers depending on how it was run. This module is the single authority.
7//!
8//! The contract of [`fmt_f64`]:
9//!
10//! - **Shortest round-trip**: the fewest decimal digits that parse back to the
11//!   exact same bits (Rust's `{}` Display, Grisu/Dragon in std). A typed
12//!   literal echoes as typed; `1.0 / 3.0` shows all 17 significant digits.
13//! - **Never scientific notation**: `0.0000001` renders as `0.0000001`, not
14//!   `1e-7` — and a nonzero value NEVER renders as `0`.
15//! - **Integral floats stay bare**: `2.0` renders as `2`.
16//! - **Bounded width**: the longest possible output (the smallest subnormal,
17//!   `5e-324`) is under 340 bytes — the direct-WASM host's scratch size.
18
19/// Renders an `f64` exactly as LOGOS displays it on every engine.
20pub fn fmt_f64(f: f64) -> String {
21    format!("{f}")
22}
23
24#[cfg(test)]
25#[path = "../../logicaffeine_tests/unit/logicaffeine_data/fmt/tests.rs"]
26mod tests;