classlib: improve accuracy of double parser and fix possible issue

This commit is contained in:
Alexey Andreev 2023-09-14 10:04:27 +02:00
parent b2aae0634e
commit 0a92994c4b
2 changed files with 4 additions and 4 deletions

View File

@ -134,10 +134,6 @@ public final class DoubleAnalyzer {
long c = (c3 << (32 + shift)) + (c2 << (16 + shift)) + (c1 << shift); long c = (c3 << (32 + shift)) + (c2 << (16 + shift)) + (c1 << shift);
cm += c0 << 16; cm += c0 << 16;
// TODO: removing this gives better result in random tests, however toString(1.0) gives '0.5'
if (((cm >>> (31 - shift)) & 1) != 0) {
++c;
}
c += cm >>> (32 - shift); c += cm >>> (32 - shift);
return c; return c;

View File

@ -39,6 +39,10 @@ public final class DoubleSynthesizer {
return negative ? Double.NEGATIVE_INFINITY : Double.POSITIVE_INFINITY; return negative ? Double.NEGATIVE_INFINITY : Double.POSITIVE_INFINITY;
} }
binMantissa += 1L << 4; binMantissa += 1L << 4;
if ((binMantissa & (-1L << 58L)) != 0) {
binMantissa >>>= 1;
binExp++;
}
if (binExp <= 0) { if (binExp <= 0) {
binMantissa >>= Math.min(-binExp + 1, 64); binMantissa >>= Math.min(-binExp + 1, 64);
binExp = 0; binExp = 0;