inttadd_ok(int x, int y) { int sum = x + y; int pos_of = x >= 0 && y >= 0 && sum < 0, neg_of = x < 0 && y < 0 && sum >= 0; return !pos_of && !neg_of; }
这里只用 >= 0 和 < 0,只需取 int 符号位即可判断,不需要其他位。
2.3.3 补码的非
原理:补码的非:
对满足 的 ,其补码的非
计算补码位级表示的非的几种方法:
对每一位取反,再对结果加 1。在 C 语言中,对于任意整数值 x,-x 和 ~x + 1 的结果完全一样
publicfinalclassFloatextendsNumberimplementsComparable<Float> { /** * A constant holding the positive infinity of type * {@code float}. It is equal to the value returned by * {@code Float.intBitsToFloat(0x7f800000)}. */ publicstaticfinalfloat 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)}. */ publicstaticfinalfloat 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)}. */ publicstaticfinalfloat NaN = 0.0f / 0.0f;
/** * A constant holding the largest positive finite value of type * {@code float}, (2-2<sup>-23</sup>)·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)}. */ publicstaticfinalfloat 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 */ publicstaticfinalfloat 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)}. */ publicstaticfinalfloat MIN_VALUE = 0x0.000002P-126f; // 1.4e-45f
近期评论