View previous topic :: View next topic |
Author |
Message |
esat
Joined: 26 May 2007 Posts: 3
|
math problem for calculator... |
Posted: Tue Sep 30, 2008 12:13 pm |
|
|
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 |
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah Guest
|
|
Posted: Tue Sep 30, 2008 12:36 pm |
|
|
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 |
|
![](templates/subSilver/images/spacer.gif) |
esat
Joined: 26 May 2007 Posts: 3
|
|
Posted: Wed Oct 01, 2008 4:21 am |
|
|
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](images/smiles/icon_smile.gif) |
|
![](templates/subSilver/images/spacer.gif) |
Douglas Kennedy
Joined: 07 Sep 2003 Posts: 755 Location: Florida
|
|
Posted: Wed Oct 01, 2008 12:28 pm |
|
|
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. |
|
![](templates/subSilver/images/spacer.gif) |
|