std::fpclassify for long double 使用 Valgrind 的错误结果

Wrong result of std::fpclassify for long double using Valgrind

我遇到了奇怪的行为。在这个程序中,我尝试检查浮点值是否等于零:

#include <cstdlib>
#include <cmath>
#include <iostream>

int main ()
{
    float       fa (0), fb (0);
    double      da (0), db (0);
    long double la (0), lb (0);

    cout << "Float:       " << (FP_ZERO == fpclassify (fa - fb) ) << endl;
    cout << "Double:      " << (FP_ZERO == fpclassify (da - db) ) << endl;
    cout << "Long double: " << (FP_ZERO == fpclassify (la - lb) ) << endl;
    cout << "Float:       " << (FP_ZERO == fpclassify (fa - 42) ) << endl;
    cout << "Double:      " << (FP_ZERO == fpclassify (da - 42) ) << endl;
    cout << "Long double: " << (FP_ZERO == fpclassify (la - 42) ) << endl;

    return EXIT_SUCCESS;
}

程序的结果是可以预见的:

$ ./llvlg 
Float:       1
Double:      1
Long double: 1
Float:       0
Double:      0
Long double: 0

但是如果我通过 Valgrind 启动程序,长双零的结果将是错误的:

$ valgrind ./llvlg 
==7521== Memcheck, a memory error detector
==7521== Copyright (C) 2002-2015, and GNU GPL'd, by Julian Seward et al.
==7521== Using Valgrind-3.12.0.SVN and LibVEX; rerun with -h for copyright info
==7521== Command: ./llvlg
==7521== 
Float:       1
Double:      1
Long double: 0
Float:       0
Double:      0
Long double: 0
==7521== 
==7521== HEAP SUMMARY:
==7521==     in use at exit: 0 bytes in 0 blocks
==7521==   total heap usage: 2 allocs, 2 frees, 73,728 bytes allocated
==7521== 
==7521== All heap blocks were freed -- no leaks are possible
==7521== 
==7521== For counts of detected and suppressed errors, rerun with: -v
==7521== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)

这是错误还是预期行为?

UPD:
可用的程序源代码 here.
构建选项:g++ main.cpp -O0 -o llvlg.
我的环境:

这是 Valgrind 的预期行为 - 一个已知限制。内部 long double 仅以 64 位(双)精度表示。

here