summaryrefslogtreecommitdiff
path: root/n/asserv/src/dsp.c
diff options
context:
space:
mode:
Diffstat (limited to 'n/asserv/src/dsp.c')
-rw-r--r--n/asserv/src/dsp.c23
1 files changed, 23 insertions, 0 deletions
diff --git a/n/asserv/src/dsp.c b/n/asserv/src/dsp.c
index 4484b2f..5bbcf65 100644
--- a/n/asserv/src/dsp.c
+++ b/n/asserv/src/dsp.c
@@ -345,3 +345,26 @@ dsp_sin (int32_t a)
return -dsp_cos_dli (a - (1L << 23) - (1L << 22));
}
+/** Compute square root, uf24.8. */
+uint32_t
+dsp_sqrt (uint32_t x)
+{
+ uint32_t root, bit, test;
+ root = 0;
+ bit = 1L << 30;
+ do
+ {
+ test = root + bit;
+ //printf ("test = 0x%x, root = 0x%x, bit = 0x%x\n", test, root, bit);
+ if (x >= test)
+ {
+ x -= test;
+ root = test + bit;
+ //printf ("x = 0x%x, root = 0x%x\n", x, root);
+ }
+ root >>= 1;
+ bit >>= 2;
+ } while (bit);
+ return root << 4;
+}
+