public void Acos() { var maxDelta = 0.00000001m; var deltas = new List <decimal>(); Assert.AreEqual(Fix64.Zero, Fix64.Acos(Fix64.One)); Assert.AreEqual(Fix64.PiOver2, Fix64.Acos(Fix64.Zero)); Assert.AreEqual(Fix64.Pi, Fix64.Acos(-Fix64.One)); // Precision for (var x = -1.0; x < 1.0; x += 0.001) { var xf = (Fix64)x; var actual = (decimal)Fix64.Acos(xf); var expected = (decimal)Math.Acos((double)xf); var delta = Math.Abs(actual - expected); deltas.Add(delta); Assert.True(delta <= maxDelta, string.Format("Precision: Acos({0}): expected {1} but got {2}", xf, expected, actual)); } for (int i = 0; i < m_testCases.Length; ++i) { var b = Fix64.FromRaw(m_testCases[i]); if (b < -Fix64.One || b > Fix64.One) { Assert.Throws <ArgumentOutOfRangeException>(() => Fix64.Acos(b)); } else { var expected = (decimal)Math.Acos((double)b); var actual = (decimal)Fix64.Acos(b); var delta = Math.Abs(expected - actual); deltas.Add(delta); Assert.True(delta <= maxDelta, string.Format("Acos({0}) = expected {1} but got {2}", b, 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); }
public void Acos() { decimal maxDelta = Fix64.Precision * 20; var deltas = new List <decimal>(); // Precision for (var x = -1.0; x < 1.0; x += 0.001) { var xf = (Fix64)x; var actual = (decimal)Fix64.Acos(xf); var expected = (decimal)Math.Acos((double)xf); var delta = Math.Abs(actual - expected); deltas.Add(delta); Assert.True(delta <= maxDelta, string.Format("Precision: Acos({0}): expected {1} but got {2}", xf, expected, actual)); } for (int i = 0; i < m_testCases.Length; ++i) { var b = Fix64.FromRaw(m_testCases[i]); if (b < -Fix64.One) { continue; } if (b > Fix64.One) { continue; } var expected = (decimal)Math.Acos((double)b); var actual = (decimal)Fix64.Acos(b); var delta = Math.Abs(expected - actual); deltas.Add(delta); Assert.True(delta <= maxDelta, string.Format("Acos({0}) = expected {1} but got {2}", b, expected, actual)); } output.WriteLine("Max error: {0} ({1} times precision)", deltas.Max(), deltas.Max() / Fix64.Precision); output.WriteLine("Average precision: {0} ({1} times precision)", deltas.Average(), deltas.Average() / Fix64.Precision); }
public static Fix64 Acos(Fix64 f) { //return Math.Acos(f.ToDouble()); return(Fix64.Acos(f)); }