Repository navigation
state_exec: state-set stores a float in its shortest round-trip form - #885
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 red
So a re-run would fail the same way until #886 is on master. I'll re-run this job then. #889 (stacked on this) will hit the same failure. |
|
#886 is on master now (a872192). I merged master into this branch (8c2da63) instead of re-running the job. A re-run keeps the original run's commit, and the macOS jobs checked out |
|
The new run (merge |
…ts in full #885 made state-set write a float in its shortest round-trip form, as state-set-tree already did, so the comment, the developer guide and a test note no longer call that a difference.
state-setwrote a float with six significant digits, so a balance or a price lost digits:(state-set "x" 1234567.5)stored"1.23457e+06", and(+ 0.1 0.2)stored"0.3", which readsback as a different number.
state-incrand #883'sstate-set-treealready write the shortesttext that reads back as the same double;
state-setnow does too. This came up while building#883 and was left out of it because it changes existing output.
Change
coerce_state_string(src/cvc/state/state_exec/intrinsics.cpp) formats a double withformat_number_shortest(std::to_chars, ordetail::format_number_shortest_fallbackwherethe library has no floating-point
to_chars) instead of a defaultstd::ostringstream.format_number_shortestmoves above it;<sstream>is no longer used there.state-set(scalars), andstate-cas/state-swapthroughatomic_scalar.All three now store the same text
state-incrdoes.1234567.51.23457e+061234567.5(+ 0.1 0.2)0.30.300000000000000040.10.10.11e211e+211e+21100000.01000001e+05The last row changes for the worse to the eye:
to_charswrites the shorter of the fixed andscientific forms. The text still reads back as the same number,
state-incralready writes itthis way, and
state_exec_locks_testpins1e5 -> "1e+05"for the formatter. Whole floats below 1e5, and those with moresignificant digits (
120000.0->"120000"), are unchanged.Not affected
slider_floatwrites throughcvc::state::value<double>(bind.h'swrite<T>, boost::lexical_cast), notcoerce_state_string, andfmt:formats only theslider's display. No other widget or
.aricomponent writes floats through it.strand a list or dict's printed form still write six digits (to_stringindata_job.cpp). So(state-set "x" (str 1234567.5))still stores"1.23457e+06"; the guidenow says to pass the number itself. Changing
to_stringwould move many print goldens, so it isleft for its own PR.
Docs
docs/STATE_EXEC_DEVELOPER_GUIDE.md:state-setturns a value into text, with the examples above.(state-children "myapp.config") ;; => ("timeout")was wrong:state-childrenreturnsevery descendant, in pre-order, by full path (
state::children()). The example now shows("myapp.config.timeout")and a nested("myapp.users.ann" "myapp.users.ann.role").state-setconverts withstr.Tests
StateTreeIntrinsicsTest.StateSetStoresAFloatInItsShortestRoundTripForm:1234567.5,0.1,1e21,-2.5,1e5,0.1 + 0.2;strtodof the stored text equals the value for0.1 + 0.2,1/3,6.02214076e23,5e-324,123456789.123;state-swapstores the same.StateTreeIntrinsicsTest.StateChildrenListsEveryDescendantByFullPathpins the guide's example.ImageMagick, HDF5, CGAL and mesher off): every
state_exec_*_testandariadne_*_testbinarypasses (34 binaries, intrinsics 158/158). No existing test pinned the six-digit text.
git clang-format(18.1.3): no changes.