Repository navigation
Description
Summary
Fix default float display so ordinary values such as 3.14 and 10.0 render as numbers, not inf. This is a shipped user-visible correctness bug in the sole formatting mechanism of the language. The right fix is to replace the ad hoc float formatter with a correct deterministic conversion routine, not to patch individual thresholds.
Spec
§15.4 makes f-strings the only formatting mechanism and says f-strings return owned str (docs/with-specification.md:7611-7624). §15.4.2 defines float modes: f fixed-point, e scientific, and g general/shortest with g as the default (docs/with-specification.md:7676-7689). §15.4.4 requires default no-spec float formatting to use general format and gives f"{3.14}" == "3.14" (docs/with-specification.md:7730-7743). §15.4.7 says debug mode for floats matches default display (docs/with-specification.md:7766-7774).
Current state
- Original issue verification: installed and stage2 binaries print
f"{3.14}" -> infandf"{10.0}" -> inf;1.5,0.5, and0.001happened to render correctly. src/CodegenDispatch.w:2238-2241routes default float formatting to the runtimewith_fmt_f64.rt/rt_core.w:64-134implementsrt_f64_to_buf, a hand-written "shortest" formatter. Its infinity detection usesif val > 1.7e308/< -1.7e308(rt/rt_core.w:72-84) rather than bit-level IEEE checks, then casts the integer part throughu64(rt/rt_core.w:97) and formats only six fractional digits (rt/rt_core.w:106-134).rt/rt_core.w:137-185implements fixed precision separately and lacks negative/positive infinity handling.rt/rt_core.w:1091-1130implementswith_fmt_f64_spec; f-string float modes: :e scientific and bare :f (§15.4.4) #440 tracks that it discards the mode and shares the same formatter substrate.test/behavior/behav_fstring_float_spec.w:5-24covers precision specs but not default no-spec float display. No test pins3.14,10.0, extremes, NaN/inf, or debug-float behavior.
Implementation plan
- Replace the hand-rolled
rt_f64_to_bufandrt_f64_to_fixed_buflogic with a deterministic Ryū d2s-style implementation inrt/rt_core.w. Use the shortest-roundtripgpath for default display and debug-float display. - Implement bit-level classification helpers for
NaN, positive/negative infinity, positive/negative zero, and finite values. Do not use numeric threshold comparisons for infinity. - Make
with_fmt_f64andwith_fmt_f64_specshare the same conversion core so Bug: default float display prints 'inf' for most values (§15.4) #438 and f-string float modes: :e scientific and bare :f (§15.4.4) #440 cannot diverge again. - Preserve existing width, sign, and padding behavior around the produced numeric string, but apply it after correct float conversion.
- Add explicit handling for
-0.0. Pick and document the spec-compatible spelling (-0or-0.0) before tests; preserve the sign if the conversion routine exposes it. - Runtime changes are seed-sensitive. Do this as a runtime-only logical change and run
with build,with build :fixpoint, andwith build :testbefore any seed/install target.
Test plan
- Add
test/behavior/behav_fstring_float_default.w:f"{3.14}" == "3.14"f"{10.0}"is numeric ("10"or the chosen general-format spelling), never"inf"f"{1.5}" == "1.5",f"{0.5}" == "0.5",f"{0.001}" == "0.001"f"{1e308}"andf"{1e-308}"do not misclassify as infinity or zerof"{0.0}"andf"{-0.0}"follow the chosen signed-zero rule
- Add NaN and +/-inf coverage using constants or operations the language can express reliably.
- Add debug-float coverage:
f"{3.14:?}"matches default float output per §15.4.7. - Add round-trip property-style coverage if the test harness can generate a fixed corpus of bit patterns: parse(format(x)) should recover x for finite values where parsing exists.
Acceptance criteria
- Default no-spec float formatting never prints
inffor finite values - Default float formatting uses general/shortest semantics consistent with §15.4.4
- Debug float formatting matches default float display
- NaN, +/-inf, +/-0, small, large, and ordinary decimal values are covered
- The implementation is deterministic and libc-independent
-
with build && with build :fixpoint && with build :testpass
Dependencies
Overlaps #440; both should be fixed by the same formatter rewrite. Blocks #503 coverage from becoming meaningful for float modes.
Traceability
From the requirements campaign (docs/requirements.md, spec v7.1). Affected requirement IDs: 15.4.2.8, 15.4.4.1, 15.4.7.4.
Activity
Requirements triage campaign: checkbox, verdict, and issue-link every…
ehartford commentedon Jun 12, 2026
Implemented in f589534. Runtime f64 formatting now classifies NaN/inf/signed zero from IEEE-754 bits instead of numeric thresholds, formats finite default-display values through the deterministic decimal path, and extends runtime float parsing to exponent literals so large/small finite values are tested correctly. Added behavior coverage for ordinary decimals, debug-display parity, 1e308, 1e-308, signed zero, and NaN/+/-inf. Verification passed: with build, with build :fixpoint, with build :test, and with build :test-green using the project seed path.