Feature request: treat double as float

Bug #1732683 reported by john on 2017-11-16
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
GNU ARM Embedded Toolchain
Undecided
Unassigned

Bug Description

Omitting double precision floating point code when it's not really needed could save precious memory on small targets. Unfortunately, double precision code gets pulled in when using sprintf. Besides, float is automatically converted to double when passed to sprintf, so execution speed suffers as well.
A compiler option to treat double as float would solve this. Besides, the standard library compiled with this option would have to be shipped.

Developing such a feature would take a big effort and a long time. As you said the compiler needs to be changed and so does the C library. All the ramifications need to be considered. One needs to consider how many people would benefit. Newlib-nano already has a mechanism to have floating point support in printf and scanf optional which provides better reward (more code saved) for less work (change in compiler is only a nice to have to automate the selection of float code).

All in all, I don't believe we can justify working on this for the time being.

Best regards.

Hi John,

A colleague of mine remarked that the following option would be of some help to you: -fsingle-precision-constant -Wdouble-promotion.

Hope this helps.

Best regards.

john (jkovach) wrote :

Since all of this mostly concerns printf, one way to address this would be to add another version of printf formatter to newlib-nano. Basically, to split _printf_float into _printf_double and _printf_float. _printf_float would use single precision floating point instead of double precision. Something similar could be done with scanf.

To post a comment you must log in.
This report contains Public information  Edit
Everyone can see this information.

Other bug subscribers