gnu-c 对浮点型数据除0.0的处理
来源:互联网 发布:分享wifi的软件 编辑:程序博客网 时间:2024/06/01 11:45
程序中有分母为 0 的情况发生,确切的说是 (double) 强制转换后的 浮点 0.0,结果发现输出的结果是 inf,即对于 如 1/(double)0的情形是 inf,而 如 0/(double)0 的情形是 -nan。inf 在比较时作为 正无穷 ∞ 处理,而 -nan 不可比较。
gcc c lib 手册 如下:
20.5.2 Infinity and NaN
IEEE 754 floating point numbers can represent positive or negative infinity, and NaN (not a number). These three values arise from calculations whose result is undefined or cannot be represented accurately. You can also deliberately set a floating-point variable to any of them, which is sometimes useful. Some examples of calculations that produce infinity or NaN:
1/0 = ∞
log (0) = -∞
sqrt (-1) = NaN
When a calculation produces any of these values, an exception also occurs; see FP Exceptions.The basic operations and math functions all accept infinity and NaN and produce sensible output. Infinities propagate through calculations as one would expect: for example, 2 + ∞ = ∞, 4/∞ = 0, atan (∞) = π/2. NaN, on the other hand, infects any calculation that involves it. Unless the calculation would produce the same result no matter what real value replaced NaN, the result is NaN.
In comparison operations, positive infinity is larger than all values except itself and NaN, and negative infinity is smaller than all values except itself and NaN. NaN is unordered: it is not equal to, greater than, or less than anything, including itself. x == x is false if the value of x is NaN. You can use this to test whether a value is NaN or not, but the recommended way to test for NaN is with the isnan function (see Floating Point Classes). In addition, <, >, <=, and >= will raise an exception when applied to NaNs.
math.h defines macros that allow you to explicitly set a variable to infinity or NaN.
Macro: float INFINITY
An expression representing positive infinity. It is equal to the value produced by mathematical operations like 1.0 / 0.0. -INFINITY represents negative infinity.You can test whether a floating-point value is infinite by comparing it to this macro. However, this is not recommended; you should use the isfinite macro instead. See Floating Point Classes.
This macro was introduced in the ISO C99 standard.
[1] https://www.gnu.org/software/libc/manual/html_node/Infinity-and-NaN.html
- gnu-c 对浮点型数据除0.0的处理
- java.math.BigDecimal 对浮点数据的精度处理
- GNU对C的扩展
- java 处理浮点型数据的显示
- GNU C 对标C的扩展
- 通过c/c++对除零代码的处理,看异常处理方法
- 串口处理浮点型数据
- X64对浮点参数的处理
- OpenCV 从浮点型数据的视差图中分割并滤除小的斑块
- C++、MATLAB 两个数值相除,取结果的余数、整除数部分 MATLAB两整数相除结果为整型、浮点型
- C语言的数据类型→浮点型数据
- objective-c浮点数相除
- 2.2.2 GNU C对标准C语言的扩展
- 两个整数相除转浮点型变量/浮点型变量的输出
- C复习笔记(浮点型数据)
- C语言浮点型数据存储结构
- 浮点型数据的转换
- vs2010对浮点数的处理埋下的坑
- 字符串方法的扩展
- Java Timer和TimerTask详解
- 欢迎使用CSDN-markdown编辑器
- [leetcode]: 121. Best Time to Buy and Sell Stock
- 仿天猫网站开发笔记4:将Django模板变量传递给外部js调用的方案
- gnu-c 对浮点型数据除0.0的处理
- c++关于结构体动态链表初始化添加删除操作代码
- SpringMVC使用了@ResponseBody报406错误的问题
- Machine Learning Class 1:Introduction,supervised & unsupervised learning
- PC端微信缓存清理方法
- vim C/C++常用配置
- 小知识-绊倒大部分人-持续更新
- 编程总结
- 23---DNS & BIND