22 #error This file is just a scratchpad for integer sqrt algorithms. It is not currently meant to an official part of the Mozzi API. 26 unsigned long isqrt(
unsigned long n) {
30 t = s+(1UL
<<(k-1
)); t <<= k+1
; if (n >= t) { n -= t; s |= 1UL
<<k; } 34 if (n >= 1UL<<62) { n -= 1UL<<62; s = 1UL<<31; }
35 sqrtBit(30); sqrtBit(29); sqrtBit(28); sqrtBit(27); sqrtBit(26);
36 sqrtBit(25); sqrtBit(24); sqrtBit(23); sqrtBit(22); sqrtBit(21);
37 sqrtBit(20); sqrtBit(19); sqrtBit(18); sqrtBit(17); sqrtBit(16);
40 if (n >= 1UL<<30) { n -= 1UL<<30; s = 1UL<<15; }
45 if (n > s<<1) s |= 1UL;
72 uint16_t SquareRoot(uint32_t a_nInput)
74 uint32_t op = a_nInput;
76 uint32_t one = 1uL << 30;
89 op = op - (res + one);
101 int cogl_sqrti (
int number)
122 uint32_t f = 0x600000;
135 flt.i = 0x5f3759df - ( flt.i >> 1 );
149 flt2.f = flt.f + 2.0;
153 y_1 = (flt2.i >> 11) * (flt2.i >> 11);
154 y_1 = (y_1 >> 8) * (x >> 8);
157 flt2.i = (flt2.i >> 11) * (y_1 >> 11);
165 y_1 = (flt2.i >> 11) * (flt2.i >> 11);
166 y_1 = (y_1 >> 8) * (x >> 8);
169 flt2.i = (flt2.i >> 11) * (y_1 >> 11);
176 return (number * flt2.i + 0x1e3c68) >> 22;
Q15n16 Q15n0_to_Q15n16(Q15n0 a)
Convert Q15n0 int16_t to Q15n16 fix.