18 #include "mozzi_fixmath.h" 23 typedef uint8_t uint8_t;
24 typedef unsigned short int uint16;
25 typedef unsigned long int uint32;
33 root, remainder, place;
39 while (place > remainder)
43 if (remainder >= root + place)
45 remainder = remainder - root - place;
46 root = root + (place << 1);
59 root, remainder, place;
65 while (place > remainder)
69 if (remainder >= root + place)
71 remainder = remainder - root - place;
72 root = root + (place << 1);
86 unsigned long isqrt(
unsigned long n) {
90 t = s+(1UL<<(k-1)); t <<= k+1; if (n >= t) { n -= t; s |= 1UL<<k; } 94 if (n >= 1UL<<62) { n -= 1UL<<62; s = 1UL<<31; }
95 sqrtBit(30); sqrtBit(29); sqrtBit(28); sqrtBit(27); sqrtBit(26);
96 sqrtBit(25); sqrtBit(24); sqrtBit(23); sqrtBit(22); sqrtBit(21);
97 sqrtBit(20); sqrtBit(19); sqrtBit(18); sqrtBit(17); sqrtBit(16);
100 if (n >= 1UL<<30) { n -= 1UL<<30; s = 1UL<<15; }
102 sqrtBit(14); sqrtBit(13); sqrtBit(12); sqrtBit(11); sqrtBit(10);
103 sqrtBit(9); sqrtBit(8); sqrtBit(7); sqrtBit(6); sqrtBit(5);
104 sqrtBit(4); sqrtBit(3); sqrtBit(2); sqrtBit(1);
105 if (n > s<<1) s |= 1UL;
132 uint16_t SquareRoot(uint32_t a_nInput)
134 uint32_t op = a_nInput;
136 uint32_t one = 1uL << 30;
149 op = op - (res + one);
161 int cogl_sqrti (
int number)
182 uint32_t f = 0x600000;
195 flt.i = 0x5f3759df - ( flt.i >> 1 );
209 flt2.f = flt.f + 2.0;
213 y_1 = (flt2.i >> 11) * (flt2.i >> 11);
214 y_1 = (y_1 >> 8) * (x >> 8);
217 flt2.i = (flt2.i >> 11) * (y_1 >> 11);
225 y_1 = (flt2.i >> 11) * (flt2.i >> 11);
226 y_1 = (y_1 >> 8) * (x >> 8);
229 flt2.i = (flt2.i >> 11) * (y_1 >> 11);
236 return (number * flt2.i + 0x1e3c68) >> 22;
Q15n16 Q15n0_to_Q15n16(Q15n0 a)
Convert Q15n0 int16_t to Q15n16 fix.