Java Float.POSITIVE_无穷大==?

Java Float.POSITIVE_无穷大==?,java,floating-point,Java,Floating Point,你是如何用任何其他方式写浮点正无穷大的 //答案必须具有平衡的父项,并且不能使用“Float”或“Double” 公开课练习{ 公共静态void main(字符串[]arg){ 断言(Float.POSITIVE_INFINITY==[?]); } } 通常您应该更喜欢使用该方法 Float.isInfinite() 您可以查看java.lang.Float中这些值是如何设置的。您可以在Double中找到相同的设置。注意十六进制浮点值的使用,例如0x1.fffff ep+127f /** *

你是如何用任何其他方式写浮点正无穷大的

//答案必须具有平衡的父项,并且不能使用“Float”或“Double”
公开课练习{
公共静态void main(字符串[]arg){
断言(Float.POSITIVE_INFINITY==[?]);
}
}

通常您应该更喜欢使用该方法

Float.isInfinite()

您可以查看java.lang.Float中这些值是如何设置的。您可以在
Double
中找到相同的设置。注意十六进制浮点值的使用,例如
0x1.fffff ep+127f

/**
 * A constant holding the positive infinity of type
 * {@code float}. It is equal to the value returned by
 * {@code Float.intBitsToFloat(0x7f800000)}.
 */
public static final float POSITIVE_INFINITY = 1.0f / 0.0f;

/**
 * A constant holding the negative infinity of type
 * {@code float}. It is equal to the value returned by
 * {@code Float.intBitsToFloat(0xff800000)}.
 */
public static final float NEGATIVE_INFINITY = -1.0f / 0.0f;

/**
 * A constant holding a Not-a-Number (NaN) value of type
 * {@code float}.  It is equivalent to the value returned by
 * {@code Float.intBitsToFloat(0x7fc00000)}.
 */
public static final float NaN = 0.0f / 0.0f;

/**
 * A constant holding the largest positive finite value of type
 * {@code float}, (2-2<sup>-23</sup>)&middot;2<sup>127</sup>.
 * It is equal to the hexadecimal floating-point literal
 * {@code 0x1.fffffeP+127f} and also equal to
 * {@code Float.intBitsToFloat(0x7f7fffff)}.
 */
public static final float MAX_VALUE = 0x1.fffffeP+127f; // 3.4028235e+38f

/**
 * A constant holding the smallest positive normal value of type
 * {@code float}, 2<sup>-126</sup>.  It is equal to the
 * hexadecimal floating-point literal {@code 0x1.0p-126f} and also
 * equal to {@code Float.intBitsToFloat(0x00800000)}.
 *
 * @since 1.6
 */
public static final float MIN_NORMAL = 0x1.0p-126f; // 1.17549435E-38f

/**
 * A constant holding the smallest positive nonzero value of type
 * {@code float}, 2<sup>-149</sup>. It is equal to the
 * hexadecimal floating-point literal {@code 0x0.000002P-126f}
 * and also equal to {@code Float.intBitsToFloat(0x1)}.
 */
public static final float MIN_VALUE = 0x0.000002P-126f; // 1.4e-45f
/**
*保持类型正无穷大的常数
*{@code float}。它等于返回的值
*{@code Float.intBitsToFloat(0x7f800000)}。
*/
公共静态最终浮点正无穷大=1.0f/0.0f;
/**
*保持类型负无穷大的常数
*{@code float}。它等于返回的值
*{@code Float.intBitsToFloat(0xff800000)}。
*/
公共静态最终浮点负无穷大=-1.0f/0.0f;
/**
*包含类型为的非数字(NaN)值的常量
*{@code float}。它相当于
*{@code Float.intBitsToFloat(0x7fc00000)}。
*/
公共静态最终浮点NaN=0.0f/0.0f;
/**
*一个常数,其中包含类型的最大正有限值
*{@code float},(2-2-23)和middot;2127
*它等于十六进制浮点文字
*{@code 0x1.FFFFF EP+127f},也等于
*{@code Float.intBitsToFloat(0x7f7fffff)}。
*/
公共静态最终浮点最大值=0x1.FFFFF EP+127f;//3.4028235e+38f
/**
*一个常数,保持类型的最小正正常值
*{@code float},2-126。它等于
*十六进制浮点文字{@code 0x1.0p-126f}以及
*等于{@code Float.intBitsToFloat(0x00800000)}。
*
*@自1.6
*/
公共静态最终浮点最小值正常=0x1.0p-126f;//1.17549435E-38f
/**
*包含类型的最小正非零值的常数
*{@code float},2-149。它等于
*十六进制浮点文字{@code 0x0.000002P-126f}
*也等于{@code Float.intBitsToFloat(0x1)}。
*/
公共静态最终浮点最小值=0x0.000002P-126f;//1.4e-45f

尝试Float.MAX_VALUE+或*2.0
不要使用“Float”或“Double”
-所以你不能使用这些类?Yell,你可以用
100000000000000000000000…
替换
,这将无限期地持续下去。可能需要一段时间。但更严重的是,为什么要这样做?请查看
Float上的JavaDoc。正无穷大
:“它等于Float.intBitsToFloat(0x7f800000)”返回的值。现在玩这个。哦,好的,非常感谢!