sprintf bugs with floating point and field specifiers?
Matt Lee
reachmatt.lee@gmail.com
Wed Sep 6 18:09:00 GMT 2006
Hi,
I am seeing some bugs with Newlib sprintf and floating point format
specifiers. Specifically, the following bits of code work incorrectly,
<snip>
char chTest[200];
int main ()
{
sprintf(chTest, "%+05.1f", 0.03f); // "+00" --> wrong
printf("%s\n\r", chTest);
sprintf(chTest, "%05.0f", 0.03f); // "0000" --> wrong
printf("%s\n\r", chTest);
sprintf(chTest, "%+05.0f", 0.03f); // "+000" --> wrong
printf("%s\n\r", chTest);
}
</snip>
Output On Xilinx PowerPC 405 platform,
+00
0000
+000
while on desktop Linux I get,
+00.0
00000
+0000
I have tried both Newlib 1.9.0 and 1.14.0 and see the same behavior. I
am running a powerpc-eabi toolchain with Newlib configured for
floating point support.
I found a few email trails, that seem to discuss related issues but
were not really the same things? I will try to debug _dtoa_r() and
cvt(), but wanted to know if this is known behavior.
thanks,
Matt.
More information about the Newlib
mailing list