This preview shows pages 1–2. Sign up to view the full content.
This preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
Unformatted text preview: (* return a better guess by averaging it with x/guess *) and improve(guess) = (guess +. x /. guess) /. 2.0 (* Return the square root of x, starting from an initial guess. *) and tryGuess(guess) = if goodEnough(guess) then guess else tryGuess(improve(guess)) in (* start with a guess of 1.0 *) tryGuess(1.0) (* explicitly typed version *) let squareRoot(x: float): float = let rec (* numerical accuracy *) delta:float = 1e10 (* returns true iff the guess is good enough *) and goodEnough(guess: float): bool = abs_float(guess *. guess . x) < delta (* return a better guess by averaging it with x/guess *) and improve(guess: float): float = (guess +. x /. guess) /. 2.0 (* Return the square root of x, starting from an initial guess. *) and tryGuess(guess: float): float = if goodEnough(guess) then guess else tryGuess(improve(guess)) in (* start with a guess of 1.0 *) tryGuess(1.0)...
View
Full
Document
This note was uploaded on 10/25/2009 for the course PHYS 2214 at Cornell.
 '07
 GIAMBATTISTA,A

Click to edit the document details