如何生成NaN的,-Infinity和+无限的ANSI C? [英] How to generate NaN, -Infinity and +Infinity in ANSI C?
问题描述
我用ANSI C89(不是C ++),我想生成NaN的,-Infinity和+无限。
有没有什么标准的方法(如标准宏)?
或者是有产生这些数字的任何平台和编译器无关的方式?
浮动F = 0.0 / 0.0; //总是f由于任何平台喃?
有在C99,但不是在previous标准AFAIK。
在C99,你就会有 NAN
和 INFINITY
宏。
从数学<&math.h中GT;
(§7.12)栏目
宏 INFINITY 扩展到float类型重新presenting的恒定前pression正面或无穷大符号(如有); ...
块引用>如果你坚持ANSI C89,你的运气了。请参见 C-FAQ 14.9 。
I use ANSI C89 (not C++), and I want to generate NaN, -Infinity and +Infinity.
Is there any standard way (eg. standard macro)? Or is there any platform and compiler independent way to generate these numbers?
float f = 0.0 / 0.0; // Is f ALWAYS in any platform is NaN?
解决方案There is in C99, but not in previous standards AFAIK.
In C99, you'll have
NAN
andINFINITY
macros.From "Mathematics
<math.h>
" (§7.12) sectionThe macro INFINITY expands to a constant expression of type float representing positive or unsigned infinity, if available; ...
If you're stuck with ANSI C89, you're out of luck. See C-FAQ 14.9.
这篇关于如何生成NaN的,-Infinity和+无限的ANSI C?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!