彻底理解byte,double,float变量范围
在这里我们只谈论 java中的数值类型
首先说byte:
这段是摘自jdk中 Byte.java中的源代码:
/** * A constant holding the minimum value a <code>byte</code> can * have, -2<sup>7</sup>. */ public static final byte MIN_VALUE = -128; /** * A constant holding the maximum value a <code>byte</code> can * have, 2<sup>7</sup>-1. */ public static final byte MAX_VALUE = 127;
System.out.println(Byte.MAX_VALUE); //最大值 System.out.println(Byte.MIN_VALUE); //最小值
/** * The constant value of this field is the smallest value of type * <code>char</code>, <code>'\u0000'</code>. * * @since 1.0.2 */ public static final char MIN_VALUE = '\u0000'; /** * The constant value of this field is the largest value of type * <code>char</code>, <code>'\uFFFF'</code>. * * @since 1.0.2 */ public static final char MAX_VALUE = '\uffff';
/** * A constant holding the largest positive finite value of type * <code>float</code>, (2-2<sup>-23</sup>)·2<sup>127</sup>. * It is equal to the hexadecimal floating-point literal * <code>0x1.fffffeP 127f</code> and also equal to * <code>Float.intBitsToFloat(0x7f7fffff)</code>. */ public static final float MAX_VALUE = 3.4028235e 38f; // 0x1.fffffeP 127f/** * A constant holding the smallest positive nonzero value of type * <code>float</code>, 2<sup>-149</sup>. It is equal to the * hexadecimal floating-point literal <code>0x0.000002P-126f</code> * and also equal to <code>Float.intBitsToFloat(0x1)</code>. */
public static final float MIN_VALUE = 1.4e-45f; // 0x0.000002P-126f
/** * A constant holding the largest positive finite value of type * <code>double</code>, * (2-2<sup>-52</sup>)·2<sup>1023</sup>. It is equal to * the hexadecimal floating-point literal * <code>0x1.fffffffffffffP 1023</code> and also equal to * <code>Double.longBitsToDouble(0x7fefffffffffffffL)</code>. */public static final double MAX_VALUE = 1.7976931348623157e 308; // 0x1.fffffffffffffP 1023/** * A constant holding the smallest positive nonzero value of type * <code>double</code>, 2<sup>-1074</sup>. It is equal to the * hexadecimal floating-point literal * <code>0x0.0000000000001P-1022</code> and also equal to * <code>Double.longBitsToDouble(0x1L)</code>. */
public static final double MIN_VALUE = 4.9e-324; // 0x0.0000000000001P-1022