how to get the mathematical function sin


Closed Thread
Results 1 to 10 of 10
  1. #1
    Join Date
    Nov 2009
    Posts
    3

    Default how to get the mathematical function sin

    I am making a calculator and I need to function without cos so but I do not get consistent values as I do, I'll be grateful. (I'm using microcode)

  2. #2
    Join Date
    Feb 2006
    Location
    Gilroy, CA
    Posts
    1,530


    Did you find this post helpful? Yes | No

    Default

    As usual, there are a couple ways to go to get sin. But hopefully, you don't want calculator precision for your ..um .... calculator.

    Melanie has a brilliant way. Old post, but I only recently discovered it.
    http://www.picbasic.co.uk/forum/show...=2873#post2873

    And doing it this way would also give you the ability to do sin, cos and atan2 on your calculator.
    http://www.picbasic.co.uk/forum/showthread.php?t=10528

  3. #3


    Did you find this post helpful? Yes | No

    Default dumb question?

    So, dumb question but...

    so what does the PICBASIC PRO SIN function do that's useful?

  4. #4


    Did you find this post helpful? Yes | No

    Default a little experimentation

    Never mind, I discovered the answer with a little impromptu LCDing.

    What is unclear in the manual is that the angle in degrees is represented by a value of 0-255 instead of 0-359. It's NOT in radians as the manual suggests (where a decimal value of 6.28 radians would correspond to 360 degrees). To calculate the value to pass to the function SIN x, you have to use x=255y/360 where y was your angle in degrees.

    The result returned from the SIN function is in the range of 0-255, in two's compliment form (where 0-127 corresponds to a scaled sin result of 0.00 to 1.00 respectively and 128-255 corresponds to a scaled sin result of -1.00 to 0.00 respectively).

    Although it's not super accurate, it's reasonably adequate to 2 decimal places if you figure 0-127 scaling is better than 1 to 100.
    Last edited by picster; - 11th July 2010 at 16:45. Reason: clarity

  5. #5
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    The results are in
    Binary Radians as the manual suggest...
    Dave
    Always wear safety glasses while programming.

  6. #6
    Join Date
    Jan 2009
    Location
    Miami, Florida USA
    Posts
    644


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by picster View Post
    Although it's not super accurate, it's reasonably adequate to 2 decimal places if you figure 0-127 scaling is better than 1 to 100.
    The PBP SIN function is accurate enough for most applications. It has an accuracy of 1/256 per Sine cycle. Of course, if you are trying to make a calculator like Minssss is trying to do it won't be accurate enough.

    Robert

  7. #7


    Did you find this post helpful? Yes | No

    Default more on sin format

    Quote Originally Posted by mackrackit View Post
    The results are in
    Binary Radians as the manual suggest...
    If I'm not mistaken, the results of a sin function are merely a ratio and don't have a unit. In this case, it's -127 to 127, which is as I see it, a number to be divided by 127 to get the actual result.

    Radians are a unit like degrees, and the result wouldn't be in radians anyway, since the result is merely supposed to be a ratio.

    I could be way off base with this, and would be glad to be shown how radians are involved.

    picster

  8. #8
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    It is just a way to have a circle fit into a byte. Probably should have been named something different.

    http://www.oopic.com/pgchap15.htm
    Dave
    Always wear safety glasses while programming.

  9. #9


    Did you find this post helpful? Yes | No

    Default not being a butthead

    Quote Originally Posted by mackrackit View Post
    It is just a way to have a circle fit into a byte. Probably should have been named something different.

    http://www.oopic.com/pgchap15.htm
    Interesting link. Sorry, I don't mean to nit-pic, just to provide some clarification.

    From a mathematical standpoint, "Brads" as referred to in the link, is a suggested misnomer as well, since radians play no role in the user's-end of the equation. Lacking any other existing unit, some new unit should be assigned. Since the nature of any angle measurement is that it cycles, similarities in this respect are moot point (since it's a requirement). I'm kind of partial to "Bangles", myself - Binary Angles where there are 256 units in a full cycle.

    The difficulties I encountered while trying to implement SIN properly in my recent program was due to the fact that the manual provided no examples, and the wording was such that one would think that radians (by definition) were the actual unit of measurement (which they aren't, since the function doesn't repeat every 6.28 units). I hope this helps others who are trying to successfully implement this function.

    picster

  10. #10
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    I do not see any buttheads or nit-picers...
    I see a confusing subject being discussed.

    I agree that some if not most of the examples are lacking, that is part of the reason the wiki was started.

    Would you be game to writing an article about this for the math section?
    http://www.picbasic.co.uk/forum/content.php?r=163
    Dave
    Always wear safety glasses while programming.

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts