Log In  

I think all of us who have used COS() and SIN() from one time to another find it rather difficult to get "clean" numbers, that is, to bounce around from one end of the negative spectrum, to positive, and back again to exactly where you started.

I wrote this routine to use for my own stuff but you can work it too if you like.

It's a simple array from 0-255 called MySin(), in it, it starts at -255, works to positive 255, and back again, in a very clean curved calculation that does not involve any math other than adding and subtracting coefficient numbers.

[16x16]

mysin={}
n=-255
a=0
p=0
repeat
  print(p.." "..n)
  repeat
    flip()
  until btn(4)
  mysin[p]=n
  mysin[127-p]=-n
  mysin[128+p]=-n
  mysin[255-p]=n
  n+=a
  a+=.128
  p+=1
until p>=64
cls()
for i=0,255 do
  pset(i/2,64+mysin[i]/8)
end

for i=0,255 do
  print(i.." "..mysin[i])
  repeat
    flip()
  until btn(4)
end

As you can see by reading every fractional value back, it is flawless in its calculations. You have a true and perfect mirror for both negative and positive values. Watch especially when the index passes 64 and 127 and compare both the negative and positive numbers.

HOPE THIS HELPS !

P#56252 2018-09-06 00:37 ( Edited 2018-09-06 23:18)

Looks like the real problem is with the SIN() function itself. I've done some diagnostics and I found what seem to be two different bugs in it.

I'll write it up separately.

P#56326 2018-09-06 18:36 ( Edited 2018-09-06 22:36)

Hey, we finally agree on something. Whoo ! Up here, on the top !

Seriously though, yes. It's flawed. That's why I'm using this table until something better comes along.

P#56333 2018-09-06 19:18 ( Edited 2018-09-06 23:19)

[Please log in to post a comment]

Follow Lexaloffle:          
Generated 2024-03-29 00:49:02 | 0.006s | Q:12