This commit is contained in:
Miloslav Ciz 2025-02-12 23:09:00 +01:00
parent 85321afd67
commit ec4393d204
17 changed files with 1952 additions and 1945 deletions

View file

@ -56,7 +56,7 @@ TODO: more
## Programming
Square root is a very common operation and oftentimes has to be VERY fast -- it's used a lot for example in [computer graphics](graphics.md) where it may need to be computed several million times per second. For this reason there oftentimes exist special instructions and otherwise hardware accelerated options, you will very likely have such function around on most computers -- in [C](c.md) math standard library there's the `sqrt` [floating point](float.md) function that will probably be very fast. But let's now consider you want to program your own square root, which may happen for example when dealing with [embedded](embedded.md) computers.
Square root is a very common operation and oftentimes has to be VERY fast -- it's used a lot for example in [computer graphics](graphics.md) and so gets executed several million times per second. For this reason there oftentimes exist special instructions and otherwise hardware accelerated options, you will very likely have such function around on most computers -- in [C](c.md) math standard library there's the `sqrt` [floating point](float.md) function that will probably be very fast. But let's now consider you want to program your own square root, which may happen for example when dealing with [embedded](embedded.md) computers.
If we really need extreme speed, we may always use a [look up table](lut.md) with precomputed values. Of course a table with ALL the values would be very big, but remember we can make a much smaller table (where each item spans a bigger range) that will provide just a quick [estimate](approximation.md) from which you'll make just a few extra iterations towards the correct answer.
@ -159,6 +159,8 @@ double sqrtF(double x)
}
```
For the real curious it's possible to look further into how serious C libraries such as [musl](musl.md) or [glibc](glibc.md) do it, but it's usually not a pleasant sight to behold.
## See Also
- [logarithm](log.md)