19 lines
484 B
Markdown
19 lines
484 B
Markdown
# Square Root
|
|
|
|
TODO
|
|
|
|
|
|
|
|
The following is an [approximation](approximation.md) of integer square root in [C](c.md) that has acceptable accuracy to about 1 million (maximum error from 1000 to 1000000 is about 7%): { Painstakingly made by me. ~drummyfish }
|
|
|
|
```
|
|
int32_t sqrtApprox(int32_t x)
|
|
{
|
|
return
|
|
(x < 1024) ?
|
|
(-2400 / (x + 120) + x / 64 + 20) :
|
|
((x < 93580) ?
|
|
(-1000000 / (x + 8000) + x / 512 + 142) :
|
|
(-75000000 / (x + 160000) + x / 2048 + 565));
|
|
}
|
|
``` |