I'm using the the "case 60 printf" demo from Coridium sample file Csample.c dated 2/7/2013 as my test case.
USE_FLOAT is defined in the code. i is integer, x is float.
I changed %d to %f or 1.3f in a couple of places, and replaced i with x.
Here's the changed section
Code: Select all
#ifdef USE_FLOAT
case 60:
x =1.23456*1000;
i = x * 1000;
//printf("1.234*1000 %d\n",i);
printf("1.234*1000 is: %f\n",x);
printf("1.234*1000 is: %1.3f\n",x);
i = 100*sinf(00.01);
printf("sin %d\n",i);
i = 100*cosf(00.01);
printf("cos %d\n",i);
//i = 100*sqrtf(1000);
x = sqrtf(1000);
printf("sqrt of 1000 is: %f\n",x);
i = 100*log10f(2000);
printf("log10 %d\n",i);
printf("pi = %d\n",i);
// how to do printf with floats
printf("%d.%03d",(int) floor(x), (int) (1000* (x-floor(x))));
break;
#endif
enter option:1.234*1000 is:
1.234*1000 is: 3f
sin 0
cos 99
sqrt of 1000 is:
log10 330
pi = 330
31.622
The last couple of lines of sample code would suggest that printf doesn't handle floats, but Coridium says it does.