Skip to content

Instantly share code, notes, and snippets.

@waddles
waddles / newton.go
Last active August 29, 2015 14:15
An implementation of Newton's method of approximating a square root, written in Go
/*
http://tour.golang.org/flowcontrol/8
Exercise: Loops and Functions
As a simple way to play with functions and loops, implement the square root function using Newton's method.
In this case, Newton's method is to approximate Sqrt(x) by picking a starting point z and then repeating:
z^2 - x
z = z - -------
2z