Slight refactoring.
@@ -224,27 +224,27 @@ public class BigFraction extends Number implements Comparable<BigFraction>, Seri
final long exponent = bits & 0x7ff0000000000000L;
final long mantissa = bits & 0x000fffffffffffffL;
- // compute m and k such that value = m * 2^k
+ // Compute m and k such that value = m * 2^k
long m;
int k;
if (exponent != 0) {
- // this was a normalized number, add the implicit most significant bit
+ // Normalized number: Add the implicit most significant bit.
m = mantissa | 0x0010000000000000L;
- k = ((int) (exponent >> 52)) - 1023 - 52;
+ k = ((int) (exponent >> 52)) - 1075; // Exponent bias is 1023.
} else {
m = mantissa;
- if (m == 0) { //number is zero, set k to 0 for simplicity
- k = 0;
- } else {
- // subnormal number, the effective exponent bias is only 1022
- k = - 1022 - 52;
+ k = 0; // For simplicity, when number is 0.
+ if (m != 0) {
+ // Subnormal number, the effective exponent bias is 1022, not 1023.
+ k = -1074;
}
}
if (sign != 0) {
m = -m;
}
- while (((m & 0x001ffffffffffffeL) != 0) && ((m & 0x1) == 0)) {
+ while ((m & 0x001ffffffffffffeL) != 0 &&
+ (m & 0x1) == 0) {
m >>= 1;
++k;
}
@@ -256,7 +256,6 @@ public class BigFraction extends Number implements Comparable<BigFraction>, Seri
numerator = BigInteger.valueOf(m).multiply(BigInteger.ZERO.flipBit(k));
denominator = BigInteger.ONE;
}
-
}
/**
