Accuracy of FSIN and FCOS in BasicAtom-Pro IDE?

I just ran an experiment of the accuracy of FSIN and FCOS versus my windows calculator, and I noticed that the results were quite off.

Atom Pro 28:
FSIN (1.0471975511965977461542144610932) resulted in:
0.8660253286

Calculator (mode: radians)
SIN^-1 (1.0471975511965977461542144610932) resulted in:
0.8660254038

According to the Atom Pro manual, the type float is good from ± 2^-126 to ± 2^127 and FCOS and FSIN is good from -pi/2 to pi/2 (actual is ± 1.74 radians). So I believe what I’m asking it to do is reasonable…

Is it because “1.0471975511965977461542144610932” (60 degrees) is being truncated in the BasicAtom-Pro IDE when converting it to binary during compile?

I have not played around much with floating point on the Pro, but a quick look at the manual shows the format of the floating point number:

ATOM PRO format:
Bits 31 – 24 exponent (E)
Bit 23 sign bit (S)
Bits 22 – 0 mantissa (M)

From this you can see that the Atom Pro (and similarly ieee format) has only 23 binary bits of data for the mantissa. Which for sure is not enough to hold your number: (.10471975511965977461542144610932) to the 33 decimal digits accuracy… My guess is that 23 bits of data might give you decimal accuracy to 7 or 8 digits, but my math is a bit rusty…

Not sure what the windows calculator uses…

Good Luck

Kurt

Thanks kurte, I couldn’t find the floating point format of the Atom Pro, which page of AtomPro_8000.pdf was it in?

I did some more experiments and found that FSIN and FCOS isn’t very reliable.

serout s_out,i9600,"FSIN 0.0: ",real FSIN 0.0,13]

Yielded:

FSIN 0.0: -0.0000000689

Not quite zero as you would expect SINE of 0.0 radians to be…

ya know these are single-precision floating point numbers running on a hitachi microcontroller and taking less than a second to return a computation… I just don’t get what the issue is… sudden realization that not all floating point calculations are equal? :confused: <- confused

Try looking at page 66 document numbering (76 pdf numbering). Or do a search for “floating point format” or “IEEE”

P.S. - I agree with Eddie, that you may be asking for too much if you want more than 7 or 8 digits of accuracy from a microcontroller doing floating point calculations such as FSIN with no underlying hardware support…

Thanks kurte, I’ve read that section but never paid attention to that section.

I thought the accuracy of the FSIN was just a curiousity since I use a lot of:

FSIN SOMEVAR where SOMEVAR = 0.0 most of the time…

The floating point format is quite interesting, the sign bit being somewhere in the middle… :stuck_out_tongue: