Thread: Reverse of sine table (back to code)

  1. #1
    Registered User
    Join Date
    Jan 2013
    Posts
    106

    Reverse of sine table (back to code)

    Hi Guys
    I have this sine table for various things in a program such as sine
    text and plasma that I’ve been using for the last million years.
    Now programming for a micro, and with code running low,
    I wonder if anyone can tell me how to generate it at run time (or pretty close).

    Basically, if I start with the same array not explicitly defined like this:
    Code:
    WORD sin_table[91];
    and then populate it with code, I assume I’ll save some program memory space.
    Any help appreciated (it’s not homework just hobby).
    Cheers, Art.


    Code:
    WORD sin_table[91] ={
        0,   285,   571,   857,  1142,  1427,  1712,  1996,  2280,  2563,
        2845,  3126,  3406,  3685,  3963,  4240,  4516,  4790,  5062,  5334,
        5603,  5871,  6137,  6401,  6663,  6924,  7182,  7438,  7691,  7943,
        8191,  8438,  8682,  8923,  9161,  9397,  9630,  9860, 10086, 10310,
        10531, 10748, 10963, 11173, 11381, 11585, 11785, 11982, 12175, 12365,
        12550, 12732, 12910, 13084, 13254, 13420, 13582, 13740, 13894, 14043,
        14188, 14329, 14466, 14598, 14725, 14848, 14967, 15081, 15190, 15295,
        15395, 15491, 15582, 15668, 15749, 15825, 15897, 15964, 16025, 16082,
        16135, 16182, 16224, 16261, 16294, 16321, 16344, 16361, 16374, 16381,
        16384
    };

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    So what are you trying to optimise?

    How fast?
    How small?
    How accurate?

    If you can't spare 180 bytes for a table, then perhaps compute it at run time.
    Bhaskara I's sine approximation formula - Wikipedia
    Maclaurin Series -- from Wolfram MathWorld
    Though if your micro lacks mul (and especially div), that could be pretty slow. But if you're looking for small code to create a table in RAM it might be worth it.

    With only 90 elements, do you really need 16 bits of precision to go with it?

    Are you performing any interpolation on the results?
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Jan 2013
    Posts
    106
    Slow, Very, The closer the better.

    Something I realised, I have a function implemented to rotate a point about an origin for graphics x/y coordinates.
    So if the point starts 16384 units under the origin, I should be able to to a for loop with 90 steps incrementing the angle 1 degree each iteration,
    and only look at the y offset for the result.
    Does that sound right?
    That would cost me almost no code.

    That’s way off the screen, but I don’t have to draw it.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Going back in code
    By sean_cantab in forum C++ Programming
    Replies: 4
    Last Post: 05-13-2016, 12:27 PM
  2. Replies: 11
    Last Post: 08-27-2015, 05:52 PM
  3. Replies: 26
    Last Post: 10-30-2013, 11:34 PM
  4. string reverse. cannot find the bug in my code.
    By getnitin15 in forum C Programming
    Replies: 25
    Last Post: 03-04-2012, 11:11 AM
  5. Code for UPPER and REVERSE
    By Unregistered in forum C Programming
    Replies: 4
    Last Post: 03-15-2002, 09:31 AM

Tags for this Thread