A few things about division by zero in C(关于 C 中除以零的一些事情)
问题描述
可能的重复:
返回值 1.#INF000 
我一直认为除以 0 会导致编译后的程序崩溃
I always thought division by 0 would result in a compiled program crashing
但是我今天发现(使用 VC++ 2010 Express)除以 0 给出了一个叫做 1.#INF000 的东西,它应该是正无穷大
However I discovered today (using VC++ 2010 Express) that division by 0 gives something called 1.#INF000 and it is supposed to be positive infinity
当它被传递给一个函数时,它被传递为 -1.#IND000
When it was passed to a function, it got passed as -1.#IND000
这是怎么回事?
在 google 上搜索 1.#INF000 和 -1.#IND000 也没有提供任何明确的解释
Searching 1.#INF000 and -1.#IND000 on google do not provide any clear explanations either
它只是 VC++ 特有的东西吗?
Is it just something specific to VC++ ?
推荐答案
浮点数除以零与整数除以零的行为不同.
Floating point division by zero behaves differently than integer division by zero.
IEEE 浮点标准区分+inf 和-inf,而整数不能存储无穷大.整数除以零会导致未定义的行为.浮点除以零由浮点标准定义,结果为 +inf 或 -inf.
The IEEE floating point standard differentiates between +inf and -inf, while integers cannot store infinity. Integer division by zero results in undefined behaviour. Floating point division by zero is defined by the floating point standard and results in +inf or -inf.
正如 Luchian 所指出的,C++ 实现不需要遵循 IEEE 浮点标准.如果您使用的实现不遵循 IEEE 浮点标准,则浮点除以零的结果未定义.
As pointed out by Luchian, C++ implementations are not required to follow the IEEE Floating point standard. If the implementation you use doesn't follow the IEEE Floating point standard the result of floating point division by zero is undefined.
这篇关于关于 C 中除以零的一些事情的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:关于 C 中除以零的一些事情
 
				
         
 
            
        基础教程推荐
- 如何检查GTK+3.0中的小部件类型? 2022-11-30
- 我有静态或动态 boost 库吗? 2021-01-01
- 如何在 C++ 中初始化静态常量成员? 2022-01-01
- 常量变量在标题中不起作用 2021-01-01
- 静态库、静态链接动态库和动态链接动态库的 .lib 文件里面是什么? 2021-01-01
- C++结构和函数声明。为什么它不能编译? 2022-11-07
- 如何通过C程序打开命令提示符Cmd 2022-12-09
- 如何将 std::pair 的排序 std::list 转换为 std::map 2022-01-01
- 在 C++ 中计算滚动/移动平均值 2021-01-01
- 这个宏可以转换成函数吗? 2022-01-01
 
    	 
    	 
    	 
    	 
    	 
    	 
    	 
    	 
						 
						 
						 
						 
						 
				 
				 
				 
				