CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

floating point

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
cerr



Joined: 10 Feb 2011
Posts: 241
Location: Vancouver, BC

View user's profile Send private message

floating point
PostPosted: Tue Mar 08, 2011 1:53 pm     Reply with quote

Hi There,

Why would this:
Code:

fprintf(DEBUG,"%f * %f = %f\r\n",(float)scldpotval1,(float)scaler,(float)scldpotval1*(float)scaler);

Give me something like
33776.00 * 1.48 = 50000.00
scldpotval1 and scaler, both are of type float
I don't understand

compiler 4.119, 18f87k22
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Mar 08, 2011 2:14 pm     Reply with quote

With no test program, it's tough to know exactly what you're doing.
But if I compile the following program with vs. 4.119 and run it in
MPLAB simulator, I get this:
Quote:
33776.00 * 1.48 = 49988.48

Code:

#include <18F87K22.h>
#fuses XT, NOWDT, PUT, BROWNOUT
#use delay(clock=4000000)   
#use rs232(baud=9600, UART1, errors, stream=DEBUG)

//========================================
void main()
{
float scldpotval1 = 33776.00;
float scaler = 1.48;

fprintf(DEBUG,"%f * %f = %f\r\n",(float)scldpotval1,(float)scaler,(float)scldpotval1*(float)scaler);
 
while(1);
}

Always post a test program so we can duplicate your test environment.
Otherwise we're just guessing, and it may be a waste of time.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group