Skip to content

dtostrf/Print(float) inconsistent value/methods, downstream use #7073

Closed
@earlephilhower

Description

@earlephilhower

#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:

  1. 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.
  2. 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)
  3. 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.
  4. 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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions