为什么Double.MIN_VALUE不是负面的 [英] Why is Double.MIN_VALUE in not negative

查看:115
本文介绍了为什么Double.MIN_VALUE不是负面的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

任何人都可以点亮一下为什么 Double.MIN_VALUE 实际上并不是双打可以使用的最小值?这是一个积极的价值,当然双可以是负面的。我知道为什么这是一个有用的数字,但它似乎是一个非常不直观的名字,尤其是当相比 Integer.MIN_VALUE的。调用它 Double.SMALLEST_POSITIVE MIN_INCREMENT 或类似的语义会更清晰。



另外,Double的最小值是多少?它是 -Double.MAX_VALUE ?这个文档似乎没有说。

解决方案

IEEE 754格式为符号保留一位,其余位表示幅度。这意味着它在原点周围是对称的(与整数值相反,它们有一个负值)。因此,最小值与最大值一样,符号位改变,所以 -Double.MAX_VALUE 是最小的您可以使用 double 来表示可能的实际数字。



我想 Double.MAX_VALUE 应该被视为最大值,在这种情况下,只需写入 -Double.MAX_VALUE 即可。这也解释了为什么 Double.MIN_VALUE 是最不正确的值(因为这代表了可能的最小值)。

但是当然,我同意命名有点误导。习惯了 Integer.MIN_VALUE 的含义,当我读到 Double.MIN_VALUE 是可以表示的最小绝对值值。也许他们认为把一个常量代表最小的可能值是多余的,因为它只是一个 MAX_VALUE 之外的 - : - )

(注意,也有 Double.NEGATIVE_INFINITY 但我不理会这个,因为它被视为特殊情况,实际上并不代表任何实际的数字。)

这里是关于这个主题的好文本。


Can anyone shed some light on why Double.MIN_VALUE is not actually the minimum value that Doubles can take? It is a positive value, and a Double can of course be negative.

I understand why it's a useful number, but it seems a very unintuitive name, especially when compared to Integer.MIN_VALUE. Calling it Double.SMALLEST_POSITIVE or MIN_INCREMENT or similar would have clearer semantics.

Also, what is the minimum value that Doubles can take? Is it -Double.MAX_VALUE? The docs don't seem to say.

解决方案

The IEEE 754 format has one bit reserved for the sign and the remaining bits representing the magnitude. This means that it is "symmetrical" around origo (as opposed to the Integer values, which have one more negative value). Thus the minimum value is simply the same as the maximum value, with the sign-bit changed, so yes, -Double.MAX_VALUE is the smallest possible actual number you can represent with a double.

I suppose the Double.MAX_VALUE should be seen as maximum magnitude, in which case it actually makes sense to simply write -Double.MAX_VALUE. It also explains why Double.MIN_VALUE is the least positive value (since that represents the least possible magnitude).

But sure, I agree that the naming is a bit misleading. Being used to the meaning Integer.MIN_VALUE, I too was a bit surprised when I read that Double.MIN_VALUE was the smallest absolute value that could be represented. Perhaps they thought it was superfluous to have a constant representing the least possible value as it is simply a - away from MAX_VALUE :-)

(Note, there is also Double.NEGATIVE_INFINITY but I'm disregarding from this, as it is to be seen as a "special case" and does not in fact represent any actual number.)

Here is a good text on the subject.

这篇关于为什么Double.MIN_VALUE不是负面的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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