There is a certain function
Where
There was a need to calculate the inverse function
Now I think about the elegant and not too slow method of calculating x (y). What are my options?
There is a certain function
Where
There was a need to calculate the inverse function
Now I think about the elegant and not too slow method of calculating x (y). What are my options?
Standard recurrence ratio does not fit?
// x(n + 1) = 0.5*(x(n) + n / x(n)) scanf("%u", &test_number); x_new = test_number; x_old = 0; while (x_old != x_new) { x_old = x_new; x_new = (x_new + test_number / x_new) >> 1; } printf("%u\n", x_new);
If I understood correctly about natural numbers, then for 32-bit integers.
unsigned int sqrt32(unsigned long n) { unsigned int c = 0x8000; unsigned int g = 0x8000; for(;;) { if(g*g > n) g ^= c; c >>= 1; if(c == 0) return g; g |= c; } }
Spread out in taylor row
Source: https://ru.stackoverflow.com/questions/102681/