Created the sqrt function found on wikipedia page
authorAleksandar Kostovic <alexandar.kostovic@gmail.com>
Sat, 27 Apr 2019 10:50:36 +0000 (12:50 +0200)
committerAleksandar Kostovic <alexandar.kostovic@gmail.com>
Sat, 27 Apr 2019 10:50:36 +0000 (12:50 +0200)
src/add/fsqrt.py

index a2065ee55462e9ba1e35c691d439bce6d5791ee8..d911e3405ec3147d1c6f04754721694a9ff57f6d 100644 (file)
@@ -1,11 +1,23 @@
 def sqrt(num):
-    
-   num ** (1/2)
 
-   return num
+    num = 6
 
+    res = 0
+    bit = 1 << 14
 
+    while (bit > num):
+        bit >>= 2
 
+    while (bit != 0):
+        if (num >= res + bit):
+            num -= res + bit
+            res = (res >> 1) + bit
+        
+        else:
+            res >>= 1;
+        bit >>= 2;
+    
+    return res
 
 """
 //This is the main code of integer sqrt function found here:http://verilogcodes.blogspot.com/2017/11/a-verilog-function-for-finding-square-root.html