Wednesday, 11 September 2013

printf cannot print float/double correctly on the screen

printf cannot print float/double correctly on the screen

Recently, I'm working with a special embedded operating system running on
mips architecture. I do not know much about it.when I use the printf
function, see some strange things:
int a = 10;
float b = 3.14;
double c = 3.14;
printf("a is %d\n"); // print correct number a
printf("b is %f\n"); // print error
printf("c is %f\n"); // print error
the output is :
a is 10
b is 0.000000
a is right,but b seems to be wrong, c even can not be printed. Function
printf comes from newlib(a C language lib). Be careful, The float/double
numbers can be calculated correctly, stored correctly in the memory, they
just can not be printed correctly.
I think there maybe something wrong with the operating system. I just
wonder what could be the reason. Is there anyone who has met this problem
before? Please give me some advice. Thanks in advance.

No comments:

Post a Comment