Skip to content

Instantly share code, notes, and snippets.

@wmmnola
Created December 25, 2017 18:48
Show Gist options
  • Save wmmnola/884da0813bfbb8f4c601e48c27a0b79e to your computer and use it in GitHub Desktop.
Save wmmnola/884da0813bfbb8f4c601e48c27a0b79e to your computer and use it in GitHub Desktop.
Continued Fraction implementation of sqrt(n) for fun
float slowsqrt(float n);
float nestedSqrt(float n, float level);
float slowsqrt(float n){
float s = 1 + ((n-1)/nestedSqrt(n,0));
return s;
}
float nestedSqrt(float n, float level){
if(level < 30){
return 2 + ((n-1)/nestedSqrt(n, level+1));
}
else{
return 1;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment