public void ComplexSqrtExtremeValues() { // Max values double sqrtMaxValue = Math.Sqrt(Double.MaxValue); Assert.IsTrue(TestUtilities.IsNearlyEqual(ComplexMath.Sqrt(Double.MaxValue), sqrtMaxValue, TestUtilities.RelativeTarget)); Assert.IsTrue(TestUtilities.IsNearlyEqual(ComplexMath.Sqrt(-Double.MaxValue), sqrtMaxValue * Complex.I, TestUtilities.RelativeTarget)); Assert.IsTrue(TestUtilities.IsNearlyEqual( ComplexMath.Sqrt(Double.MaxValue + Double.MaxValue * Complex.I), Math.Sqrt(Math.Sqrt(2.0)) * sqrtMaxValue * (Math.Cos(Math.PI / 8.0) + Math.Sin(Math.PI / 8.0) * Complex.I), TestUtilities.RelativeTarget)); // One component infinite Assert.IsTrue(ComplexMath.Sqrt(Double.PositiveInfinity) == new Complex(Double.PositiveInfinity, 0.0)); Assert.IsTrue(ComplexMath.Sqrt(Double.NegativeInfinity) == new Complex(0.0, Double.PositiveInfinity)); // Both components infinite Complex ppInfinity = new Complex(Double.PositiveInfinity, Double.PositiveInfinity); Complex pnInfinity = new Complex(Double.PositiveInfinity, Double.NegativeInfinity); Complex nnInfinity = new Complex(Double.NegativeInfinity, Double.NegativeInfinity); Complex npInfinity = new Complex(Double.NegativeInfinity, Double.PositiveInfinity); Assert.IsTrue(ComplexMath.Sqrt(ppInfinity) == ppInfinity); Assert.IsTrue(ComplexMath.Sqrt(pnInfinity) == pnInfinity); Assert.IsTrue(ComplexMath.Sqrt(nnInfinity) == pnInfinity); Assert.IsTrue(ComplexMath.Sqrt(npInfinity) == ppInfinity); // NaNs Assert.IsTrue(Complex.IsNaN(ComplexMath.Sqrt(new Complex(Double.NaN, 0.0)))); Assert.IsTrue(Complex.IsNaN(ComplexMath.Sqrt(new Complex(0.0, Double.NaN)))); Assert.IsTrue(Complex.IsNaN(ComplexMath.Sqrt(new Complex(Double.NaN, Double.MaxValue)))); Assert.IsTrue(Complex.IsNaN(ComplexMath.Sqrt(new Complex(Double.MaxValue, Double.NaN)))); Assert.IsTrue(Complex.IsNaN(ComplexMath.Sqrt(new Complex(Double.NaN, Double.PositiveInfinity)))); Assert.IsTrue(Complex.IsNaN(ComplexMath.Sqrt(new Complex(Double.PositiveInfinity, Double.NaN)))); Assert.IsTrue(Complex.IsNaN(ComplexMath.Sqrt(new Complex(Double.NaN, Double.NaN)))); }
public void ComplexIDefinition() { Assert.IsTrue(ComplexMath.Sqrt(-1.0) == Complex.I); }