Skip to content

Commit

Permalink
Sync results from optimized and non-potimized versions
Browse files Browse the repository at this point in the history
Commit migrated from dotnet/corefx@8e058d7
  • Loading branch information
kant2002 authored and tannergooding committed Sep 11, 2018
1 parent f253d35 commit aaec403
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 71 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -178,11 +178,6 @@ public static Complex Divide(double dividend, Complex divisor)
double c = right.m_real;
double d = right.m_imaginary;

if (d == 0.0)
{
return left / c;
}

// Computing c * c + d * d will overflow even in cases where the actual result of the division does not overflow.
if (Math.Abs(d) < Math.Abs(c))
{
Expand All @@ -198,6 +193,26 @@ public static Complex Divide(double dividend, Complex divisor)

public static Complex operator /(Complex left, double right)
{
if (right == 0)
{
return new Complex(double.NaN, double.NaN);
}

if (!double.IsFinite(left.m_real) && !double.IsFinite(left.m_imaginary))
{
return new Complex(double.NaN / right, double.NaN);
}

if (!double.IsFinite(left.m_real))
{
return new Complex(left.m_real / right, double.NaN);
}

if (!double.IsFinite(left.m_imaginary))
{
return new Complex(double.NaN, left.m_imaginary / right);
}

return new Complex(left.m_real / right, left.m_imaginary / right);
}

Expand All @@ -208,16 +223,6 @@ public static Complex Divide(double dividend, Complex divisor)
double c = right.m_real;
double d = right.m_imaginary;

if (d == 0.0)
{
if (c == 0.0)
{
return new Complex(left / c, left / c);
}

return left / c;
}

// Computing c * c + d * d will overflow even in cases where the actual result of the division does not overflow.
if (Math.Abs(d) < Math.Abs(c))
{
Expand Down
58 changes: 2 additions & 56 deletions src/libraries/System.Runtime.Numerics/tests/ComplexTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -728,7 +728,8 @@ public static void Cosh_Legacy(double real, double imaginary, double expectedRea
public static IEnumerable<object[]> Divide_TestData()
{
yield return new object[] { 0, 0, 10, 50 }; // 0 / x = 0
yield return new object[] { 10, 50, double.NaN, double.NaN }; // x / NaN = NaN
yield return new object[] { 10, 50, double.NaN, double.NaN }; // 0 / x = NaN
yield return new object[] { 10, 50, 0, 0 }; // x / 0 = 0

yield return new object[] { 1, 0, 10, 50 }; // 1 / x = x
yield return new object[] { 10, 50, 1, 0 }; // x / 1 = x
Expand All @@ -742,13 +743,6 @@ public static IEnumerable<object[]> Divide_TestData()
yield return new object[] { double.MinValue, double.MinValue, SmallRandomPositiveDouble(), SmallRandomPositiveDouble() };
}

public static IEnumerable<object[]> Divide_AdvancedTestData()
{
yield return new object[] { 10, 50, double.NaN, double.NaN, double.NaN, double.NaN }; // 0 / NaN = NaN
yield return new object[] { 10, 50, 0, 0, double.PositiveInfinity, double.PositiveInfinity }; // x / 0 = Inf
yield return new object[] { 0, 0, 0, 0, double.NaN, double.NaN }; // 0 / 0 = NaN
}

[Theory]
[MemberData(nameof(Divide_TestData))]
[MemberData(nameof(SmallRandom_4_TestData))]
Expand Down Expand Up @@ -780,22 +774,6 @@ public static void Divide(double realLeft, double imaginaryLeft, double realRigh
VerifyRealImaginaryProperties(result, expectedReal, expectedImaginary);
}

[Theory]
[MemberData(nameof(Divide_AdvancedTestData))]
public static void Divide_Advanced(double realLeft, double imaginaryLeft, double realRight, double imaginaryRight, double expectedReal, double expectedImaginary)
{
var dividend = new Complex(realLeft, imaginaryLeft);
var divisor = new Complex(realRight, imaginaryRight);

// Operator
Complex result = dividend / divisor;
VerifyRealImaginaryProperties(result, expectedReal, expectedImaginary);

// Static method
result = Complex.Divide(dividend, divisor);
VerifyRealImaginaryProperties(result, expectedReal, expectedImaginary);
}

[Theory]
[MemberData(nameof(Divide_TestData))]
[MemberData(nameof(SmallRandom_4_TestData))]
Expand All @@ -818,22 +796,6 @@ public static void DivideByDouble(double realLeft, double imaginaryLeft, double
VerifyRealImaginaryProperties(result, expectedReal, expectedImaginary);
}

[Theory]
[MemberData(nameof(Divide_AdvancedTestData))]
public static void DivideByDouble_Advanced(double realLeft, double imaginaryLeft, double realRight, double imaginaryRight, double expectedReal, double expectedImaginary)
{
var dividend = new Complex(realLeft, imaginaryLeft);
var divisor = realRight;

// Operator
Complex result = dividend / divisor;
VerifyRealImaginaryProperties(result, expectedReal, expectedImaginary);

// Static method
result = Complex.Divide(dividend, divisor);
VerifyRealImaginaryProperties(result, expectedReal, expectedImaginary);
}

[Theory]
[MemberData(nameof(Divide_TestData))]
[MemberData(nameof(SmallRandom_4_TestData))]
Expand All @@ -856,22 +818,6 @@ public static void DivideByComplex(double realLeft, double imaginaryLeft, double
VerifyRealImaginaryProperties(result, expectedReal, expectedImaginary);
}

[Theory]
[MemberData(nameof(Divide_AdvancedTestData))]
public static void DivideByComplex_Advanced(double realLeft, double imaginaryLeft, double realRight, double imaginaryRight, double expectedReal, double expectedImaginary)
{
var dividend = realLeft;
var divisor = new Complex(realRight, imaginaryRight);

// Operator
Complex result = dividend / divisor;
VerifyRealImaginaryProperties(result, expectedReal, expectedImaginary);

// Static method
result = Complex.Divide(dividend, divisor);
VerifyRealImaginaryProperties(result, expectedReal, expectedImaginary);
}

[Fact]
[SkipOnTargetFramework(TargetFrameworkMonikers.NetFramework)]
public static void Equals_netcore()
Expand Down

0 comments on commit aaec403

Please sign in to comment.