How can I print (i.e. stdout) a float in C without if it will be passed to double when passed to printf?
The problem here is that variable functions in C allow all float parameters to double, which leads to two unnecessary conversions. For example, if you enable -Wdouble-promotion in GCC and compile
float f = 0.f; printf("%f", f);
You'll get
warning: implicit conversion from 'float' to 'double' when passing argument to function
I have relatively little processing power to play with (ARM Cortex-M3 at 72 MHz), and I definitely have a bottleneck in the output of ASCII floating point data. Since the architecture lacks a hardware FPU to begin with, converting between single and double precision does not help.
Is there a way to print float in direct C more efficiently?
Xo wang
source share