Author Topic: cos(, tan( and sin( return strange values  (Read 2648 times)

0 Members and 1 Guest are viewing this topic.

Offline SamTebbs33

  • LV1 Newcomer (Next: 20)
  • *
  • Posts: 16
  • Rating: +0/-0
    • View Profile
cos(, tan( and sin( return strange values
« on: January 16, 2014, 12:43:34 pm »
When using Disp {sin(90)}>Dec I get 8, why is that? If that is supposed to happen, could anyone guide me to somehow getting the proper value of sin(90)?

Thanks!

Offline Xeda112358

  • they/them
  • Moderator
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 4704
  • Rating: +719/-6
  • Calc-u-lator, do doo doo do do do.
    • View Profile
Re: cos(, tan( and sin( return strange values
« Reply #1 on: January 16, 2014, 01:13:41 pm »
If you have read the documentation, what it means by having the range on [-128,127] is that 64 corresponds to "90" or "pi/2" or whatever other notation you might be used to. Likewise, since Axe only works with integers and fixed point, the output is basically 128*sin(x). Otherwise, it would always return 0 from rounding :P

So, the binary angle 90 corresponds to the degree measure 90*180/128=126.5625, and 128*sin(126.5625) is about 103. Axe returns 105, since it is an approximation (this is still within .01 of the actual, which is good).

You aren't getting 105, though, which might seem weird, but the problem is that you are using {}. In Axe, this means "read the byte at the address given." Basically, you told it to display the number at byte 105 of memory. If you wanted, you could get Calcsys, open the hex editor, press [Alpha][G] (for Goto) and type the address 006A and you will see the byte value is indeed 08.

EDIT: Also, I don't think Axe supports tan()... If you do want that, I would suggest using a fixed point division of sin()/cos(). For example:
Code: [Select]
.TAN
Ans→X
sin(X)/*cos(X)→X
Then do something like 37*128/180:Asm(prgmTAN:Ans and you should get an approximation of 256*tan(37).