Author Topic: A Cosine function, with no tablebase usage.  (Read 3053 times)

Offline peterb

  • Bot Destroyer
  • ***
  • Posts: 148
    • View Profile
A Cosine function, with no tablebase usage.
« on: April 04, 2010, 09:29:34 PM »
cosine (from +100 to -100) , based on the 1256 darwinbots  x degrees

notice i kept the value of e inside here since there might be different ways to optimize this math into to darwinbots.
e is about 2.71828182845904523536  (source wikipedia)

the function cos(x)*100  as  f(x) =  

      100.336
      + 1.55527e-015*x*x*x*x*x*x
      + 6.72543e-009*x*x*x*x
      - 1.48672e-006*x*x*x
      - 5.86017e-012*x*x*x*x*x
      - 0.000986079*x*x
      - 0.0193941*x
__________________________(sum)


PS
I don't deserve big credits for it, I'm just playing with my new math toy and giving it some tests.
Still it might be useful for those who want to play with sin and cos   sin (x) = cos (x-324)
So we can create Spiro-graphic effects  
Notice i let result from -100 to 100 for integer rounding reasons    true cos should have a final 100 div after it.
I'm not sure how precise it will be these function inside the integer universe of darwin bots.
My mechanical turk , is going to keep number crunching on the data set so maybe i have a better function tomorrow.
But i doubt it as this is pretty near to the real thing..
Note this function might require mod function for its input 1256 mod

hmm and it might be that *x*x*x*x*x*x  results in overflow...

Offline bacillus

  • Bot Overlord
  • ****
  • Posts: 907
    • View Profile
A Cosine function, with no tablebase usage.
« Reply #1 on: April 10, 2010, 02:10:08 AM »
Just taylor series should do it. I'm sure those units sound a bit off to me, and you'd have to break down each polynomial into several steps to fit it into the 32000-range, dropping a whole lot of accuracy long the way. Did you remember to scale it up so it doesn't get rounded to one or zero?
"They laughed at Columbus, they laughed at Fulton, they laughed at the Wright brothers. But they also laughed at Bozo the Clown."
- Carl Sagan

Offline peterb

  • Bot Destroyer
  • ***
  • Posts: 148
    • View Profile
A Cosine function, with no tablebase usage.
« Reply #2 on: April 10, 2010, 08:41:25 PM »
it is scaled up from -100 to +100