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

math problem for calculator...

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



Joined: 26 May 2007
Posts: 3

View user's profile Send private message

math problem for calculator...
PostPosted: Tue Sep 30, 2008 12:13 pm     Reply with quote

my problem is easy but i am not solve it.

i find sin(30)=0.50000052 but it's real result is sin(30)=0.50000000

for this reason i find
2/sin(30)=3.9999..

how can i solve it. and i must use 7-8 digits(correctly) after the point.

thanks for helps
Ttelmah
Guest







PostPosted: Tue Sep 30, 2008 12:36 pm     Reply with quote

You can't, except to write/use your own maths library.
CCS (for the 12, 16, & 18 chips), only supports a single precision floating point data type. This gives about 6 total digits of precision _only_. This is what you are seeing.
In the past, I have used the int32 type, as a fixed precision format (%w supports outputting values like this), and used a simple lookup table, combined with an iterative approximation, to give improved accuracies.

Best Wishes
esat



Joined: 26 May 2007
Posts: 3

View user's profile Send private message

PostPosted: Wed Oct 01, 2008 4:21 am     Reply with quote

ok. thanks "Ttelmah". my code is not here. for this reason, after the 4 october, i will write again. i wish , we will solve this problem.

for example, it is a equation and this is in string type.

"-2*cos-30/ln30-2*cos^2-10/-ln30-2*2sin30/2*sin+30/20*sin30^2/5" or
"11.45+((81*sin(30.5)+(5^2))+log(22.42)/5!)"

i can convert this equations in aritmetic type and solved. this results are similar "casio fx-82MS calculator" but only 5 digits after the point.

i wish tell my problem correctly. see u later, after the 4 october.

thanks for all... Smile
Douglas Kennedy



Joined: 07 Sep 2003
Posts: 755
Location: Florida

View user's profile Send private message AIM Address

PostPosted: Wed Oct 01, 2008 12:28 pm     Reply with quote

Most calculators do their work in binary coded decimal (BCD). This means they don't leave base ten ( decimal) notation. History has us accepting this notation as accurate. PIC uses binary notation and does calculations in binary. This is distinct from BCD which is at it's core still decimal notation.
Binary notation is most efficient for the PIC. The PIC produces accurate results for binary notation within the storage format chosen 23 bit mantissa and 8 bit exponent. The issues you are experiencing result in the conversion of one notation to another. In your case from decimal to binary and then binary to decimal. An example take the number 0.1 in decimal. It cannot be notated in binary exactly no matter the precision. Now it is true that at say 64 bit binary notation the difference is small enough not to bother anyone. The PIC uses 23 bits so it is never guaranteed to be useful beyond 6 or 7 decimal digits. There are obviously numbers that can be expressed exactly in both binary and decimal. That is whole numbers up to 2^23 and decimals that are the sums of negative powers of two Ex 0.125 or 0.625 (.5+.125).
The PIC compiler automatically does a notation conversion from your program line into binary instructions so you have no control over it unless you roll your own solution. The functions of sine and cosine also have their own issues since either in binary or decimal except for certain values they can't be expressed exactly with limited notational precision similarly with numbers like pi.
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