Example #1
0
        //[Fact]
        public void AtanBenchmark()
        {
            var deltas = new List <decimal>();

            var swf = new Stopwatch();
            var swd = new Stopwatch();

            for (var x = -1.0; x < 1.0; x += 0.001)
            {
                for (int k = 0; k < 1000; ++k)
                {
                    var xf = (Fix64)x;
                    swf.Start();
                    var actualF = MathFix.Atan(xf);
                    swf.Stop();
                    swd.Start();
                    var expected = Math.Atan((double)xf);
                    swd.Stop();
                    deltas.Add(Math.Abs((decimal)actualF - (decimal)expected));
                }
            }
            Console.WriteLine("Max error: {0} ({1} times precision)", deltas.Max(), deltas.Max() / Fix64.Precision);
            Console.WriteLine("Average precision: {0} ({1} times precision)", deltas.Average(), deltas.Average() / Fix64.Precision);
            Console.WriteLine("Fix64.Atan time = {0}ms, Math.Atan time = {1}ms", swf.ElapsedMilliseconds, swd.ElapsedMilliseconds);
        }
Example #2
0
        public void Atan()
        {
            var maxDelta = 0.00000001m;
            var deltas   = new List <decimal>();

            Assert.Equal(Fix64.Zero, MathFix.Atan(Fix64.Zero));

            // Precision
            for (var x = -1.0; x < 1.0; x += 0.0001)
            {
                var xf       = (Fix64)x;
                var actual   = (decimal)MathFix.Atan(xf);
                var expected = (decimal)Math.Atan((double)xf);
                var delta    = Math.Abs(actual - expected);
                deltas.Add(delta);
                Assert.True(delta <= maxDelta, string.Format("Precision: Atan({0}): expected {1} but got {2}", xf, expected, actual));
            }

            // Scalability and edge cases
            foreach (var x in m_testCases)
            {
                var xf       = (Fix64)x;
                var actual   = (decimal)MathFix.Atan(xf);
                var expected = (decimal)Math.Atan((double)xf);
                var delta    = Math.Abs(actual - expected);
                deltas.Add(delta);
                Assert.True(delta <= maxDelta, string.Format("Scalability: Atan({0}): expected {1} but got {2}", xf, expected, actual));
            }
            Console.WriteLine("Max error: {0} ({1} times precision)", deltas.Max(), deltas.Max() / Fix64.Precision);
            Console.WriteLine("Average precision: {0} ({1} times precision)", deltas.Average(), deltas.Average() / Fix64.Precision);
        }