Fixes some bugs in JCL

This commit is contained in:
konsoletyper 2014-03-12 22:35:20 +04:00
parent b85dfcd7a0
commit 44264c7ea8
7 changed files with 25 additions and 24 deletions

View File

@ -67,7 +67,8 @@ public class CharBuffer {
} }
public void put(CharBuffer buffer) { public void put(CharBuffer buffer) {
while (buffer.pos < buffer.end) { int sz = Math.min(buffer.end - buffer.pos, end - pos);
for (int i = 0; i < sz; ++i) {
data[pos++] = buffer.data[buffer.pos++]; data[pos++] = buffer.data[buffer.pos++];
} }
} }

View File

@ -38,7 +38,7 @@ public class TBufferedReader extends TReader {
throw new TIllegalArgumentException(); throw new TIllegalArgumentException();
} }
this.innerReader = innerReader; this.innerReader = innerReader;
this.buffer = new char[TMath.min(64, size)]; this.buffer = new char[TMath.max(64, size)];
} }
public TBufferedReader(TReader innerReader) { public TBufferedReader(TReader innerReader) {
@ -160,8 +160,8 @@ public class TBufferedReader extends TReader {
if (eof) { if (eof) {
return false; return false;
} }
while (true) { while (offset < buffer.length) {
int charsRead = innerReader.read(buffer, offset, buffer.length - 1); int charsRead = innerReader.read(buffer, offset, buffer.length - offset);
if (charsRead == -1) { if (charsRead == -1) {
eof = true; eof = true;
break; break;

View File

@ -82,7 +82,7 @@ public class TInputStreamReader extends TReader {
break; break;
} }
} }
return outBuffer.position() - off; return wrapBuffer.position() - off;
} }
private boolean fillBuffer() throws TIOException { private boolean fillBuffer() throws TIOException {

View File

@ -274,7 +274,7 @@ public class TDouble extends TNumber implements TComparable<TDouble> {
return NaN; return NaN;
} }
} }
boolean negative = (bits & (1 << 63)) != 0; boolean negative = (bits & (1L << 63)) != 0;
int rawExp = (int)((bits >> 52) & 0x7FFL); int rawExp = (int)((bits >> 52) & 0x7FFL);
long mantissa = bits & 0xFFFFFFFFFFFFFL; long mantissa = bits & 0xFFFFFFFFFFFFFL;
if (rawExp == 0) { if (rawExp == 0) {

View File

@ -307,12 +307,12 @@ public class TLong extends TNumber implements TComparable<TLong> {
} }
public static int bitCount(long i) { public static int bitCount(long i) {
i = (i & 0xAAAAAAAAAAAAAAAAL) >> 1 + i & 0x5555555555555555L; i = ((i & 0xAAAAAAAAAAAAAAAAL) >> 1) + (i & 0x5555555555555555L);
i = (i & 0xCCCCCCCCCCCCCCCCL) >> 2 + i & 0x3333333333333333L; i = ((i & 0xCCCCCCCCCCCCCCCCL) >> 2) + (i & 0x3333333333333333L);
i = (i & 0x3030303030303030L) >> 4 + i & 0x0303030303030303L; i = ((i & 0x3030303030303030L) >> 4) + (i & 0x0303030303030303L);
i = (i & 0x0700070007000700L) >> 8 + i & 0x0007000700070007L; i = ((i & 0x0700070007000700L) >> 8) + (i & 0x0007000700070007L);
i = (i & 0x000F0000000F0000L) >> 16 + i & 0x0000000F0000000FL; i = ((i & 0x000F0000000F0000L) >> 16) + (i & 0x0000000F0000000FL);
i = (i & 0x0000001F00000000L) >> 32 + i & 0x000000000000001FL; i = ((i & 0x0000001F00000000L) >> 32) + (i & 0x000000000000001FL);
return (int)i; return (int)i;
} }
@ -327,19 +327,19 @@ public class TLong extends TNumber implements TComparable<TLong> {
} }
public static long reverse(long i) { public static long reverse(long i) {
i = (i & 0xAAAAAAAAAAAAAAAAL) >> 1 | (i & 0x5555555555555555L) << 1; i = ((i & 0xAAAAAAAAAAAAAAAAL) >> 1) | ((i & 0x5555555555555555L) << 1);
i = (i & 0xCCCCCCCCCCCCCCCCL) >> 2 | (i & 0x3333333333333333L) << 2; i = ((i & 0xCCCCCCCCCCCCCCCCL) >> 2) | ((i & 0x3333333333333333L) << 2);
i = (i & 0xF0F0F0F0F0F0F0F0L) >> 4 | (i & 0x0F0F0F0F0F0F0F0FL) << 4; i = ((i & 0xF0F0F0F0F0F0F0F0L) >> 4) | ((i & 0x0F0F0F0F0F0F0F0FL) << 4);
i = (i & 0xFF00FF00FF00FF00L) >> 8 | (i & 0x00FF00FF00FF00FFL) << 8; i = ((i & 0xFF00FF00FF00FF00L) >> 8) | ((i & 0x00FF00FF00FF00FFL) << 8);
i = (i & 0xFFFF0000FFFF0000L) >> 16 | (i & 0x0000FFFF0000FFFFL) << 16; i = ((i & 0xFFFF0000FFFF0000L) >> 16) | ((i & 0x0000FFFF0000FFFFL) << 16);
i = (i & 0xFFFF0000FFFF0000L) >> 32 | (i & 0x0000FFFF0000FFFFL) << 32; i = ((i & 0xFFFF0000FFFF0000L) >> 32) | ((i & 0x0000FFFF0000FFFFL) << 32);
return i; return i;
} }
public static long reverseBytes(long i) { public static long reverseBytes(long i) {
i = (i & 0xFF00FF00FF00FF00L) >> 8 | (i & 0x00FF00FF00FF00FFL) << 8; i = ((i & 0xFF00FF00FF00FF00L) >> 8) | ((i & 0x00FF00FF00FF00FFL) << 8);
i = (i & 0xFFFF0000FFFF0000L) >> 16 | (i & 0x0000FFFF0000FFFFL) << 16; i = ((i & 0xFFFF0000FFFF0000L) >> 16) | ((i & 0x0000FFFF0000FFFFL) << 16);
i = i >> 32 | i << 32; i = (i >> 32) | (i << 32);
return i; return i;
} }

View File

@ -169,12 +169,12 @@ public final class TMath extends TObject {
public static double sinh(double x) { public static double sinh(double x) {
double e = exp(x); double e = exp(x);
return e - 1 / e; return (e - 1 / e) / 2;
} }
public static double cosh(double x) { public static double cosh(double x) {
double e = exp(x); double e = exp(x);
return e + 1 / e; return (e + 1 / e) / 2;
} }
public static double tanh(double x) { public static double tanh(double x) {

View File

@ -413,7 +413,7 @@ Long_fromNumber = function(val) {
return new Long(val | 0, (val / 0x100000000) | 0); return new Long(val | 0, (val / 0x100000000) | 0);
} }
Long_toNumber = function(val) { Long_toNumber = function(val) {
return val.lo + 0x100000000 * val.hi; return val.hi >= 0 ? val.lo + 0x100000000 * val.hi : -0x100000000 * (val.hi ^ 0xFFFFFFFF) + val.lo;
} }
Long_add = function(a, b) { Long_add = function(a, b) {
var a_lolo = a.lo & 0xFFFF; var a_lolo = a.lo & 0xFFFF;