Description
#7068 removed two slightly different (and both slightly wrong) implementations of double
to ASCII string
in Print::print(float)
and dtostrf
(a non-std. AVR C addition AFAICT) and replaced it with a call to newlib's sprintf(%f)
which is known good.
Unfortunately, as @mcspr noted, there are folks who are building the core w/o float-printf support (printf_float
in platform.txt), so the above PR will end up borking their output.
Might need to be labelled as breaking? See
https://github.com/arendst/Tasmota/blob/1598e6227a31be5f27081c5a660d22d21613c0ca/platformio.ini#L83
https://github.com/arendst/Tasmota/blob/development/pio/strip-floats.py
https://github.com/xoseperez/espurna/blob/dev/code/scripts/espurna_utils/float_support.py
The main question now is what is the right thing to do in this case. I suggest it's one of the following:
- Revert to duplicated code and inconsistent output diffs between Print() and dtostrf() in corner cases. (i.e. undo Use sprintf to output floats in Print/dtostrf #7068). Larger code for most people (3 different versions of float->ascii in ROM), but downstream keeps working.
- Keep sprintf(%f) and disallow disabling printf_float, requiring changes in downstream projects (ROM will go up ~1K for them, but down ~1KB for most users since the 2 dup'd versions will be expunged)
- Pick method from Print(float) and replicate it in dtostrf() so they match. Then replace Print(float) with a call to dtostrf(). Smaller ROM for all, both match, but may not match the correct output in some cases.
- Same as 3, but use the dtostrf() as golden and not Print()s version.
FWIW, looking at the AVC-LIBC implementation, it is closest in logic to number 2 above. They go down to the binary FP level and extract exponents and mantissas (as the AVR ASM level) and work with those parts to actually generate strings.
Any opinions from downstream?