c++ - 错误 : non-floating-point argument in call to function ‘__builtin_isnan’

标签 c++

#include <stdio.h>      
#include <math.h>       

int main()

{

    //  printf ("isnan(0.0)       : %d\n",isnan(0.0));

    //  printf ("isnan(1.0/0.0)   : %d\n",isnan(1.0/0.0));

    //  printf ("isnan(-1.0/0.0)  : %d\n",isnan(-1.0/0.0));

    //  printf ("isnan(sqrt(-1.0)): %d\n",isnan(sqrt(sqrt(-1.0))));

    //  printf ("isnan(sqrt(-1.0)): %d\n",isnan(sqrt(floor(-1.0))));

    //  printf ("isnan(-1.0/0.0)): %d\n",isnan(-1.0/0.0));

    //  printf ("isnan(sqrt(-1.0)): %d\n",isnan(sqrt(floor(sqrt(-1.0)))));

    printf ("isnan(1/0): %d\n",isnan(1/0));

    //  printf ("isnan(sqrt(-1.0)): %d\n",isnan(sqrt(-1/0)));

    return 0;
}

我遇到了这个错误:

snann.c:23:28: error: non-floating-point argument in call to function ‘__builtin_isnan’
 printf ("isnan(1/0): %d\n",isnan(1/0));

问题是什么?

isnan 可以很好地处理其他输入(我评论过的那些)。

我需要解决这个问题,因为我在编译GNSS-R软件时,也遇到了这个错误。

欢迎提出任何建议。

最佳答案

问题是您向 isnan 提供了一个非浮点参数,正如它所说。

当我们翻到 the documentation ,我们看到:

Determines [whether] the given floating point number arg is a not-a-number (NaN) value. The macro returns an integral value.

1是一个整数,0是一个整数,所以1/0是一个整数。

所以,您使用的宏错误,如果 GNSS-R 执行 isnan(1/0),那么 GNSS-R 也是错误的。

实际上,由于整数除以零,您的整个程序的行为是未定义的,但这是另一个问题!

关于c++ - 错误 : non-floating-point argument in call to function ‘__builtin_isnan’ ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50153410/

相关文章:

c++ - 创建双向本地/Unix 套接字

c++ - 数组的名称是右值吗?

c++ - 有没有办法从 sqlite3 对象获取数据库位置?

c++ - SDL:延迟直到键盘输入

当通过其中一个删除对象时,C++ 将所有指针设置为 null

C++:值的名称可能有链接

c++ - 如何从 openMP (C++) 中的线程生成子线程

c++ - 使用 OpenGL 无法正确显示三角形带

c++ - 在 C++ 中为类创建 [][] 运算符

c++ - 多次包含cpp文件