From 264ec6d3b61267429026b0090047e81fe85900d5 Mon Sep 17 00:00:00 2001 From: Aleksandar Kostovic Date: Sat, 27 Apr 2019 12:50:36 +0200 Subject: [PATCH] Created the sqrt function found on wikipedia page --- src/add/fsqrt.py | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/src/add/fsqrt.py b/src/add/fsqrt.py index a2065ee5..d911e340 100644 --- a/src/add/fsqrt.py +++ b/src/add/fsqrt.py @@ -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 -- 2.30.2