)
}
}
)
(
}
{
)
)
(
)
(
(
{
}
)
(
)
}
)
)
{
(
(
)
)
}
)
(
}

Iterative Square Root

  1. //------------------------------------------------------------------
  2. float function_IterativeSquareRoot (float x) {
  3.   // http://en.wikipedia.org/wiki/Methods_of_computing_square_roots
  4.   // Ancient Babylonian technology
  5.   functionName = "Iterative (Heron's) Square Root";
  6.   float y = 0.5; 
  7.   int n = 6;
  8.   for (int i=0; i<n; i++) {
  9.     y = (y + x/y)/2.0;
  10.   }
  11.   return y;
  12. }

Was browsing some code by Golan Levin and stumbled on this…

There are some real gems in the repo – might port some stuff from there in the future…

snippet.zone ~ 2021-24 /// {s/z}