两次除以零:为什么结果不一致? [英] Double divide by zero: Why is the result inconsistent?

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

问题描述

为什么会有以下结果:

double a = 0.0/0.0;
double b = 0/0.0;

= NaN

但是结果例如:

double e = 0.1/0.0;
double e = 12.0/0.0;
double f = 1.0/0.0;

= Infinity

我知道 double float 的除法在某种程度上有些不同。我对结果 NaN 感到非常满意,因为当某物除以零时,结果未定义。但是为什么他们定义大于零除以零的结果是 Infitity

I understand that double or float divisions are somehow a little bit different. I am pretty happy with the resulting NaN because the result is not defined when something is divided by zero. But why they defined that the result of something greater than zero divided by zero is Infitity? Has this something todo with the method they use to perform the division of floating points?

推荐答案

还有其他答案可以用来指定浮点数的除法吗?符合标准,因此属于预期行为。您似乎想知道为什么标准如此。我想这是因为某些表达式具有定义明确的限制(例如在微积分中),而有些甚至没有限制。具有明确定义的限制的对象将获得带符号的无穷大(因为这是限制)。像0/0这样的值会获得NaN,因为那里没有限制。 (从左边开始的极限是负无穷大,从右边开始的极限是正无穷大。)在所有情况下,当我说 limit时,我的意思是n / x的极限为x->。 0 ,其中 n 是固定分子。

There are other answers that specify that this is in the standard and therefore "expected" behavior. You seem to want to know why the standard is like that. I would guess that the reason is that some expressions have well-defined limits (as in calculus) and some do not even have a limit. The ones with a well-defined limit get a signed infinity (since that is the limit). The ones like 0/0 get NaN because there is no limit there. (The limit from the left is negative infinity and the limit from the right is positive infinity.) In all cases, when I say "limit", I mean limit of n/x as x -> 0, where n is the fixed numerator.

这篇关于两次除以零:为什么结果不一致?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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