Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def sqrt n
- g, avg = 1
- loop {
- q = n / g
- avg = (q + g) / 2.0
- (avg-g).abs <= 0.000001 ? break : g = avg
- }
- avg
- end
- sqrt 9999*9999
- sqrt 0.00000000000000000000000001
- puts sqrt(1.0e+24) == 1000000000000.0
Add Comment
Please, Sign In to add comment