News for hackers. Stuff that matters.
Re:Float Toy by Sharlin on Saturday August 20, 2022 @08:39PM (#32536377)
A while ago I realized that a very fast way to multiply or divide a 32-bit float by 2^n is to simply reinterpret it as int and add/subtract n<<23. Plus some checks if you care about overflow. Obvious in retrospect, and may not be worth it on modern desktop hardware, but still a nice trick. (This was in the context of optimizing a texture sampler for power-of-two textures.)
Re:Float Toy by adgjlsfhk1 on Saturday August 20, 2022 @10:26PM (#32536872)
One place where this is used in practice is in the code to compute floating point exponentials.
Re:Float Toy by alberth on Saturday August 20, 2022 @08:59PM (#32536483)
You can do lots of interesting things with bit shifts.

Like the famous Quake3 Fast Inverse Square

https://www.beyond3d.com/content/articles/8/

Re:Float Toy by ChrisLomont on Saturday August 20, 2022 @10:13PM (#32536822)
Plenty of languages have this in their standard libraries for exactly this purpose. I use it in C/C++ and C# frequently in numerical code.
Re:Float Toy by Sharlin on Sunday August 21, 2022 @09:10AM (#32539802)
Oh wow, I had totally missed that C has such functions as `ldexp` and `scalb*`.