Example #1
0
        public void CanDetermineIfNaN()
        {
            var complex = new Complex(double.NaN, 1);

            Assert.IsTrue(complex.IsNaN(), "Real part is NaN.");
            complex = new Complex(1, double.NaN);
            Assert.IsTrue(complex.IsNaN(), "Imaginary part is NaN.");
            complex = new Complex(double.NaN, double.NaN);
            Assert.IsTrue(complex.IsNaN(), "Both parts are NaN.");
        }
Example #2
0
 /// <summary>Gets the degree of a sequence of coefficients which represents a polynomial.
 /// </summary>
 /// <param name="coefficients">The coefficients, where the null-based index corresponds to the power of the argument, i.e. starting from absolute coefficient, first oder coefficient etc.</param>
 /// <returns>The degree of the polynomial which coefficients are specified by <paramref name="coefficients"/>.</returns>
 /// <exception cref="ArgumentNullException">Thrown, if <paramref name="coefficients"/> is <c>null</c>.</exception>
 public static int GetDegree(IList <System.Numerics.Complex> coefficients)
 {
     if (coefficients == null)
     {
         throw new ArgumentNullException(nameof(coefficients), String.Format(CultureInfo.CurrentCulture, ExceptionMessages.ArgumentNull, nameof(coefficients)));
     }
     for (int j = coefficients.Count - 1; j >= 0; j--)
     {
         System.Numerics.Complex coefficient = coefficients[j];
         if ((coefficient.IsNaN() == false) && (Double.IsInfinity(coefficient.Real) == false) && (Double.IsInfinity(coefficient.Imaginary) == false) && (coefficient != 0.0))
         {
             return(j);
         }
     }
     return(0);
 }
        public static void AlmostEqual(Complex expected, Complex actual)
        {
            if (expected.IsNaN() && actual.IsNaN() || expected.IsInfinity() && expected.IsInfinity())
            {
                return;
            }

            if (!expected.Real.AlmostEqual(actual.Real))
            {
                Assert.Fail("Real components are not equal. Expected:{0}; Actual:{1}", expected.Real, actual.Real);
            }

            if (!expected.Imaginary.AlmostEqual(actual.Imaginary))
            {
                Assert.Fail("Imaginary components are not equal. Expected:{0}; Actual:{1}", expected.Imaginary, actual.Imaginary);
            }
        }