java中float的min值为正是为什么? [英] min value of float in java is positive why?

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

问题描述

当我们在java中的任何一个原始类型上使用MIN_VALUE函数时,它为我们提供了该类型的最小值。
BUT
如果是浮动和双倍它返回最小正值虽然float和double也可以有负值。

when we use MIN_VALUE function on either of primitive types in java it give us minimum value possible for that type. BUT in case of float and double it returned minimum positive value though float and double can have negative values also.

推荐答案

MIN_VALUE 告诉你浮点数的准确程度可以得到,但不是它可以代表的数学最小值。他们应该更好地命名...

MIN_VALUE tells you how precise a float can get, but not the mathematical minimum it can represent. They should have named it better...

MAX_VALUE 是浮点数的数学最小值(同样是双数)。

Negative of MAX_VALUE is the mathematical minimum value for floats(same goes for double).

你可以假设这个的原因与数字如何用二进制表示有关:

The reason you can assume this has to do with how numbers are represented in binary:

Java float和double使用符号位表示负值/正值,而不是2的整数补码表示。这意味着它的正负值具有相同的幅度,即。 - (最大正值)=负最大值因此,您不需要为浮点数定义实际的数学最小常量,因为您可以使用正的最大常量来计算负限。对于整数,您需要2个不同的常量来定义最大值/最小值,因为它们以二进制表示,即-max!= min。

Java float and doubles use sign bit to represent negative/positive values as opposed to two's complement representation for integers. This means it's positive and negative value have the same magnitude, ie. -(positive max) = negative max. Therefore you don't need to define an actual mathematical minimum constant for floats because you can just use the positive max constant to figure out the what the negative bound is. For integers, you need 2 different constants defining max/min because of the way they represented in binary, i.e. -max != min.

更多信息http://people.uncw.edu/tompkinsj/133/numbers/Reals.htm

这篇关于java中float的min值为正是为什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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