public void SinHalfPITest() { foreach (MultiPrecision <Pow2.N8> x in TestTool.ShortRangeSet <Pow2.N8>()) { MultiPrecision <Pow2.N8> y = MultiPrecision <Pow2.N8> .SinHalfPI(x); Console.WriteLine(x); Console.WriteLine(y); TestTool.Tolerance(Math.Sin((double)x * Math.PI / 2), y, minerr: 1e-5, ignore_sign: true); } for (int x = -32; x <= 32; x += 2) { MultiPrecision <Pow2.N8> y = MultiPrecision <Pow2.N8> .SinHalfPI(x); Assert.AreEqual(MultiPrecision <Pow2.N8> .Zero, y); Assert.AreEqual(Sign.Plus, y.Sign); } Assert.IsTrue(MultiPrecision <Pow2.N8> .NearlyEqualBits( MultiPrecision <Pow2.N8> .Sqrt2 / 2, MultiPrecision <Pow2.N8> .SinHalfPI(MultiPrecision <Pow2.N8> .Div(1, 2)), 1)); Assert.IsTrue(MultiPrecision <Pow2.N8> .NearlyEqualBits( MultiPrecision <Pow2.N8> .Point5, MultiPrecision <Pow2.N8> .SinHalfPI(MultiPrecision <Pow2.N8> .Div(1, 3)), 1)); Assert.IsTrue(MultiPrecision <Pow2.N8> .NearlyEqualBits( MultiPrecision <Pow2.N8> .Sqrt(3) / 2, MultiPrecision <Pow2.N8> .SinHalfPI(MultiPrecision <Pow2.N8> .Div(2, 3)), 1)); Assert.IsTrue(MultiPrecision <Pow2.N16> .NearlyEqualBits( MultiPrecision <Pow2.N16> .Sqrt2 / 2, MultiPrecision <Pow2.N16> .SinHalfPI(MultiPrecision <Pow2.N16> .Div(1, 2)), 1)); Assert.IsTrue(MultiPrecision <Pow2.N16> .NearlyEqualBits( MultiPrecision <Pow2.N16> .Point5, MultiPrecision <Pow2.N16> .SinHalfPI(MultiPrecision <Pow2.N16> .Div(1, 3)), 1)); Assert.IsTrue(MultiPrecision <Pow2.N16> .NearlyEqualBits( MultiPrecision <Pow2.N16> .Sqrt(3) / 2, MultiPrecision <Pow2.N16> .SinHalfPI(MultiPrecision <Pow2.N16> .Div(2, 3)), 1)); }
public void DivLongTest() { foreach (MultiPrecision <Pow2.N8> a in vs) { foreach (long b in us) { MultiPrecision <Pow2.N8> c_actual = MultiPrecision <Pow2.N8> .Div(a, b); MultiPrecision <Pow2.N8> c_expect = MultiPrecision <Pow2.N8> .Div(a, (MultiPrecision <Pow2.N8>) b); Trace.WriteLine($"{a} / {b} = {c_expect}"); Trace.WriteLine($"{a} / {b} = {c_actual}"); if (c_actual.IsNaN && c_expect.IsNaN) { continue; } if (a.IsNaN) { if (!c_actual.IsNaN) { Console.WriteLine($"{a} / {b} = {c_expect}"); Console.WriteLine($"{a} / {b} = {c_actual}"); Console.Write("\n"); Assert.Fail(); } } else { Console.WriteLine($"{a} / {b} = {c_expect}"); Console.WriteLine($"{a} / {b} = {c_actual}"); Console.Write("\n"); Assert.IsTrue(MultiPrecision <Pow2.N8> .NearlyEqualBits(c_expect, c_actual, 1)); } } } }