如何生成NaN的,-Infinity和+无限的ANSI C? [英] How to generate NaN, -Infinity and +Infinity in ANSI C?

查看:153
本文介绍了如何生成NaN的,-Infinity和+无限的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 and INFINITY macros.

From "Mathematics <math.h>" (§7.12) section

The 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屋!

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