如何检查C ++编译器是否使用IEEE 754浮点标准 [英] How to check if C++ compiler uses IEEE 754 floating point standard

查看:252
本文介绍了如何检查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 ++。从标准 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

Which should return true if IEEE 754 is in use, false otherwise.

作为替代方法, Adam的回答也应该为C ++做。

As an alternative method, the second part of Adam's answer should do it also for C++.

这篇关于如何检查C ++编译器是否使用IEEE 754浮点标准的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