diff --git a/core/src/main/java/org/teavm/cache/ClassIO.java b/core/src/main/java/org/teavm/cache/ClassIO.java index 552805e2f..035baac07 100644 --- a/core/src/main/java/org/teavm/cache/ClassIO.java +++ b/core/src/main/java/org/teavm/cache/ClassIO.java @@ -118,7 +118,7 @@ public class ClassIO { output.writeUnsigned(0); } else if (value instanceof Integer) { output.writeUnsigned(1); - output.writeUnsigned((Integer) value); + output.writeSigned((Integer) value); } else if (value instanceof Long) { output.writeUnsigned(2); output.writeSigned((Long) value); diff --git a/core/src/main/java/org/teavm/cache/VarDataInput.java b/core/src/main/java/org/teavm/cache/VarDataInput.java index 0cd611066..2eac22206 100644 --- a/core/src/main/java/org/teavm/cache/VarDataInput.java +++ b/core/src/main/java/org/teavm/cache/VarDataInput.java @@ -45,7 +45,7 @@ public class VarDataInput { public int readSigned() throws IOException { int value = readUnsigned(); - return (value & 1) == 0 ? (value >>> 1) : -(value >>> 1); + return (value & 1) == 0 ? (value >>> 1) : ~(value >>> 1); } public long readUnsignedLong() throws IOException { @@ -65,7 +65,7 @@ public class VarDataInput { public long readSignedLong() throws IOException { long value = readUnsignedLong(); - return (value & 1) == 0 ? (value >> 1) : -(value >> 1); + return (value & 1) == 0 ? (value >> 1) : ~(value >> 1); } public float readFloat() throws IOException { @@ -106,7 +106,7 @@ public class VarDataInput { long bits = mantissa & ((1L << 52) - 1); bits |= (long) exponent << 52; if (sign) { - bits |= 1L << 53; + bits |= 1L << 63; } return Double.longBitsToDouble(bits); diff --git a/core/src/main/java/org/teavm/cache/VarDataOutput.java b/core/src/main/java/org/teavm/cache/VarDataOutput.java index e64405457..9d9e3da1d 100644 --- a/core/src/main/java/org/teavm/cache/VarDataOutput.java +++ b/core/src/main/java/org/teavm/cache/VarDataOutput.java @@ -37,7 +37,7 @@ public class VarDataOutput implements Closeable { } public void writeSigned(int value) throws IOException { - writeUnsigned(value < 0 ? ((-value) << 1) | 1 : value << 1); + writeUnsigned(value < 0 ? ((~value) << 1) | 1 : value << 1); } public void writeUnsigned(long value) throws IOException { @@ -49,7 +49,7 @@ public class VarDataOutput implements Closeable { } public void writeSigned(long value) throws IOException { - writeUnsigned(value < 0 ? ((-value) << 1) | 1 : value << 1); + writeUnsigned(value < 0 ? ((~value) << 1) | 1 : value << 1); } public void writeFloat(float value) throws IOException {