Beispiel #1
0
        private static void TestNumber(double value)
        {
            var    expected = GetBytes(value);
            double result   = IEEEFloat.ToDouble(expected, 0);
            var    actual   = GetBytes(result);

            AreEqual(expected, actual);
        }
Beispiel #2
0
        public void TestDoublePrecision()
        {
            TestNumber(0.0);
            //TestNumber(-0.0);
            TestNumber(4.3);
            TestNumber(Math.PI);
            TestNumber(double.NegativeInfinity);
            TestNumber(double.PositiveInfinity);
            TestNumber(double.NaN);

            int start = 120; // pick val < 127
            int end   = 135; // pick val > 128

            var buf = new byte[8];

            for (int b0 = start; b0 < end; ++b0)
            {
                for (int b1 = start; b1 < end; ++b1)
                {
                    for (int b2 = start; b2 < end; ++b2)
                    {
                        for (int b3 = start; b3 < end; ++b3)
                        {
                            buf[0] = (byte)b0;
                            buf[1] = (byte)b1;
                            buf[2] = (byte)b2;
                            buf[3] = (byte)b3;
                            buf[4] = (byte)b0;
                            buf[5] = (byte)b1;
                            buf[6] = (byte)b2;
                            buf[7] = (byte)b3;
                            double val = IEEEFloat.ToDouble(buf, 0);
                            if (!double.IsNaN(val))
                            {
                                var buf2 = GetBytes(val);
                                AreEqual(buf, buf2);
                            }
                        }
                    }
                }
            }
        }