相关疑难解决方法(0)

-1.#IND000在Visual Studio调试窗口中的含义是什么?

在Visual Studio 2010监视窗口中,我发现变量的值变为-1.#IND000.这是什么意思?

visual-studio visual-studio-debugging

18
推荐指数
1
解决办法
7346
查看次数

C++如何处理NAN?有标准方式还是编译器依赖?

在需要处理sin(x)/ x函数的程序中,我遇到了NAN问题,我简化了以下代码中的问题:

#include <iostream>
#include <cmath>

int main()
{
    std::cout.precision(15);

    //This line compiles and run in g++, but does not compile in Visual Studio 2013
    std::cout << 0.0/0.0 << std::endl;

    //This line compiles and run in both g++ and VS2013
    std::cout << std::sin(0.0)/0.0 << std::endl;

    return 0;
}
Run Code Online (Sandbox Code Playgroud)

在g ++中,输出为:-nan -nan,在VS2013中,输出为:-1.IND,因为第一行没有编译所以我把它注释掉了.

我的问题是:

  1. 这个'-1.IND'是什么意思?

  2. 似乎NAN处理依赖于编译器,这应该在C++中标准化吗?为什么?

  3. 我用这个hack来处理这个问题:

    double sinc(double x)
    {
        if(x == 0.0)
            return 1.0;
        return std::sin(x)/x;
    }
    
    Run Code Online (Sandbox Code Playgroud)

这是正确的方法吗?

编辑:另一个问题,4.为什么VS2013处理0.0/0.0和sin(0.0)/0.0不同?

c++ floating-point nan

18
推荐指数
2
解决办法
2391
查看次数

精确为零的float/double相等

我有一个使用floatsdoubles执行一些计算的算法.

例:

double a;
double b;
double c;
...
double result = c / (b - a);
if ((result > 0) && (result < small_number))
{
    // result is relevant...
} else {
    // result not required...
}
Run Code Online (Sandbox Code Playgroud)

现在,我担心(b - a)可能是零.如果它接近于零而不是零,则无关紧要,因为result它将超出范围是有用的,并且我已经检测到(当(b - a)接近零时,result将接近+/- inf,这不在范围内0- small_number. ..)

但如果结果(b - a)恰好为零,我预计由于除以零而会发生某种平台依赖.我可以将if声明更改为:

if ((!((b-a) == 0.0)) && ((result = c/(b-a)) > 0) && (result …
Run Code Online (Sandbox Code Playgroud)

c++ floating-point

9
推荐指数
2
解决办法
3万
查看次数

值返回1.#INF000

交集算法不起作用; 其中一个值,tmin评估为1.#INF000- 这意味着什么,为什么会发生?tmax似乎很好.

float Ray::Intersects(BoundingBox boundingBox)
{
// direction is unit direction vector of the ray
D3DXVECTOR3 dirfrac(
    1.0f / direction.x,
    1.0f / direction.y,
    1.0f / direction.z);

D3DXVECTOR3 min = boundingBox.Min();
D3DXVECTOR3 max = boundingBox.Max();

//min and max are the negative and positive corners of the bounding box
float t1 = (min.x - origin.x) * dirfrac.x;
float t2 = (max.x - origin.x) * dirfrac.x;
float t3 = (min.y - origin.y) * dirfrac.y;
float t4 …
Run Code Online (Sandbox Code Playgroud)

c++

3
推荐指数
1
解决办法
4562
查看次数