PROstart - MakeitC printf problem

Questions about the BASICtools and MakeItC
Post Reply
Pompey2
Posts: 16
Joined: Fri Oct 19, 2012 12:10 pm

PROstart - MakeitC printf problem

Post by Pompey2 »

I can't figure out how to get printf to print floats when using C on a PROstart. Basic has been overwritten
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	
Here's what I get:

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.



basicchip
Posts: 1090
Joined: Fri Oct 19, 2012 2:39 am
Location: Weeki Watchee, FL
Contact:

Re: PROstart - MakeitC printf problem

Post by basicchip »

USE_FLOAT has to be defined when printf is compiled as well

You can do that in MakeItC under the menu item User Compile options

-DUSE_FLOAT

From MakeItC you can find all instances of USE_FLOAT in the search window, which would show you that there is an #ifdef USE_FLOAT in printf.c

So printf does handle float, it is just not the default case. It could be made that way, just for most of the code we write floats are seldom used.

basicchip
Posts: 1090
Joined: Fri Oct 19, 2012 2:39 am
Location: Weeki Watchee, FL
Contact:

Re: PROstart - MakeitC printf problem

Post by basicchip »

A quick check enabling USE_FLOAT just for printf adds almost 3.9K to a C program even if floats are not used.

This is a big deal for the smaller parts, so integer handling will remain the default.

Post Reply