diff --git a/dotnet/Pyrolite.Tests/Pickle/ArrayConstructorTests.cs b/dotnet/Pyrolite.Tests/Pickle/ArrayConstructorTests.cs index bcdb6b7..a495d21 100644 --- a/dotnet/Pyrolite.Tests/Pickle/ArrayConstructorTests.cs +++ b/dotnet/Pyrolite.Tests/Pickle/ArrayConstructorTests.cs @@ -159,47 +159,47 @@ public void testFloats() // f/d ArrayConstructor ac=new ArrayConstructor(); Assert.AreEqual(16711938.0f, - ((float[])ac.construct('f', 14, new byte[]{0x4b,0x7f,0x01,0x02}))[0] ); + ((float[])ac.construct('f', 15, new byte[]{0x4b,0x7f,0x01,0x02}))[0] ); Assert.AreEqual(float.PositiveInfinity, - ((float[])ac.construct('f', 14, new byte[]{0x7f,0x80,0x00,0x00}))[0]); + ((float[])ac.construct('f', 15, new byte[]{0x7f,0x80,0x00,0x00}))[0]); Assert.AreEqual(float.NegativeInfinity, - ((float[])ac.construct('f', 14, new byte[]{0xff,0x80,0x00,0x00}))[0]); + ((float[])ac.construct('f', 15, new byte[]{0xff,0x80,0x00,0x00}))[0]); Assert.AreEqual(-0.0f, - ((float[])ac.construct('f', 14, new byte[]{0x80,0x00,0x00,0x00}))[0]); + ((float[])ac.construct('f', 15, new byte[]{0x80,0x00,0x00,0x00}))[0]); Assert.AreEqual(16711938.0f, - ((float[])ac.construct('f', 15, new byte[]{0x02,0x01,0x7f,0x4b}))[0]); + ((float[])ac.construct('f', 14, new byte[]{0x02,0x01,0x7f,0x4b}))[0]); Assert.AreEqual(float.PositiveInfinity, - ((float[])ac.construct('f', 15, new byte[]{0x00,0x00,0x80,0x7f}))[0]); + ((float[])ac.construct('f', 14, new byte[]{0x00,0x00,0x80,0x7f}))[0]); Assert.AreEqual(float.NegativeInfinity, - ((float[])ac.construct('f', 15, new byte[]{0x00,0x00,0x80,0xff}))[0]); + ((float[])ac.construct('f', 14, new byte[]{0x00,0x00,0x80,0xff}))[0]); Assert.AreEqual(-0.0f, - ((float[])ac.construct('f', 15, new byte[]{0x00,0x00,0x00,0x80}))[0]); + ((float[])ac.construct('f', 14, new byte[]{0x00,0x00,0x00,0x80}))[0]); Assert.AreEqual(9006104071832581.0d, - ((double[])ac.construct('d', 16, new byte[]{0x43,0x3f,0xff,0x01,0x02,0x03,0x04,0x05}))[0]); + ((double[])ac.construct('d', 17, new byte[]{0x43,0x3f,0xff,0x01,0x02,0x03,0x04,0x05}))[0]); Assert.AreEqual(double.PositiveInfinity, - ((double[])ac.construct('d', 16, new byte[]{0x7f,0xf0,0x00,0x00,0x00,0x00,0x00,0x00}))[0]); + ((double[])ac.construct('d', 17, new byte[]{0x7f,0xf0,0x00,0x00,0x00,0x00,0x00,0x00}))[0]); Assert.AreEqual(double.NegativeInfinity, - ((double[])ac.construct('d', 16, new byte[]{0xff,0xf0,0x00,0x00,0x00,0x00,0x00,0x00}))[0]); + ((double[])ac.construct('d', 17, new byte[]{0xff,0xf0,0x00,0x00,0x00,0x00,0x00,0x00}))[0]); Assert.AreEqual(-0.0d, - ((double[])ac.construct('d', 16, new byte[]{0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00}))[0]); + ((double[])ac.construct('d', 17, new byte[]{0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00}))[0]); Assert.AreEqual(9006104071832581.0d, - ((double[])ac.construct('d', 17, new byte[]{0x05,0x04,0x03,0x02,0x01,0xff,0x3f,0x43}))[0]); + ((double[])ac.construct('d', 16, new byte[]{0x05,0x04,0x03,0x02,0x01,0xff,0x3f,0x43}))[0]); Assert.AreEqual(double.PositiveInfinity, - ((double[])ac.construct('d', 17, new byte[]{0x00,0x00,0x00,0x00,0x00,0x00,0xf0,0x7f}))[0]); + ((double[])ac.construct('d', 16, new byte[]{0x00,0x00,0x00,0x00,0x00,0x00,0xf0,0x7f}))[0]); Assert.AreEqual(double.NegativeInfinity, - ((double[])ac.construct('d', 17, new byte[]{0x00,0x00,0x00,0x00,0x00,0x00,0xf0,0xff}))[0]); + ((double[])ac.construct('d', 16, new byte[]{0x00,0x00,0x00,0x00,0x00,0x00,0xf0,0xff}))[0]); Assert.AreEqual(-0.0d, - ((double[])ac.construct('d', 17, new byte[]{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80}))[0]); + ((double[])ac.construct('d', 16, new byte[]{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80}))[0]); // check if multiple values in an array work - Assert.AreEqual(new float[] {1.1f, 2.2f}, (float[]) ac.construct('f', 14, new byte[]{0x3f,0x8c,0xcc,0xcd, 0x40,0x0c,0xcc,0xcd})); - Assert.AreEqual(new float[] {1.1f, 2.2f}, (float[]) ac.construct('f', 15, new byte[]{0xcd,0xcc,0x8c,0x3f, 0xcd,0xcc,0x0c,0x40})); - Assert.AreEqual(new double[]{1.1d, 2.2d}, (double[]) ac.construct('d', 16, new byte[]{0x3f,0xf1,0x99,0x99,0x99,0x99,0x99,0x9a, 0x40,0x01,0x99,0x99,0x99,0x99,0x99,0x9a})); - Assert.AreEqual(new double[]{1.1d, 2.2d}, (double[]) ac.construct('d', 17, new byte[]{0x9a,0x99,0x99,0x99,0x99,0x99,0xf1,0x3f, 0x9a,0x99,0x99,0x99,0x99,0x99,0x01,0x40})); + Assert.AreEqual(new float[] {1.1f, 2.2f}, (float[]) ac.construct('f', 15, new byte[]{0x3f,0x8c,0xcc,0xcd, 0x40,0x0c,0xcc,0xcd})); + Assert.AreEqual(new float[] {1.1f, 2.2f}, (float[]) ac.construct('f', 14, new byte[]{0xcd,0xcc,0x8c,0x3f, 0xcd,0xcc,0x0c,0x40})); + Assert.AreEqual(new double[]{1.1d, 2.2d}, (double[]) ac.construct('d', 17, new byte[]{0x3f,0xf1,0x99,0x99,0x99,0x99,0x99,0x9a, 0x40,0x01,0x99,0x99,0x99,0x99,0x99,0x9a})); + Assert.AreEqual(new double[]{1.1d, 2.2d}, (double[]) ac.construct('d', 16, new byte[]{0x9a,0x99,0x99,0x99,0x99,0x99,0xf1,0x3f, 0x9a,0x99,0x99,0x99,0x99,0x99,0x01,0x40})); } } diff --git a/dotnet/Pyrolite/Pickle/Objects/ArrayConstructor.cs b/dotnet/Pyrolite/Pickle/Objects/ArrayConstructor.cs index 267fc6e..f053cb0 100644 --- a/dotnet/Pyrolite/Pickle/Objects/ArrayConstructor.cs +++ b/dotnet/Pyrolite/Pickle/Objects/ArrayConstructor.cs @@ -394,10 +394,10 @@ protected double[] constructDoubleArray(int machinecode, byte[] data) { double[] result = new double[data.Length / 8]; byte[] bigendian=new byte[8]; for (int i = 0; i < data.Length / 8; ++i) { - if(machinecode==16) { + if(machinecode==17) { result[i] = PickleUtils.bytes_to_double(data, i * 8); } else { - // 17=big endian, flip the bytes + // 16=little endian, flip the bytes bigendian[0]=data[7+i*8]; bigendian[1]=data[6+i*8]; bigendian[2]=data[5+i*8]; @@ -416,10 +416,10 @@ protected float[] constructFloatArray(int machinecode, byte[] data) { float[] result = new float[data.Length / 4]; byte[] bigendian=new byte[4]; for (int i = 0; i < data.Length / 4; ++i) { - if (machinecode == 14) { + if (machinecode == 15) { result[i] = PickleUtils.bytes_to_float(data, i * 4); } else { - // 15=big endian, flip the bytes + // 14=little endian, flip the bytes bigendian[0]=data[3+i*4]; bigendian[1]=data[2+i*4]; bigendian[2]=data[1+i*4]; diff --git a/java/src/net/razorvine/pickle/objects/ArrayConstructor.java b/java/src/net/razorvine/pickle/objects/ArrayConstructor.java index cc0f185..97519c5 100644 --- a/java/src/net/razorvine/pickle/objects/ArrayConstructor.java +++ b/java/src/net/razorvine/pickle/objects/ArrayConstructor.java @@ -330,10 +330,10 @@ protected double[] constructDoubleArray(int machinecode, byte[] data) { double[] result = new double[data.length / 8]; byte[] bigendian=new byte[8]; for (int i = 0; i < data.length / 8; ++i) { - if(machinecode==16) { + if(machinecode == 17) { result[i] = PickleUtils.bytes_to_double(data, i * 8); } else { - // 17=big endian, flip the bytes + // 16=little endian, flip the bytes bigendian[0]=data[7+i*8]; bigendian[1]=data[6+i*8]; bigendian[2]=data[5+i*8]; @@ -352,10 +352,10 @@ protected float[] constructFloatArray(int machinecode, byte[] data) { float[] result = new float[data.length / 4]; byte[] bigendian=new byte[4]; for (int i = 0; i < data.length / 4; ++i) { - if (machinecode == 14) { + if (machinecode == 15) { result[i] = PickleUtils.bytes_to_float(data, i * 4); } else { - // 15=big endian, flip the bytes + // 14=little endian, flip the bytes bigendian[0]=data[3+i*4]; bigendian[1]=data[2+i*4]; bigendian[2]=data[1+i*4]; diff --git a/java/test/net/razorvine/pickle/test/ArrayConstructorTest.java b/java/test/net/razorvine/pickle/test/ArrayConstructorTest.java index ccc36eb..86ac30b 100644 --- a/java/test/net/razorvine/pickle/test/ArrayConstructorTest.java +++ b/java/test/net/razorvine/pickle/test/ArrayConstructorTest.java @@ -160,47 +160,48 @@ public void testFloats() { // f/d ArrayConstructor ac=new ArrayConstructor(); + // big endian assertTrue(16711938.0f == - ((float[])ac.construct('f', 14, new byte[]{0x4b,0x7f,0x01,0x02}))[0] ); + ((float[])ac.construct('f', 15, new byte[]{0x4b,0x7f,0x01,0x02}))[0] ); assertTrue(Float.POSITIVE_INFINITY == - ((float[])ac.construct('f', 14, new byte[]{(byte)0x7f,(byte)0x80,0x00,0x00}))[0]); + ((float[])ac.construct('f', 15, new byte[]{(byte)0x7f,(byte)0x80,0x00,0x00}))[0]); assertTrue(Float.NEGATIVE_INFINITY == - ((float[])ac.construct('f', 14, new byte[]{(byte)0xff,(byte)0x80,0x00,0x00}))[0]); + ((float[])ac.construct('f', 15, new byte[]{(byte)0xff,(byte)0x80,0x00,0x00}))[0]); assertTrue(-0.0f == - ((float[])ac.construct('f', 14, new byte[]{(byte)0x80,0x00,0x00,0x00}))[0]); - + ((float[])ac.construct('f', 15, new byte[]{(byte)0x80,0x00,0x00,0x00}))[0]); + // little endian assertTrue(16711938.0f == - ((float[])ac.construct('f', 15, new byte[]{0x02,0x01,0x7f,0x4b}))[0]); + ((float[])ac.construct('f', 14, new byte[]{0x02,0x01,0x7f,0x4b}))[0]); assertTrue(Float.POSITIVE_INFINITY == - ((float[])ac.construct('f', 15, new byte[]{0x00,0x00,(byte)0x80,(byte)0x7f}))[0]); + ((float[])ac.construct('f', 14, new byte[]{0x00,0x00,(byte)0x80,(byte)0x7f}))[0]); assertTrue(Float.NEGATIVE_INFINITY == - ((float[])ac.construct('f', 15, new byte[]{0x00,0x00,(byte)0x80,(byte)0xff}))[0]); + ((float[])ac.construct('f', 14, new byte[]{0x00,0x00,(byte)0x80,(byte)0xff}))[0]); assertTrue(-0.0f == - ((float[])ac.construct('f', 15, new byte[]{0x00,0x00,0x00,(byte)0x80}))[0]); - + ((float[])ac.construct('f', 14, new byte[]{0x00,0x00,0x00,(byte)0x80}))[0]); + // big endian assertTrue(9006104071832581.0d == - ((double[])ac.construct('d', 16, new byte[]{0x43,0x3f,(byte)0xff,0x01,0x02,0x03,0x04,0x05}))[0]); + ((double[])ac.construct('d', 17, new byte[]{0x43,0x3f,(byte)0xff,0x01,0x02,0x03,0x04,0x05}))[0]); assertTrue(Double.POSITIVE_INFINITY == - ((double[])ac.construct('d', 16, new byte[]{(byte)0x7f,(byte)0xf0,0x00,0x00,0x00,0x00,0x00,0x00}))[0]); + ((double[])ac.construct('d', 17, new byte[]{(byte)0x7f,(byte)0xf0,0x00,0x00,0x00,0x00,0x00,0x00}))[0]); assertTrue(Double.NEGATIVE_INFINITY == - ((double[])ac.construct('d', 16, new byte[]{(byte)0xff,(byte)0xf0,0x00,0x00,0x00,0x00,0x00,0x00}))[0]); + ((double[])ac.construct('d', 17, new byte[]{(byte)0xff,(byte)0xf0,0x00,0x00,0x00,0x00,0x00,0x00}))[0]); assertTrue(-0.0d == - ((double[])ac.construct('d', 16, new byte[]{(byte)0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00}))[0]); - + ((double[])ac.construct('d', 17, new byte[]{(byte)0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00}))[0]); + // little endian assertTrue(9006104071832581.0d == - ((double[])ac.construct('d', 17, new byte[]{0x05,0x04,0x03,0x02,0x01,(byte)0xff,0x3f,0x43}))[0]); + ((double[])ac.construct('d', 16, new byte[]{0x05,0x04,0x03,0x02,0x01,(byte)0xff,0x3f,0x43}))[0]); assertTrue(Double.POSITIVE_INFINITY == - ((double[])ac.construct('d', 17, new byte[]{0x00,0x00,0x00,0x00,0x00,0x00,(byte)0xf0,(byte)0x7f}))[0]); + ((double[])ac.construct('d', 16, new byte[]{0x00,0x00,0x00,0x00,0x00,0x00,(byte)0xf0,(byte)0x7f}))[0]); assertTrue(Double.NEGATIVE_INFINITY == - ((double[])ac.construct('d', 17, new byte[]{0x00,0x00,0x00,0x00,0x00,0x00,(byte)0xf0,(byte)0xff}))[0]); + ((double[])ac.construct('d', 16, new byte[]{0x00,0x00,0x00,0x00,0x00,0x00,(byte)0xf0,(byte)0xff}))[0]); assertTrue(-0.0d == - ((double[])ac.construct('d', 17, new byte[]{0x00,0x00,0x00,0x00,0x00,0x00,0x00,(byte)0x80}))[0]); + ((double[])ac.construct('d', 16, new byte[]{0x00,0x00,0x00,0x00,0x00,0x00,0x00,(byte)0x80}))[0]); // check if multiple values in an array work - assertArrayEquals(new float[] {1.1f, 2.2f}, (float[]) ac.construct('f', 14, new byte[]{0x3f,(byte)0x8c,(byte)0xcc,(byte)0xcd, 0x40,0x0c,(byte)0xcc,(byte)0xcd}) ,0); - assertArrayEquals(new float[] {1.1f, 2.2f}, (float[]) ac.construct('f', 15, new byte[]{(byte)0xcd,(byte)0xcc,(byte)0x8c,0x3f, (byte)0xcd,(byte)0xcc,0x0c,0x40}) ,0); - assertArrayEquals(new double[]{1.1d, 2.2d}, (double[]) ac.construct('d', 16, new byte[]{(byte)0x3f,(byte)0xf1,(byte)0x99,(byte)0x99,(byte)0x99,(byte)0x99,(byte)0x99,(byte)0x9a, (byte)0x40,(byte)0x01,(byte)0x99,(byte)0x99,(byte)0x99,(byte)0x99,(byte)0x99,(byte)0x9a}) ,0); - assertArrayEquals(new double[]{1.1d, 2.2d}, (double[]) ac.construct('d', 17, new byte[]{(byte)0x9a,(byte)0x99,(byte)0x99,(byte)0x99,(byte)0x99,(byte)0x99,(byte)0xf1,(byte)0x3f, (byte)0x9a,(byte)0x99,(byte)0x99,(byte)0x99,(byte)0x99,(byte)0x99,(byte)0x01,(byte)0x40}) ,0); + assertArrayEquals(new float[] {1.1f, 2.2f}, (float[]) ac.construct('f', 15, new byte[]{0x3f,(byte)0x8c,(byte)0xcc,(byte)0xcd, 0x40,0x0c,(byte)0xcc,(byte)0xcd}) ,0); + assertArrayEquals(new float[] {1.1f, 2.2f}, (float[]) ac.construct('f', 14, new byte[]{(byte)0xcd,(byte)0xcc,(byte)0x8c,0x3f, (byte)0xcd,(byte)0xcc,0x0c,0x40}) ,0); + assertArrayEquals(new double[]{1.1d, 2.2d}, (double[]) ac.construct('d', 17, new byte[]{(byte)0x3f,(byte)0xf1,(byte)0x99,(byte)0x99,(byte)0x99,(byte)0x99,(byte)0x99,(byte)0x9a, (byte)0x40,(byte)0x01,(byte)0x99,(byte)0x99,(byte)0x99,(byte)0x99,(byte)0x99,(byte)0x9a}) ,0); + assertArrayEquals(new double[]{1.1d, 2.2d}, (double[]) ac.construct('d', 16, new byte[]{(byte)0x9a,(byte)0x99,(byte)0x99,(byte)0x99,(byte)0x99,(byte)0x99,(byte)0xf1,(byte)0x3f, (byte)0x9a,(byte)0x99,(byte)0x99,(byte)0x99,(byte)0x99,(byte)0x99,(byte)0x01,(byte)0x40}) ,0); } }