fork download
  1.  
  2. sqrt' :: Double -> Double -> Double
  3. sqrt' x guess
  4. | guessIsGoodEnough = guess
  5. | otherwise = sqrt' x improvedGuess
  6. where
  7. -- Test the precision of the guess
  8. precision = 1e-15
  9. guessIsGoodEnough = abs (guess * guess - x) < precision * x
  10. -- Improve our guessed square
  11. improvedGuess = (guess + x / guess) / 2
  12.  
  13. main = putStrLn.show $ 1.0/((sqrt' 1234567899 1) + (sqrt' 1234567898 1))
  14.  
Success #stdin #stdout 0s 4728KB
stdin
Standard input is empty
stdout
1.4230249486517707e-5