Skip to content

Instantly share code, notes, and snippets.

@tetsu-miyagawa
Created December 11, 2015 13:23
Show Gist options
  • Save tetsu-miyagawa/f45b4d48ce617c2e1c43 to your computer and use it in GitHub Desktop.
Save tetsu-miyagawa/f45b4d48ce617c2e1c43 to your computer and use it in GitHub Desktop.
CTMCP Section 3.2.4
declare Sqrt Iterate Abs
fun {Abs X} if X < 0.0 then ~X else X end end
fun {Iterate S IsDone Transform}
if {IsDone S} then S
else S1 in
S1={Transform S}
{Iterate S1 IsDone Transform}
end
end
fun {Sqrt X}
{Iterate
1.0
fun {$ G} {Abs X-G*G}/X < 0.00001 end
fun {$ G} (G+X/G)/2.0 end}
end
{Browse {Sqrt 10.0}}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment