给定归一化的浮点数f,f 之后/之前的下一个归一化浮点数是多少.
随着比特twiddling,提取尾数和指数我有:
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
}
Run Code Online (Sandbox Code Playgroud)
但是,这可以通过浮点运算来完成吗?
如
std::numeric_limits<double>::epsilon()
Run Code Online (Sandbox Code Playgroud)
只是1的"邻域"中的误差差异 - 例如:
normalized(d+=std::numeric_limits<double>::epsilon()) = d for d large
Run Code Online (Sandbox Code Playgroud)
它看起来更像错误率而不是错误差异,因此我天真的直觉就是
(1.+std::numeric_limits<double>::epsilon())*f //should be the next.
Run Code Online (Sandbox Code Playgroud)
和
(1.-std::numeric_limits<double>::epsilon())*f //should be the previous.
Run Code Online (Sandbox Code Playgroud)
特别是我有3个问题,任何人都做了以下任何一个(对于IEEE754):
1)对这个问题做了错误分析?
2)证明(或可证明)对于任何标准化的双d
(1.+std::numeric_limits<double>::epsilon())*d != d ?
Run Code Online (Sandbox Code Playgroud)
3)证明对于任何标准化的双数d,不存在双f
d < f < (1.+std::numeric_limits<double>::epsilon())*d ?
Run Code Online (Sandbox Code Playgroud) 我看到一些发布的代码超出范围错误,这让我很奇怪.我希望编译器为此代码生成警告(至少在最高级别)
#pragma warning(push,4)
int main(){
int x[2];
x[2]=0;
return 0;
}
#pragma warning(pop)
Run Code Online (Sandbox Code Playgroud)
但事实并非如此.
EDG编译器很好地说:
"sourceFile.cpp", line 3: warning:
subscript out of range
x[2]=0;
^
Run Code Online (Sandbox Code Playgroud)
实际上EDG说的更多(所有这些都是预期的)
"sourceFile.cpp", line 1: warning:
unrecognized #pragma
#pragma warning(push,4)
^
"sourceFile.cpp", line 4: warning:
subscript out of range
x[2]=0;
^
"sourceFile.cpp", line 3: warning:
variable "x" was set but never used
int x[2];
^
"sourceFile.cpp", line 7: warning:
unrecognized #pragma
#pragma warning(pop)
Run Code Online (Sandbox Code Playgroud)
但这不是我的问题.
我认为这个失败警告VC9中遗漏的严重错误,(因为自动变量!!!!).任何人都可以给我一个改变主意的严肃理由吗?