STD :: FPCLASSIFY的错误结果使用Valgrind进行长时间的双重双重结果
Wrong result of std::fpclassify for long double using Valgrind
i以奇怪的行为碰到。在此程序中,我尝试检查是浮点值等于零:
#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 :
此处可用的程序的源代码。
构建选项:g++ main.cpp -O0 -o llvlg
。
我的环境:
$ uname -a Linux tiptop 4.8.0-53-generic #56-Ubuntu SMP Tue May 16 00:23:44 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux
$ gcc --version gcc (Ubuntu 6.2.0-5ubuntu12) 6.2.0 20161005
$ valgrind --version valgrind-3.12.0.SVN
$ cat /proc/cpuinfo ... model name : Intel(R) Core(TM) i7-4700MQ CPU @ 2.40GHz ...
这是带有Valgrind的预期行为 - 已知的限制。内部长双重只用64位(双重(精度表示。
请参阅此处。
相关文章:
- 使用Boost Interprocess创建托管共享内存需要很长时间
- SFML RenderWindow打开窗口需要很长时间
- Kafka C++客户端需要很长时间才能收到消息
- 给定使用 C++ 或 C,我如何测量在 linux 下进行线程切换需要多长时间?可能吗?
- asio::read() 需要很长时间,使用 asio::write 没有问题
- 将线程锁定很长时间
- 正在等待在非阻塞文件描述符上长时间运行ioctl
- 即使长时间等待,C++线程也不会加入
- 连接() 在连接被拒绝时长时间挂起
- 为什么这段代码需要这么长时间才能用 g++ 编译?
- 如何在长时间运行的方法中等待信号?
- mbed 套接字连接需要很长时间
- Lambda 捕获此函数和长时间运行的函数
- 以相同的结果测量时间
- std::fstream 需要很长时间才能将大数据写入.csv文件中
- 为什么与Java和Python相比,使用Cmake运行C++程序每次都需要这么长时间?
- 需要很长时间
- 在关闭应用程序期间正确关闭线程,该线程可能会运行很长时间的循环
- 如何在长时间计算中进行C 的一次进度更新
- 使用std::chrono计算持续时间,当它应该花费很长时间时,结果是0纳秒