用C约分工有几件事情是零 [英] A few things about division by zero in C

查看:83
本文介绍了用C约分工有几件事情是零的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能重复:结果
  值返回1#INF000

我按0一直以为师将导致编译的程序崩溃

I always thought division by 0 would result in a compiled program crashing

不过我今天发现(使用VC ++ 2010防爆preSS)被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

这是什么回事?

搜索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约分工有几件事情是零的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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