为什么0除以0是错误? [英] Why is 0 divided by 0 an error?

查看:264
本文介绍了为什么0除以0是错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的代码中进行的计算中遇到了这个问题,如果除数也为0,则除数为0.在我的代码中,对于这种情况,我返回0.我想知道,虽然通常不定义除以零的原因,但为什么不对这种情况作例外处理呢?我的理解为何除以零是不确定的,基本上是因为它不能逆转.但是,在0/0的情况下,我看不到此问题.

I have come across this problem in a calculation I do in my code, where the divisor is 0 if the divident is 0 too. In my code I return 0 for that case. I am wondering, while division by zero is generally undefined, why not make an exception for this case? My understanding why division by zero is undefined is basically that it cannot be reversed. However, I do not see this problem in the case 0/0.

编辑好,所以这个问题引发了很多讨论.我犯了一个错误,因为它获得了很多选票,所以过分地接受了答案.我现在接受了 AakashM的答案,因为它提供了有关如何分析问题的想法.

EDIT OK, so this question spawned a lot of discussion. I made the mistake of over-eagerly accepting an answer based on the fact that it received a lot of votes. I now accepted AakashM's answer, because it provides an idea on how to analyze the problem.

推荐答案

这是数学而非编程,但要简要介绍一下:

This is maths rather than programming, but briefly:

  • 从某种意义上说,为some-strictly-positive-quantity / 0分配正无穷大的值"是合理的,因为限制是明确定义的

  • It's in some sense justifiable to assign a 'value' of positive-infinity to some-strictly-positive-quantity / 0, because the limit is well-defined

但是,x / y的极限值xy都趋于零取决于它们采取的路径.例如,lim (x -> 0) 2x / x显然是2,而lim (x -> 0) x / 5x显然是1/5.极限的数学定义要求无论遵循什么路径到达极限.

However, the limit of x / y as x and y both tend to zero depends on the path they take. For example, lim (x -> 0) 2x / x is clearly 2, whereas lim (x -> 0) x / 5x is clearly 1/5. The mathematical definition of a limit requires that it is the same whatever path is followed to the limit.

这篇关于为什么0除以0是错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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