Skip to content

Commit d9e9763

Browse files
committed
Correct rounding, improve FastRandom, and fix style and documentation
1 parent 469ea9f commit d9e9763

16 files changed

+3348
-2936
lines changed

src/main/java/com/upokecenter/cbor/CBORObject.java

Lines changed: 70 additions & 73 deletions
Large diffs are not rendered by default.

src/main/java/com/upokecenter/cbor/URIUtility.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -553,8 +553,7 @@ private static int parseDecOctet(
553553
return ((c - '0') * 10) + (s.charAt(index + 1) - '0');
554554
}
555555
if (c == '2' && index + 3 < endOffset &&
556-
(s.charAt(index + 1) == '5') && (s.charAt(index + 2) >= '0' && s.charAt(index + 2) <= '5'
557-
) &&
556+
(s.charAt(index + 1) == '5') && (s.charAt(index + 2) >= '0' && s.charAt(index + 2) <= '5') &&
558557
s.charAt(index + 3) == delim) {
559558
return 250 + (s.charAt(index + 2) - '0');
560559
}

src/main/java/com/upokecenter/util/BigInteger.java

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2134,15 +2134,13 @@ private static short DivideThreeWordsByTwo(
21342134
short valueQ;
21352135
{
21362136
valueQ = ((short)(valueB1 + 1) == 0) ? words1[words1Start + 2] :
2137-
(
2138-
(
2139-
valueB1 != 0) ? DivideUnsigned(
2140-
MakeUint(
2141-
words1[words1Start + 1],
2142-
words1[words1Start + 2]),
2143-
(short)(((int)valueB1 + 1) & 0xffff)) : DivideUnsigned(
2144-
MakeUint(words1[words1Start], words1[words1Start + 1]),
2145-
valueB0));
2137+
((valueB1 != 0) ? DivideUnsigned(
2138+
MakeUint(
2139+
words1[words1Start + 1],
2140+
words1[words1Start + 2]),
2141+
(short)(((int)valueB1 + 1) & 0xffff)) : DivideUnsigned(
2142+
MakeUint(words1[words1Start], words1[words1Start + 1]),
2143+
valueB0));
21462144

21472145
int valueQint = ((int)valueQ) & 0xffff;
21482146
int valueB0int = ((int)valueB0) & 0xffff;
@@ -3417,14 +3415,14 @@ public int getDigitCount() {
34173415
((value >= 100000000000000L) ? 15 : ((value >=
34183416
10000000000000L) ?
34193417
14 : ((value >= 1000000000000L) ? 13 : ((value >=
3420-
100000000000L) ? 12 : ((value >= 10000000000L) ?
3421-
11 : ((value >= 1000000000L) ? 10 : 9)))))))));
3418+
100000000000L) ? 12 : ((value >= 10000000000L) ?
3419+
11 : ((value >= 1000000000L) ? 10 : 9)))))))));
34223420
} else {
34233421
int v2 = (int)value;
34243422
return (v2 >= 100000000) ? 9 : ((v2 >= 10000000) ? 8 : ((v2 >=
34253423
1000000) ? 7 : ((v2 >= 100000) ? 6 : ((v2 >=
3426-
10000) ? 5 : ((v2 >= 1000) ? 4 : ((v2 >= 100) ? 3 :
3427-
((v2 >= 10) ? 2 : 1)))))));
3424+
10000) ? 5 : ((v2 >= 1000) ? 4 : ((v2 >= 100) ?
3425+
3 : ((v2 >= 10) ? 2 : 1)))))));
34283426
}
34293427
}
34303428
int bitlen = this.getUnsignedBitLength();
@@ -4063,18 +4061,19 @@ public int getLowestSetBit() {
40634061
} else {
40644062
return (((c << 15) & 0xffff) != 0) ? (retSetBit + 0) : ((((c <<
40654063
14) & 0xffff) != 0) ? (retSetBit + 1) : ((((c <<
4066-
13) & 0xffff) != 0) ? (retSetBit + 2) : ((((c <<
4067-
12) & 0xffff) != 0) ? (retSetBit + 3) : ((((c << 11) & 0xffff) !=
4068-
0) ? (retSetBit +
4064+
13) & 0xffff) != 0) ? (retSetBit + 2) : ((((c <<
4065+
12) & 0xffff) != 0) ? (retSetBit + 3) : ((((c << 11) &
4066+
0xffff) != 0) ? (retSetBit +
40694067
4) : ((((c << 10) & 0xffff) != 0) ? (retSetBit +
4070-
5) : ((((c << 9) & 0xffff) != 0) ? (retSetBit + 6) : ((((c <<
4068+
5) : ((((c << 9) & 0xffff) != 0) ? (retSetBit + 6) :
4069+
((((c <<
40714070
8) & 0xffff) != 0) ? (retSetBit + 7) : ((((c << 7) & 0xffff) !=
40724071
0) ? (retSetBit + 8) : ((((c << 6) & 0xffff) !=
4073-
0) ? (retSetBit + 9) : ((((c <<
4072+
0) ? (retSetBit + 9) : ((((c <<
40744073
5) & 0xffff) != 0) ? (retSetBit + 10) : ((((c <<
4075-
4) & 0xffff) != 0) ? (retSetBit + 11) : ((((c << 3) & 0xffff) !=
4076-
0) ? (retSetBit + 12) : ((((c << 2) & 0xffff) !=
4077-
0) ? (retSetBit + 13) : ((((c << 1) & 0xffff) !=
4074+
4) & 0xffff) != 0) ? (retSetBit + 11) : ((((c << 3) &
4075+
0xffff) != 0) ? (retSetBit + 12) : ((((c << 2) & 0xffff) !=
4076+
0) ? (retSetBit + 13) : ((((c << 1) & 0xffff) !=
40784077
0) ? (retSetBit + 14) : (retSetBit + 15)))))))))))))));
40794078
}
40804079
}

src/main/java/com/upokecenter/util/DataUtilities.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -734,7 +734,7 @@ public static String ReadUtf8ToString(
734734
int retval = DataUtilities.ReadUtf8(stream, bytesCount, builder, replace);
735735
if (retval == -1) {
736736
throw new IOException(
737-
"Unpaired surrogate code point found." ,
737+
"Unpaired surrogate code point found.",
738738
new java.nio.charset.MalformedInputException(1));
739739
}
740740
return builder.toString();

0 commit comments

Comments
 (0)