[Haskell-cafe] Debugging Newton's method for square roots
Vraj Mohan
r.vrajmohan at gmail.com
Sun Oct 15 08:17:20 EDT 2006
I am new to Haskell and need help in debugging my code.
I wrote the following function for calculating square roots using Newton's
method:
my_sqrt :: Float -> Float
my_sqrt x = improve 1 x
where improve y x = if abs (y * y - x) < epsilon
then y
else improve ((y + (x/y))/ 2) x
epsilon = 0.00001
This works for several examples that I tried out but goes into an infinite loop
for my_sqrt 96. How do I go about debugging this code in GHC or Hugs?
(The equivalent code is well-behaved on MIT Scheme)
More information about the Haskell-Cafe
mailing list