aboutsummaryrefslogtreecommitdiff
path: root/j1demo/firmware/sincos.fs
diff options
context:
space:
mode:
authorDimitri Sokolyuk <ds@doozer.de>2017-05-23 17:06:09 +0200
committerDimitri Sokolyuk <ds@doozer.de>2017-05-23 17:06:09 +0200
commit6f86ce7057dd7cd1b491e8f09501258822d2ea74 (patch)
treeb3bfa11f0f72d0e1ca7c84d948af20b7494dd26b /j1demo/firmware/sincos.fs
Import j1demo
Diffstat (limited to 'j1demo/firmware/sincos.fs')
-rw-r--r--j1demo/firmware/sincos.fs36
1 files changed, 36 insertions, 0 deletions
diff --git a/j1demo/firmware/sincos.fs b/j1demo/firmware/sincos.fs
new file mode 100644
index 0000000..6ad1ea4
--- /dev/null
+++ b/j1demo/firmware/sincos.fs
@@ -0,0 +1,36 @@
+( Sine and cosine JCB 18:29 11/18/10)
+
+create sintab
+
+meta
+
+: mksin
+ 65 0 do
+ i s>d d>f 128e0 f/ pi f* fsin
+ 32767e0 f* f>d drop
+ t,
+ loop
+;
+mksin
+
+target
+
+: sin ( th -- v )
+ dup d# 128 and >r
+ d# 127 and
+ dup d# 63 > if
+ invert d# 129 + \ 64->64, 65->63
+ then
+ cells sintab + @
+ r> if
+ negate
+ then
+;
+
+: cos d# 64 + sin ;
+
+: sin* ( s th -- sinth * s )
+ sin swap 2* m* nip ;
+
+: cos* ( s th -- costh * s )
+ cos swap 2* m* nip ;