作为师乘法和LUT? /快浮师倒数 [英] division as multiply and LUT ? / fast float division reciprocal
问题描述
时有可能使浮动分工形式倒数
的查找表(例如像的1 / f - > 1 * INV并[f])?如何可以做?
我认为,一些与面具和转移应appled浮动,使
它索引的形式?如何将它exectly?
Is it possible to make a reciprocal of float division in form of look up table (such like 1/f -> 1*inv[f] ) ? How it could be done? I think some and mask and shift should be appled to float to make it a form of index? How would be it exectly?
推荐答案
您可以猜到一个近似逆是这样的:
You can guess an approximate inverse like this:
int x = reinterpret_cast<int>(f);
x = 0x7EEEEEEE - x;
float inv = reinterpret_cast<float>(x);
在我的测试中,0x7EF19D07略好(用2牛顿迭代改进的影响进行测试在内)。
In my tests, 0x7EF19D07 was slightly better (tested with the effects of 2 Newton-Raphson refinements included).
您可以再与牛顿迭代改进:
Which you can then improve with Newton-Raphson:
inv = inv * (2 - inv * f);
迭代往往你想要的。 2或3次迭代给出很好的结果。
Iterate as often as you want. 2 or 3 iterations give nice results.
要尽量减少相对误差:
- 0x7EF311C2(无精)
- 0x7EF311C3(1细化)
- 0x7EF312AC(2改进)
- 0x7EEEEBB3(3改进)
要最大限度地减少对1和2之间输入的绝对误差(它们工作得很好够在该范围之外,但它们可能不是最好的):
To minimize the absolute error for inputs between 1 and 2 (they work well enough outside that range, but they may not be the best):
- 0x7EF504F3(无精)
- 0x7EF40D2F(1细化)
- 0x7EF39252(2改进)
三年细化步骤,初始近似值勉强影响最大相对误差。 0x7EEEEEEE的伟大工程,我不能找到更好的东西。
For three refinement steps, the initial approximation barely affects the maximum relative error. 0x7EEEEEEE works great, and I couldn't find anything better.
这篇关于作为师乘法和LUT? /快浮师倒数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!