How to check if C++ compiler uses IEEE 754 floating point standard(如何检查 C++ 编译器是否使用 IEEE 754 浮点标准)
问题描述
我想问一个这个之后的问题定义检查编译器是否使用标准很好地回答了.但是,这仅适用于 C.有没有办法在 C++ 中做同样的事情?
I would like to ask a question that follows this one which is pretty well answered by the define check if the compiler uses the standard. However this woks for C only. Is there a way to do the same in C++?
我不希望将浮点类型转换为文本或使用一些相当复杂的转换函数.我只需要编译器检查.如果您知道此类兼容编译器的列表,请发布链接.没找到.
I do not wish to covert floating point types to text or use some pretty complex conversion functions. I just need the compiler check. If you know a list of such compatible compilers please post the link. I could not find it.
推荐答案
其实你有一个更简单的方法可以在 C++ 中实现这一点.从 C++ 标准 18.2.1.1
开始,numeric_limits
类存在于 std
中.为了访问所述静态成员,您只需执行以下操作:
Actually you have an easier way to achieve this in C++. From the C++ standard 18.2.1.1
the class numeric_limits
exists within std
. In order to access said static member you simply do this:
std::numeric_limits<double>::is_iec559;
或者:
std::numeric_limits<float>::is_iec559;
如果正在使用 IEEE 754,则应该返回 true
,否则返回 false.
Which should return true
if IEEE 754 is in use, false otherwise.
作为替代方法,亚当的回答的第二部分a> 对于 C++ 也应该这样做.
As an alternative method, the second part of Adam's answer should do it also for C++.
这篇关于如何检查 C++ 编译器是否使用 IEEE 754 浮点标准的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何检查 C++ 编译器是否使用 IEEE 754 浮点标准


- 将函数的返回值分配给引用 C++? 2022-01-01
- XML Schema 到 C++ 类 2022-01-01
- GDB 不显示函数名 2022-01-01
- DoEvents 等效于 C++? 2021-01-01
- 使用 __stdcall & 调用 DLLVS2013 中的 GetProcAddress() 2021-01-01
- 将 hdc 内容复制到位图 2022-09-04
- 如何提取 __VA_ARGS__? 2022-01-01
- OpenGL 对象的 RAII 包装器 2021-01-01
- 哪个更快:if (bool) 或 if(int)? 2022-01-01
- 从父 CMakeLists.txt 覆盖 CMake 中的默认选项(...)值 2021-01-01