Skip to content

Fix InfixFormatter coefficient precision loss on model output - #176

Merged
foolnotion merged 2 commits into
mainfrom
fix/infix-formatter-coefficient-precision
Aug 20, 2026
Merged

Fix InfixFormatter coefficient precision loss on model output#176
foolnotion merged 2 commits into
mainfrom
fix/infix-formatter-coefficient-precision

Conversation

@foolnotion

@foolnotion foolnotion commented Aug 19, 2026

Copy link
Copy Markdown
Member

Summary

The InfixFormatter class printed coefficients at a fixed 6-decimal precision ({:.6f}), which silently rounds any coefficient below roughly 5e-7 to 0.000000. A caller that re-parses the printed model text gets a different model back: a tiny, load-bearing coefficient (for example in a divisor) becomes a literal zero.

Fix: switch coefficient formatting from fixed-point to general (%g-style) notation, and standardize every call site on std::numeric_limits<Operon::Scalar>::max_digits10, the minimum digit count that round-trips a float exactly. This replaces a mix of hardcoded 6, digits10 (insufficient for round-trip), and digits (correct but needlessly verbose) across operon_gp.cpp, operon_nsgp.cpp, operon_enum.cpp, pareto_front.cpp, operon_parse_model.cpp, and custom_primitives.cpp.

Test plan

  • All parser/formatter tests pass, including the 100k-tree roundtrip test.
  • Full suite otherwise unaffected, aside from one pre-existing failure unrelated to this change.
  • Manually confirmed: a coefficient that previously printed as -0.000000 now prints as -0.000000761; re-parsing the corrected text produces finite predictions instead of an all-non-finite error.

Fixed-point {:.6f} silently rounded coefficients below ~5e-7 to
0.000000, producing genuine division-by-zero when independent tooling
re-parses the printed model. Switch to general/%g-style formatting at
max_digits10 (round-trip-exact); found via 0.17% of the already-published
production matrix reporting "feasible" for numerically non-finite models.
…branches were still fixed-point, missed in the initial pass; also fix the two remaining hardcoded-6 call sites.
@foolnotion
foolnotion merged commit cf706ac into main Aug 20, 2026
3 checks passed
@foolnotion
foolnotion deleted the fix/infix-formatter-coefficient-precision branch August 20, 2026 08:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant