Repository navigation
state_exec: to_string prints a float in its shortest round-trip form - #889
Merged
Merged
Conversation
coerce_state_string formatted a double with a default ostringstream, so state-set (and state-cas / state-swap, which share it) kept six significant digits: (state-set "x" 1234567.5) stored "1.23457e+06", and 0.1 + 0.2 stored "0.3", which reads back as a different number. It now uses format_number_shortest, as state-incr already does: "1234567.5", "0.30000000000000004", "0.1", "1e+21". Of the fixed and scientific texts the shorter is written, so 100000.0 is now "1e+05" (it was "100000"). The Ariadne widgets are unaffected: slider_float writes through cvc::state::value<double> (lexical_cast), and fmt: formats only its display. str and list printing still write six digits (to_string in data_job.cpp). STATE_EXEC_DEVELOPER_GUIDE.md section 5 now says how state-set turns a value into text, and its state-children example shows what state-children returns: every descendant, in pre-order, by full path. A test pins that example.
The print walker (data_job.cpp) wrote a double with a default ostringstream, so str, str-concat, print, an Ariadne computed label and a list's printed form kept six significant digits: (str 1234567.5) was "1.23457e+06". It now calls format_number_shortest, the text state-set and state-incr store, so (state-set k (str d)) and (state-set k d) store the same thing. format_number_shortest moves out of intrinsics.cpp's anonymous namespace and is declared in types.h, beside to_string. A whole float still prints as an integer's digits (2.0 as "2"), as before and as state-set stores it; printing it as "2.0" so it reads back as a float belongs with the rest of grammar phase P5's round trip (string escaping, +inf.0). Non-whole floats now print up to 17 digits: (/ 1.0 3) is "0.3333333333333333", where it was "0.333333". Docs: the developer guide's note that str prints six digits goes; the locks doc no longer says coerce_state_string writes 6 digits (stale since the state-set change); the grammar doc says what to_string prints now and what P5 still has to do; the CLI guide shows (/ 355 113.0)'s full text.
transfix
enabled auto-merge (squash)
October 30, 2026 05:48
…est-float # Conflicts: # docs/STATE_EXEC_DEVELOPER_GUIDE.md # src/cvc/tests/state_exec_intrinsics_test.cpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Stacked on #885. This branch holds #885's commit (5ebe185) and one of its own (9fe3518);
review 9fe3518. Merge #885 first; I'll rebase this onto master then. It targets master because
CI runs only on PRs into master.
str,str-concat,print, an Ariadne computed label and a list's printed form wrote a floatwith six significant digits:
(str 1234567.5)was"1.23457e+06", and a float inside a listlost digits the same way. After #885,
state-setstores"1234567.5", so(state-set k (str d))and
(state-set k d)stored different text. Now they store the same text.Change
doublebranch (src/cvc/state/state_exec/data_job.cpp) callsformat_number_shortestinstead of a defaultstd::ostringstream.format_number_shortestmoves out of intrinsics.cpp's anonymous namespace and is declared intypes.h, beside
to_string. Its definition (std::to_chars, ordetail::format_number_shortest_fallbackwhere the library has no floating to_chars) staysin intrinsics.cpp.
(str 1234567.5)1.23457e+061234567.5(str (+ 0.1 0.2))0.30.30000000000000004(str (/ 1.0 3))0.3333330.3333333333333333(str (list 1234567.5))(1.23457e+06)(1234567.5)(str 2.0)22(str 100000.0)1000001e+05(str 0.1),(str 1e21)0.1,1e+21A whole float prints as
2, not2.0I kept the current form, for three reasons:
strthen writes exactly whatstate-setandstate-incrstore, so the two ways of writing anumber to the tree agree byte for byte.
display_string->to_string) keep showing3for(* 1.5 2).Only non-whole floats change, and only by gaining the digits they had lost.
2.0is there so a whole float reads back as a float, which is the parse(to_string(v)) == vgoal of the grammar's phase P5. That goal also needs string escaping and
+inf.0. Doing onepiece of it here would change the printed form twice.
Visible changes to watch
(/ 1.0 3)shows0.3333333333333333. Usemath.roundto show fewer.100000.0prints1e+05.Docs
strprints six digits.coerce_state_stringwrites 6 digits. That went stale withstate_exec: state-set stores a float in its shortest round-trip form #885.
to_stringprints now and what P5 still has to do.(/ 355 113.0)shows3.1415929203539825.Tests
BuiltinsTest.StrWritesAFloatInItsShortestRoundTripForm:(str 1234567.5),(str (+ 0.1 0.2)),0.1,1e21,2.0->"2",-0.0->"-0", a list's floats,str-concatwith a float;strtodof the printed text equals the value for five more.StateTreeIntrinsicsTest.StateSetStoresAFloatInItsShortestRoundTripFormalso checks thatstrandstate-setwrite the same text.ImageMagick, HDF5, CGAL and mesher off): all 35
state_exec_*andariadne_*binaries pass.So do async_lane_test, stream_test, tf_overlay_tasks_test, app_test and thread_pool_test, the
other tests that run the DSL.
"78.", and3.14159 * 25 prints
78.53975either way. cvcGL tests (CVCGL off): their float strings arenode values, not printed DSL floats.
git clang-format(18.1.3) applied.