summaryrefslogtreecommitdiff
path: root/test/test.c
diff options
context:
space:
mode:
authortomsmeding <tom.smeding@gmail.com>2017-08-08 18:25:28 +0200
committertomsmeding <tom.smeding@gmail.com>2017-08-08 18:25:28 +0200
commit4f34eb13d06cdfa7b526f7e0aced9955808ee0d3 (patch)
tree91707211e007ad3f2cfbadd0d7b3292a3e0cad88 /test/test.c
parent0bb9d719c86db457439ee8e012eb141c76eed307 (diff)
Add faster interpreter, and some stuff
Diffstat (limited to 'test/test.c')
-rw-r--r--test/test.c45
1 files changed, 45 insertions, 0 deletions
diff --git a/test/test.c b/test/test.c
new file mode 100644
index 0000000..bdc11fc
--- /dev/null
+++ b/test/test.c
@@ -0,0 +1,45 @@
+#include <stdio.h>
+#include <stdint.h>
+
+// typedef uint32_t SF;
+// const int ush=24,ssh=31;
+typedef uint16_t SF;
+const int ush=11,ssh=15;
+
+SF mul(SF a,SF b){
+ SF sg=1;
+ if(a>=(1<<ssh)){a=-a; sg*=-1;}
+ if(b>=(1<<ssh)){b=-b; sg*=-1;}
+ return sg*(SF)(((uint64_t)a*(uint64_t)b)>>ush);
+}
+
+SF mk(int i){
+ return i<<ush;
+}
+
+float flt(SF a){
+ float sg=1;
+ if(a>=(1<<ssh)){a=-a; sg*=-1;}
+ return (float)a/(float)(1<<ush)*sg;
+}
+
+int main(void){
+ const SF L=mk(-2),R=mk(1);
+ const SF T=mk(1),B=-(mk(1));
+ for(SF y=T;y!=B-(mk(1)>>4);y-=mk(1)>>4){
+ for(SF x=L;x!=R;x+=mk(1)>>5){
+ int n=0;
+ SF a=x,b=y,a2=mul(a,a),b2=mul(b,b);
+ while(n<26&&a2+b2<mk(4)){
+ b=mul(mk(2),mul(a,b))+y;
+ a=a2-b2+x;
+ a2=mul(a,a);
+ b2=mul(b,b);
+ n++;
+ }
+ if(n==26)putchar(' ');
+ else putchar('A'+n);
+ }
+ putchar('\n');
+ }
+}