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

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

问题描述

谁能解释为什么 Double.MIN_VALUE 实际上不是 Doubles 可以取的最小值?它是一个正值,Double 当然可以是负值.

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.

我理解为什么它是一个有用的数字,但它似乎是一个非常不直观的名称,尤其是与 Integer.MIN_VALUE 相比时.将其称为 Double.SMALLEST_POSITIVEMIN_INCREMENT 或类似名称会具有更清晰的语义.

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.

另外,双打可以取的最小值是多少?是 -Double.MAX_VALUE 吗?文档似乎没有说.

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

推荐答案

IEEE 754 格式保留一位用于符号,其余位表示幅度.这意味着它围绕 origo 是对称的"(与整数值相反,后者还有一个负值).因此,最小值与最大值相同,符号位已更改,因此-Double.MAX_VALUE 是您可以表示的最小可能实际数字带有 double.

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.

我认为 Double.MAX_VALUE 应该被视为最大幅度,在这种情况下,简单地编写 -Double.MAX_VALUE 实际上是有意义的>.它还解释了为什么 Double.MIN_VALUE 是最小的正值(因为它代表了最小可能的幅度).

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).

但可以肯定,我同意命名有点误导.习惯了 Integer.MIN_VALUE 的含义,当我读到 Double.MIN_VALUE 是最小的绝对值时,我也有点惊讶被代表.也许他们认为拥有一个代表最小可能值的常量是多余的,因为它只是一个 - 远离 MAX_VALUE :-)

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 :-)

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

(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天全站免登陆