相关疑难解决方法(0)

std :: isinf不能与-ffast-math一起使用.如何检查无穷大

示例代码:

#include <iostream>
#include <cmath>
#include <stdint.h>

using namespace std;

static bool my_isnan(double val) {
    union { double f; uint64_t x; } u = { val };
    return (u.x << 1) > 0x7ff0000000000000u;
}

int main() {
    cout << std::isinf(std::log(0.0)) << endl;
    cout << std::isnan(std::sqrt(-1.0)) << endl;
    cout << my_isnan(std::sqrt(-1.0)) << endl;
    cout << __isnan(std::sqrt(-1.0)) << endl;

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

在线编译器.

使用-ffast-math,该代码打印"0,0,1,1" - 没有,它打印"1,1,1,1".

那是对的吗?在这些情况下,我认为std::isinf/ std::isnan应该仍然可以使用-ffast-math.

另外,我如何检查无限/ NaN -ffast-math?您可以看到my_isnan这样做,它确实有效,但该解决方案当然非常依赖于架构.另外,为什么在 …

c++ c++-standard-library fast-math

5
推荐指数
1
解决办法
2973
查看次数

标签 统计

c++ ×1

c++-standard-library ×1

fast-math ×1