public void Sign() { var sources = new[] { Fix64.MinValue, (Fix64)(-1), Fix64.Zero, Fix64.One, Fix64.MaxValue }; var expecteds = new[] { -1, -1, 0, 1, 1 }; for (int i = 0; i < sources.Length; ++i) { var actual = MathFix.Sign(sources[i]); var expected = expecteds[i]; Assert.Equal(expected, actual); } }
public void Sqrt() { for (int i = 0; i < m_testCases.Length; ++i) { var f = Fix64.FromRaw(m_testCases[i]); if (MathFix.Sign(f) < 0) { Assert.Throws <ArgumentOutOfRangeException>(() => MathFix.Sqrt(f)); } else { var expected = Math.Sqrt((double)f); var actual = (double)MathFix.Sqrt(f); var delta = (decimal)Math.Abs(expected - actual); Assert.True(delta <= Fix64.Precision); } } }