mpaland/printf

Floats : out of range

NotSqrt opened this issue · 4 comments

Hi,

What is missing exactly to support double numbers ?

I see the message in the tests :

printf/test/test_suite.cpp

Lines 1016 to 1017 in 21a282a

// out of range in the moment, need to be fixed by someone
test::sprintf(buffer, "%.1f", 1E20);

Maybe for the moment, a message can be added to the caveats in the README :

Double precision is not supported and will result in an empty string.

Thanks !

Is that due to this ?

printf/printf.c

Lines 322 to 326 in c235b5c

// TBD: for very large numbers switch back to native sprintf for exponentials. Anyone want to write code to replace this?
// Normal printf behavior is to print EVERY whole number digit which can be 100s of characters overflowing your buffers == bad
if (value > thres_max) {
return 0U;
}

This is the only missing feature I found compared to xprintfc (which is a bit smaller but not compliant with the standard, and not really tested).
They use this code to handle floats : https://github.com/MarioViara/xprintfc/blob/8f07c7c0d76370cdb44dbaee81f1f4201b1e7561/src/xformatc.c#L773
and their tests use printf("Floating > 32 bit %f",pow(2.0,32.0)+1.0);

I think, FP support is not completely and satisfying implemented by now. Exponential representation is missing, too.
I didn't support the double type in the fist way, just because it's not so common in embedded systems and you can always cast a float down to a double.

Have you seen this? https://github.com/ulfjack/ryu
It seems like it might still be experimental for C, but looks very promising...

This is closed by 4.0.0