给定归一化的浮点数f,在f之前/之后的下一个归一化浮点数是多少。
通过微动,提取尾数和指数,我得到了:
next_normalized(double&){
if mantissa is not all ones
maximally denormalize while maintaining equality
add 1 to mantissa
normalize
else
check overflow
set mantissa to 1
add (mantissa size in bits) to exponent.
endif
}
但是不是用浮点运算就能做到吗?
作为
std::numeric_limits<double>::epsilon()
只是“邻居”为1时的错误差异。-例如:
normalized(d+=std::numeric_limits<double>::epsilon()) = d for d large
看起来错误率比错误差更大,因此我的天真直觉是
(1.+std::numeric_limits<double>::epsilon())*f //should be the next.
和
(1.-std::numeric_limits<double>::epsilon())*f //should be the previous.
特别是我有3个问题,是否有人做过以下任何一项(针对IEEE754):
1)对此问题进行了错误分析?
2)证明(或可以证明)对于任何归一化 double d
(1.+std::numeric_limits<double>::epsilon())*d != d ?
3)证明对于任何归一化 double 数d都不存在 double f
d < f < (1.+std::numeric_limits<double>::epsilon())*d ?
最佳答案
我不确定“归一化 double 数”是什么意思,但是在大多数C标准数学库中,要使用下一个可表示的 double 数是通过 nextafter()
function完成的。
关于floating-point - 标准化 float f之后(之前)的下一个标准化 float 是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1336767/