floating-point - 标准化 float f之后(之前)的下一个标准化 float 是什么?

标签 floating-point

给定归一化的浮点数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/

相关文章:

cuda - 在 CUDA 中获取浮点特殊值的方法?

javascript - Math.cos 不准确

javascript - 如何从 float 中 chop 多余的零

python - 创建一个程序,返回超过非负整数 n 的最小立方体

Python(奇怪地)四舍五入值

perl - 如何修复此 Perl 代码,使 1.1 + 2.2 == 3.3?

math - float 学有问题吗?

c - 如何在 C 中读取二进制文件并将输出显示为 float ?

python - python/numpy 中的 float 学不能跨机器重现

c++ - float 和整数歧义