source: golgotha/src/i4/math/int_sqrt.hh @ 80

Last change on this file since 80 was 80, checked in by Sam Hocevar, 11 years ago
  • Adding the Golgotha source code. Not sure what's going to be interesting in there, but since it's all public domain, there's certainly stuff to pick up.
File size: 771 bytes
Line 
1/********************************************************************** <BR>
2  This file is part of Crack dot Com's free source code release of
3  Golgotha. <a href="http://www.crack.com/golgotha_release"> <BR> for
4  information about compiling & licensing issues visit this URL</a>
5  <PRE> If that doesn't help, contact Jonathan Clark at
6  golgotha_source@usa.net (Subject should have "GOLG" in it)
7***********************************************************************/
8
9#ifndef I4_INT_SQRT
10#define I4_INT_SQRT
11
12
13// From Graphics Gems II. p 387
14
15inline w32 i4_int_sqrt(w32 n)
16{
17  w32 next=n/2, current;
18  if (n<=1)
19    return n;
20  do
21  {
22    current=next;
23    next=(next+n/next)/2;
24  } while (next<current);
25  return current;
26}
27
28
29#endif
Note: See TracBrowser for help on using the repository browser.