Beispiel #1
0
 public void ComplexTrigPeriodicity()
 {
     foreach (Complex z in TestUtilities.GenerateComplexValues(1.0E-2, 1.0E2, 8))
     {
         Assert.IsTrue(TestUtilities.IsNearlyEqual(ComplexMath.Sin(z), ComplexMath.Sin(z + 2.0 * Math.PI)));
         Assert.IsTrue(TestUtilities.IsNearlyEqual(ComplexMath.Cos(z), ComplexMath.Cos(z + 2.0 * Math.PI)));
     }
 }
Beispiel #2
0
 public void ComplexTrigSpecialCases()
 {
     Assert.IsTrue(ComplexMath.Sin(0.0) == Complex.Zero);
     Assert.IsTrue(ComplexMath.Cos(0.0) == Complex.One);
     Assert.IsTrue(ComplexMath.Tan(0.0) == Complex.Zero);
     Assert.IsTrue(TestUtilities.IsNearlyEqual(ComplexMath.Sin(Math.PI / 2.0), 1.0, TestUtilities.RelativeTarget));
     Assert.IsTrue(TestUtilities.IsNearlyEqual(ComplexMath.Tan(Math.PI / 4.0), 1.0, TestUtilities.RelativeTarget));
 }
Beispiel #3
0
 public void ComplexTrigExtremeValues()
 {
     Assert.IsTrue(Complex.IsNaN(ComplexMath.Sin(Double.PositiveInfinity)));
     Assert.IsTrue(Complex.IsNaN(ComplexMath.Sin(Double.NegativeInfinity)));
     Assert.IsTrue(Complex.IsNaN(ComplexMath.Sin(Double.NaN)));
     Assert.IsTrue(Complex.IsNaN(ComplexMath.Cos(Double.PositiveInfinity)));
     Assert.IsTrue(Complex.IsNaN(ComplexMath.Cos(Double.NegativeInfinity)));
     Assert.IsTrue(Complex.IsNaN(ComplexMath.Cos(Double.NaN)));
 }
Beispiel #4
0
 public void ComplexArcTrigInversion()
 {
     foreach (Complex z in TestUtilities.GenerateComplexValues(1.0E-4, 1.0E4, 32))
     {
         Complex asin = ComplexMath.Asin(z);
         Assert.IsTrue(TestUtilities.IsNearlyEqual(ComplexMath.Sin(asin), z));
         Complex acos = ComplexMath.Acos(z);
         Assert.IsTrue(TestUtilities.IsNearlyEqual(ComplexMath.Cos(acos), z));
         Assert.IsTrue(TestUtilities.IsSumNearlyEqual(asin, acos, Math.PI / 2.0));
     }
 }
Beispiel #5
0
 public void ComplexDoubleAngle()
 {
     foreach (Complex z in TestUtilities.GenerateComplexValues(1.0E-4, 1.0E4, 16))
     {
         if (Math.Abs(z.Im) > Math.Log(Double.MaxValue / 10.0))
         {
             continue;
         }
         Assert.IsTrue(TestUtilities.IsNearlyEqual(ComplexMath.Sin(2.0 * z), 2.0 * ComplexMath.Sin(z) * ComplexMath.Cos(z)));
         //Assert.IsTrue(TestUtilities.IsNearlyEqual(ComplexMath.Cos(2.0 * z), ComplexMath.Sqr(ComplexMath.Cos(z)) - ComplexMath.Sqr(ComplexMath.Sin(z))));
     }
 }
Beispiel #6
0
 public void ComplexNegativeAngles()
 {
     foreach (Complex z in TestUtilities.GenerateComplexValues(1.0E-4, 1.0E4, 16))
     {
         if (Math.Abs(z.Im) > Math.Log(Double.MaxValue / 10.0))
         {
             continue;                                                    // sin and cos blow up in imaginary part of argument gets too big
         }
         Assert.IsTrue(TestUtilities.IsNearlyEqual(ComplexMath.Sin(-z), -ComplexMath.Sin(z)), String.Format("remainder {0}", ComplexMath.Sin(-a) + ComplexMath.Sin(a)));
         Assert.IsTrue(TestUtilities.IsNearlyEqual(ComplexMath.Cos(-z), ComplexMath.Cos(z)), String.Format("{0} vs. {1}", ComplexMath.Cos(-a), ComplexMath.Cos(a)));
         Assert.IsTrue(TestUtilities.IsNearlyEqual(ComplexMath.Tan(-z), -ComplexMath.Tan(z)));
     }
 }
