Jas*_*ker 9 c++ floating-point cout cpu-registers floating-point-precision
所以我有一个看起来像这样的函数:
float function(){
float x = SomeValue;
return x / SomeOtherValue;
}
Run Code Online (Sandbox Code Playgroud)
在某些时候,此函数溢出并返回一个非常大的负值.为了尝试准确地追踪这发生的位置,我添加了一个cout语句,以便函数看起来像这样:
float function(){
float x = SomeValue;
cout << x;
return x / SomeOtherValue;
}
Run Code Online (Sandbox Code Playgroud)
它工作了!当然,我通过使用双重完全解决了这个问题.但我很好奇为什么这个功能在我做的时候能正常工作.这是典型的,还是我错过了其他地方的错误?
(如果有任何帮助,浮点数中存储的值只是一个整数值,而不是一个特别大的值.我只是把它放在一个浮点数中以避免转换.)