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 support@ccsinfo.com

floating error

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







floating error
PostPosted: Tue Jun 03, 2003 5:36 am     Reply with quote

Hi,
I have CCS PCM compiler ver 3.088
but floating point error

#define f1 1.41
#define f2 2.76
#define f3 3.14

printf(lcd_putc,"\%\f1.2f \%1.2f \%1.2f",f1,f2,f3);

On Display
1.40 2.75 3.14

Why?
___________________________
This message was ported from CCS's old forum
Original Post ID: 144515001
Steve H.
Guest







Re: floating error
PostPosted: Tue Jun 03, 2003 9:41 am     Reply with quote

A PIC isn't a PC with unlimited resources and double precision math. You are trying to shove a decimal number into a limited precision binary representation. Without rounding errors you are lucky to get 3 digits.

For precise outputs you should consider using fixed point math with int's or long's and add the decimal point for the user display only.

This topic has been covered before on this board, search fixed point, float error, rounding, etc.
___________________________
This message was ported from CCS's old forum
Original Post ID: 144515006
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