Пример #1
0
        public void encodeDecodeSlof()
        {
            Random random = new Random();
            int    n      = 1000;

            double[] ics = new double[n];
            for (int i = 0; i < n; i++)
            {
                ics[i] = Math.Pow(10, 6 * random.NextDouble());
            }

            byte[] encoded      = new byte[n * 2 + 8];
            double fixedPoint   = MSNumpress.optimalSlofFixedPoint(ics, n);
            int    encodedBytes = MSNumpress.encodeSlof(ics, n, encoded, fixedPoint);

            double[] decoded        = new double[n];
            int      decodedDoubles = MSNumpress.decodeSlof(encoded, encodedBytes, decoded);

            Assert.AreEqual(n, decodedDoubles);

            for (int i = 0; i < n; i++)
            {
                Assert.AreEqual(0.0, (ics[i] - decoded[i]) / ((ics[i] + decoded[i]) / 2), 0.0005);
            }
        }
Пример #2
0
        public void encodeDecodeSlof5()
        {
            Random random = new Random();
            int    n      = 1000;

            double[] ics = new double[n];
            for (int i = 0; i < n; i++)
            {
                ics[i] = Math.Pow(10, 6 * random.NextDouble());
            }

            byte[]   encoded      = new byte[n * 2 + 8];
            double[] decoded      = new double[n];
            double[] firstDecoded = new double[n];
            double   fixedPoint   = MSNumpress.optimalSlofFixedPoint(ics, n);

            int encodedBytes   = MSNumpress.encodeSlof(ics, n, encoded, fixedPoint);
            int decodedDoubles = MSNumpress.decodeSlof(encoded, encodedBytes, decoded);

            for (int i = 0; i < n; i++)
            {
                firstDecoded[i] = decoded[i];
            }

            for (int i = 0; i < 5; i++)
            {
                MSNumpress.encodeSlof(decoded, n, encoded, fixedPoint);
                MSNumpress.decodeSlof(encoded, encodedBytes, decoded);
            }

            Assert.AreEqual(n, decodedDoubles);

            for (int i = 0; i < n; i++)
            {
                Assert.AreEqual(firstDecoded[i], decoded[i], double.Epsilon);
            }
        }