-
-
Save abdollar/1504845 to your computer and use it in GitHub Desktop.
Square root calculation using Newton-Raphson
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Square root calculation using Newton-Raphson | |
# from Practical Programming (1968) | |
a = 256 | |
x = (1 + a) / 2.0 | |
loop do | |
ox = x | |
x = (x + a.to_f / x) / 2.0 | |
break if x >= ox | |
end | |
puts "The square root of #{a} is #{x}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment