I am lost with the following code trying to calculate square roots. The code is:
(defn tempsqrt [x p i]
(if (< i 2)
p
(tempsqrt x (+ (/ x (* 2 p)) (/ p 2)) (- i 1))))
(defn mysqrt [x]
(let [i 10
p (/ x 5)]
(tempsqrt x p i)))
When I execute (msqrt 1)
in Counterclockwise, it seems I get an endless loop since I have to forcibly stop processing.
I have tried to output i
and p
in mysqrt
and they seem to be calculated fine, I think there must be some stupid problem somewhere but I can't manage to find it.