C 中的 NaN 文字?
如何用 C 语言编写 NaN
浮点文字?
How do you write an NaN
floating-point literal in C?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
如何用 C 语言编写 NaN
浮点文字?
How do you write an NaN
floating-point literal in C?
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(4)
在C99的
中In C99's
<math.h>
5.2.4.2.2/3:
7.12/5(数学.h):
因此,如果您的实现完全支持 NaN,并且如果部分或全部 NaN 是安静的,您就可以获得一个值。如果失败,您就进入了实现定义的领域。
对于其中一些浮点宏,还存在一个轻微的担忧,即编译器前端可能不知道它是否支持该功能,因为它生成的代码可以在架构的多个版本上运行支持情况各不相同。我不知道这是否适用于这个宏,但这是另一种情况,您进入实现定义的领域 - 预处理器可能保守地声称它不支持该功能,而实际上整个实现,就像您一样重新使用它,确实如此。
5.2.4.2.2/3:
7.12/5 (math.h):
So you can get a value if your implementation supports NaNs at all, and if some or all of those NaNs are quiet. Failing that you're into implementation-defined territory.
There's also a slight worry with some of these floating-point macros that the compiler front-end might not know whether it supports the feature or not, because it produces code that can run on multiple versions of an architecture where support varies. I don't know whether that applies to this macro, but it's another situation where you're into implementation-defined territory - the preprocessor might conservatively claim that it doesn't support the feature when actually the implementation as a whole, as you're using it, does.
使用
NAN
更好,但如果您使用的是具有 NaN 的系统,0.0/0.0
是获取 NaN 的简单方法...Using
NAN
is better, but if you're on a system that has NaNs,0.0/0.0
is an easy way to get one...在 C 中,您可以通过以下方式编写 NaN 浮点文字。
请注意,这不是标准方法。在 Microsoft C 上,它工作得很好。
In C you can write a NaN floating point literal in the following way.
Please note that, this is not a standard way. On Microsoft C, it works fine.