Feature request: treat double as float

Bug #1732683 reported by john
8
This bug affects 1 person
Affects Status Importance Assigned to Milestone
GNU Arm Embedded Toolchain
New
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.

Revision history for this message
Thomas Preud'homme (thomas-preudhomme) wrote :

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.

Revision history for this message
Thomas Preud'homme (thomas-preudhomme) wrote :

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.

Revision history for this message
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  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.