Beispiel #7
0
 public void ComplexDoubleAngle()
 {
     foreach (Complex z in TestUtilities.GenerateComplexValues(1.0E-3, 1.0E3, 16))
     {
         // Since sin(z) and cos(z) have factors that go like e^{\pm Im(z)}, they will blow up if the imaginary
         // part of z gets too big. We just skip over those problematic values.
         if (Math.Abs(z.Im) > Math.Log(Double.MaxValue) / 2.0)
         {
             continue;
         }
         Assert.IsTrue(TestUtilities.IsNearlyEqual(ComplexMath.Sin(2.0 * z), 2.0 * ComplexMath.Sin(z) * ComplexMath.Cos(z)));
         Assert.IsTrue(TestUtilities.IsSumNearlyEqual(ComplexMath.Sqr(ComplexMath.Cos(z)), -ComplexMath.Sqr(ComplexMath.Sin(z)), ComplexMath.Cos(2.0 * z)));
     }
 }
Beispiel #8
0
 public void ComplexPythagorean()
 {
     foreach (Complex z in TestUtilities.GenerateComplexValues(1.0E-4, 1.0E4, 16))
     {
         if (Math.Abs(z.Im) > Math.Log(Double.MaxValue / 10.0))
         {
             continue;                                                    // sin and cos blow up in imaginary part of argument gets too big
         }
         Complex sin = ComplexMath.Sin(z);
         Complex cos = ComplexMath.Cos(z);
         Console.WriteLine("z={0} s={1} c={2} s^2+c^2={3}", z, sin, cos, sin * sin + cos * cos);
         Assert.IsTrue(TestUtilities.IsSumNearlyEqual(sin * sin, cos * cos, 1.0));
     }
 }
Beispiel #9
0
 public void ComplexTrigPythagorean()
 {
     foreach (Complex z in TestUtilities.GenerateComplexValues(1.0E-3, 1.0E3, 16))
     {
         // Since sin(z) and cos(z) have factors that go like e^{\pm Im(z)}, they will blow up if the imaginary
         // part of z gets too big. We just skip over those problematic values.
         if (Math.Abs(z.Im) > Math.Log(Double.MaxValue) / 2.0)
         {
             continue;
         }
         Complex sin = ComplexMath.Sin(z);
         Complex cos = ComplexMath.Cos(z);
         Console.WriteLine("z={0} s={1} c={2} s^2+c^2={3}", z, sin, cos, sin * sin + cos * cos);
         Assert.IsTrue(TestUtilities.IsSumNearlyEqual(sin * sin, cos * cos, 1.0));
     }
 }
Beispiel #10
0
 public void ComplexAngleAdditionTest()
 {
     Assert.IsTrue(TestUtilities.IsNearlyEqual(ComplexMath.Sin(a + b), ComplexMath.Sin(a) * ComplexMath.Cos(b) + ComplexMath.Cos(a) * ComplexMath.Sin(b)), String.Format("{0} != {1}", ComplexMath.Sin(a + b), ComplexMath.Sin(a) * ComplexMath.Cos(b) + ComplexMath.Cos(a) * ComplexMath.Sin(b)));
     Assert.IsTrue(TestUtilities.IsNearlyEqual(ComplexMath.Cos(a + b), ComplexMath.Cos(a) * ComplexMath.Cos(b) - ComplexMath.Sin(a) * ComplexMath.Sin(b)));
 }
Beispiel #11
0
 public void ComplexSinSinh()
 {
     foreach (Complex x in TestUtilities.GenerateComplexValues(1.0E-2, 1.0E2, 10))
     {
         Assert.IsTrue(TestUtilities.IsNearlyEqual(ComplexMath.Sinh(x), -ComplexMath.I * ComplexMath.Sin(ComplexMath.I * x)));
         Assert.IsTrue(TestUtilities.IsNearlyEqual(ComplexMath.I * ComplexMath.Sinh(-ComplexMath.I * x), ComplexMath.Sin(x)));
     }
 }