使用.NET 3中的硬件内部函数,我意识到:
float a = ..;
float b = 1f / a;
不能严格地产生与相同的数值结果
Vector256<float> a = ..;
Vector256<float> b = Avx.Reciprocal(a);
结果在数值上很接近,但并不完全相同。相反,为了保持代码的float
和Vector256<float>
变体之间的等效性,需要编写以下内容:
Vector256<float> a = ..;
Vector256<float> b = Avx.Divide(Vector256.Create(1f), a);
如何重现Avx.倒数((的严格标量等价物?
在.NET 6中,您可以使用MathF.倒数估计https://learn.microsoft.com/en-us/dotnet/api/system.mathf.reciprocalestimate?view=net-6.0