.NET 是否有内置方法来计算 ULP给定的 double 型或浮点型?
如果没有,最有效的方法是什么?
最佳答案
看起来这个功能很简单;这是基于 vulkanino 链接问题的接受答案中的伪代码:
double value = whatever;
long bits = BitConverter.DoubleToInt64Bits(value);
double nextValue = BitConverter.Int64BitsToDouble(bits + 1);
double result = nextValue - value;
对于 float ,您需要提供自己的 SingleToInt32Bits
和 Int32BitsToSingle
实现,因为 BitConverter 没有这些函数。
This page显示该函数的 java 实现中的特殊情况;处理这些也应该相当简单。
关于c# - 计算 double 最后一位的单位 (ULP),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62283029/