blob: c00804fcc8ba77f2d6440b79ac9f7b35bd898ccb (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
|
#include "math.h"
int64_t fsqrt64(int64_t a, unsigned int fracbits)
{
int64_t b = a/2 + (1 << fracbits); /* initial approximation */
unsigned int n;
const unsigned int iterations = 3; /* very rough approximation */
for (n = 0; n < iterations; ++n)
b = (b + (((int64_t)(a) << fracbits)/b))/2;
return b;
}
|