sincos.fs 522 B

123456789101112131415161718192021222324252627282930313233343536
  1. ( Sine and cosine JCB 18:29 11/18/10)
  2. create sintab
  3. meta
  4. : mksin
  5. 65 0 do
  6. i s>d d>f 128e0 f/ pi f* fsin
  7. 32767e0 f* f>d drop
  8. t,
  9. loop
  10. ;
  11. mksin
  12. target
  13. : sin ( th -- v )
  14. dup d# 128 and >r
  15. d# 127 and
  16. dup d# 63 > if
  17. invert d# 129 + \ 64->64, 65->63
  18. then
  19. cells sintab + @
  20. r> if
  21. negate
  22. then
  23. ;
  24. : cos d# 64 + sin ;
  25. : sin* ( s th -- sinth * s )
  26. sin swap 2* m* nip ;
  27. : cos* ( s th -- costh * s )
  28. cos swap 2* m* nip ;