You've already forked linux-packaging-mono
Imported Upstream version 5.4.0.167
Former-commit-id: 5624ac747d633e885131e8349322922b6a59baaa
This commit is contained in:
parent
e49d6f06c0
commit
536cd135cc
@@ -2,7 +2,8 @@
|
||||
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Import Project="..\dir.props" />
|
||||
<PropertyGroup>
|
||||
<AssemblyVersion>4.1.0.0</AssemblyVersion>
|
||||
<AssemblyVersion>4.1.1.0</AssemblyVersion>
|
||||
<AssemblyKey>MSFT</AssemblyKey>
|
||||
<IsNETCoreApp>true</IsNETCoreApp>
|
||||
<IsUAP>true</IsUAP>
|
||||
</PropertyGroup>
|
||||
|
||||
@@ -9,6 +9,9 @@ using System.Globalization;
|
||||
namespace System.Numerics
|
||||
{
|
||||
[Serializable]
|
||||
#if !MONO
|
||||
[System.Runtime.CompilerServices.TypeForwardedFrom("System.Numerics, Version=4.0.0.0, PublicKeyToken=b77a5c561934e089")]
|
||||
#endif
|
||||
public struct BigInteger : IFormattable, IComparable, IComparable<BigInteger>, IEquatable<BigInteger>
|
||||
{
|
||||
private const int knMaskHighBit = int.MinValue;
|
||||
|
||||
@@ -13,6 +13,9 @@ namespace System.Numerics
|
||||
/// are real numbers, and i is the imaginary unit, with the property i2= -1.
|
||||
/// </summary>
|
||||
[Serializable]
|
||||
#if !MONO
|
||||
[System.Runtime.CompilerServices.TypeForwardedFrom("System.Numerics, Version=4.0.0.0, PublicKeyToken=b77a5c561934e089")]
|
||||
#endif
|
||||
public struct Complex : IEquatable<Complex>, IFormattable
|
||||
{
|
||||
public static readonly Complex Zero = new Complex(0.0, 0.0);
|
||||
@@ -30,20 +33,21 @@ namespace System.Numerics
|
||||
// This value is used inside Asin and Acos.
|
||||
private static readonly double s_log2 = Math.Log(2.0);
|
||||
|
||||
private double _real;
|
||||
private double _imaginary;
|
||||
// Do not rename, these fields are needed for binary serialization
|
||||
private double m_real;
|
||||
private double m_imaginary;
|
||||
|
||||
public Complex(double real, double imaginary)
|
||||
{
|
||||
_real = real;
|
||||
_imaginary = imaginary;
|
||||
m_real = real;
|
||||
m_imaginary = imaginary;
|
||||
}
|
||||
|
||||
public double Real { get { return _real; } }
|
||||
public double Imaginary { get { return _imaginary; } }
|
||||
public double Real { get { return m_real; } }
|
||||
public double Imaginary { get { return m_imaginary; } }
|
||||
|
||||
public double Magnitude { get { return Abs(this); } }
|
||||
public double Phase { get { return Math.Atan2(_imaginary, _real); } }
|
||||
public double Phase { get { return Math.Atan2(m_imaginary, m_real); } }
|
||||
|
||||
public static Complex FromPolarCoordinates(double magnitude, double phase)
|
||||
{
|
||||
@@ -77,34 +81,34 @@ namespace System.Numerics
|
||||
|
||||
public static Complex operator -(Complex value) /* Unary negation of a complex number */
|
||||
{
|
||||
return new Complex(-value._real, -value._imaginary);
|
||||
return new Complex(-value.m_real, -value.m_imaginary);
|
||||
}
|
||||
|
||||
public static Complex operator +(Complex left, Complex right)
|
||||
{
|
||||
return new Complex(left._real + right._real, left._imaginary + right._imaginary);
|
||||
return new Complex(left.m_real + right.m_real, left.m_imaginary + right.m_imaginary);
|
||||
}
|
||||
|
||||
public static Complex operator -(Complex left, Complex right)
|
||||
{
|
||||
return new Complex(left._real - right._real, left._imaginary - right._imaginary);
|
||||
return new Complex(left.m_real - right.m_real, left.m_imaginary - right.m_imaginary);
|
||||
}
|
||||
|
||||
public static Complex operator *(Complex left, Complex right)
|
||||
{
|
||||
// Multiplication: (a + bi)(c + di) = (ac -bd) + (bc + ad)i
|
||||
double result_Realpart = (left._real * right._real) - (left._imaginary * right._imaginary);
|
||||
double result_Imaginarypart = (left._imaginary * right._real) + (left._real * right._imaginary);
|
||||
return new Complex(result_Realpart, result_Imaginarypart);
|
||||
double result_realpart = (left.m_real * right.m_real) - (left.m_imaginary * right.m_imaginary);
|
||||
double result_imaginarypart = (left.m_imaginary * right.m_real) + (left.m_real * right.m_imaginary);
|
||||
return new Complex(result_realpart, result_imaginarypart);
|
||||
}
|
||||
|
||||
public static Complex operator /(Complex left, Complex right)
|
||||
{
|
||||
// Division : Smith's formula.
|
||||
double a = left._real;
|
||||
double b = left._imaginary;
|
||||
double c = right._real;
|
||||
double d = right._imaginary;
|
||||
double a = left.m_real;
|
||||
double b = left.m_imaginary;
|
||||
double c = right.m_real;
|
||||
double d = right.m_imaginary;
|
||||
|
||||
if (Math.Abs(d) < Math.Abs(c))
|
||||
{
|
||||
@@ -120,7 +124,7 @@ namespace System.Numerics
|
||||
|
||||
public static double Abs(Complex value)
|
||||
{
|
||||
return Hypot(value._real, value._imaginary);
|
||||
return Hypot(value.m_real, value.m_imaginary);
|
||||
}
|
||||
|
||||
private static double Hypot(double a, double b)
|
||||
@@ -192,13 +196,13 @@ namespace System.Numerics
|
||||
public static Complex Conjugate(Complex value)
|
||||
{
|
||||
// Conjugate of a Complex number: the conjugate of x+i*y is x-i*y
|
||||
return new Complex(value._real, -value._imaginary);
|
||||
return new Complex(value.m_real, -value.m_imaginary);
|
||||
}
|
||||
|
||||
public static Complex Reciprocal(Complex value)
|
||||
{
|
||||
// Reciprocal of a Complex number : the reciprocal of x+i*y is 1/(x+i*y)
|
||||
if (value._real == 0 && value._imaginary == 0)
|
||||
if (value.m_real == 0 && value.m_imaginary == 0)
|
||||
{
|
||||
return Zero;
|
||||
}
|
||||
@@ -207,12 +211,12 @@ namespace System.Numerics
|
||||
|
||||
public static bool operator ==(Complex left, Complex right)
|
||||
{
|
||||
return left._real == right._real && left._imaginary == right._imaginary;
|
||||
return left.m_real == right.m_real && left.m_imaginary == right.m_imaginary;
|
||||
}
|
||||
|
||||
public static bool operator !=(Complex left, Complex right)
|
||||
{
|
||||
return left._real != right._real || left._imaginary != right._imaginary;
|
||||
return left.m_real != right.m_real || left.m_imaginary != right.m_imaginary;
|
||||
}
|
||||
|
||||
public override bool Equals(object obj)
|
||||
@@ -223,47 +227,47 @@ namespace System.Numerics
|
||||
|
||||
public bool Equals(Complex value)
|
||||
{
|
||||
return _real.Equals(value._real) && _imaginary.Equals(value._imaginary);
|
||||
return m_real.Equals(value.m_real) && m_imaginary.Equals(value.m_imaginary);
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
int n1 = 99999997;
|
||||
int realHash = _real.GetHashCode() % n1;
|
||||
int imaginaryHash = _imaginary.GetHashCode();
|
||||
int realHash = m_real.GetHashCode() % n1;
|
||||
int imaginaryHash = m_imaginary.GetHashCode();
|
||||
int finalHash = realHash ^ imaginaryHash;
|
||||
return finalHash;
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return string.Format(CultureInfo.CurrentCulture, "({0}, {1})", _real, _imaginary);
|
||||
return string.Format(CultureInfo.CurrentCulture, "({0}, {1})", m_real, m_imaginary);
|
||||
}
|
||||
|
||||
public string ToString(string format)
|
||||
{
|
||||
return string.Format(CultureInfo.CurrentCulture, "({0}, {1})", _real.ToString(format, CultureInfo.CurrentCulture), _imaginary.ToString(format, CultureInfo.CurrentCulture));
|
||||
return string.Format(CultureInfo.CurrentCulture, "({0}, {1})", m_real.ToString(format, CultureInfo.CurrentCulture), m_imaginary.ToString(format, CultureInfo.CurrentCulture));
|
||||
}
|
||||
|
||||
public string ToString(IFormatProvider provider)
|
||||
{
|
||||
return string.Format(provider, "({0}, {1})", _real, _imaginary);
|
||||
return string.Format(provider, "({0}, {1})", m_real, m_imaginary);
|
||||
}
|
||||
|
||||
public string ToString(string format, IFormatProvider provider)
|
||||
{
|
||||
return string.Format(provider, "({0}, {1})", _real.ToString(format, provider), _imaginary.ToString(format, provider));
|
||||
return string.Format(provider, "({0}, {1})", m_real.ToString(format, provider), m_imaginary.ToString(format, provider));
|
||||
}
|
||||
|
||||
public static Complex Sin(Complex value)
|
||||
{
|
||||
// We need both sinh and cosh of imaginary part. To avoid multiple calls to Math.Exp with the same value,
|
||||
// we compute them both here from a single call to Math.Exp.
|
||||
double p = Math.Exp(value._imaginary);
|
||||
double p = Math.Exp(value.m_imaginary);
|
||||
double q = 1.0 / p;
|
||||
double sinh = (p - q) * 0.5;
|
||||
double cosh = (p + q) * 0.5;
|
||||
return new Complex(Math.Sin(value._real) * cosh, Math.Cos(value._real) * sinh);
|
||||
return new Complex(Math.Sin(value.m_real) * cosh, Math.Cos(value.m_real) * sinh);
|
||||
// There is a known limitation with this algorithm: inputs that cause sinh and cosh to overflow, but for
|
||||
// which sin or cos are small enough that sin * cosh or cos * sinh are still representable, nonetheless
|
||||
// produce overflow. For example, Sin((0.01, 711.0)) should produce (~3.0E306, PositiveInfinity), but
|
||||
@@ -274,8 +278,8 @@ namespace System.Numerics
|
||||
public static Complex Sinh(Complex value)
|
||||
{
|
||||
// Use sinh(z) = -i sin(iz) to compute via sin(z).
|
||||
Complex sin = Sin(new Complex(-value._imaginary, value._real));
|
||||
return new Complex(sin._imaginary, -sin._real);
|
||||
Complex sin = Sin(new Complex(-value.m_imaginary, value.m_real));
|
||||
return new Complex(sin.m_imaginary, -sin.m_real);
|
||||
}
|
||||
|
||||
public static Complex Asin(Complex value)
|
||||
@@ -300,18 +304,18 @@ namespace System.Numerics
|
||||
}
|
||||
|
||||
public static Complex Cos(Complex value) {
|
||||
double p = Math.Exp(value._imaginary);
|
||||
double p = Math.Exp(value.m_imaginary);
|
||||
double q = 1.0 / p;
|
||||
double sinh = (p - q) * 0.5;
|
||||
double cosh = (p + q) * 0.5;
|
||||
return new Complex(Math.Cos(value._real) * cosh, -Math.Sin(value._real) * sinh);
|
||||
return new Complex(Math.Cos(value.m_real) * cosh, -Math.Sin(value.m_real) * sinh);
|
||||
}
|
||||
|
||||
[SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Cosh", Justification = "Cosh is the name of a mathematical function.")]
|
||||
public static Complex Cosh(Complex value)
|
||||
{
|
||||
// Use cosh(z) = cos(iz) to compute via cos(z).
|
||||
return Cos(new Complex(-value._imaginary, value._real));
|
||||
return Cos(new Complex(-value.m_imaginary, value.m_real));
|
||||
}
|
||||
|
||||
public static Complex Acos(Complex value)
|
||||
@@ -346,12 +350,12 @@ namespace System.Numerics
|
||||
// tan z = (sin(2x) / cosh(2y) + i \tanh(2y)) / (1 + cos(2x) / cosh(2y))
|
||||
// which correctly computes the (tiny) real part and the (normal-sized) imaginary part.
|
||||
|
||||
double x2 = 2.0 * value._real;
|
||||
double y2 = 2.0 * value._imaginary;
|
||||
double x2 = 2.0 * value.m_real;
|
||||
double y2 = 2.0 * value.m_imaginary;
|
||||
double p = Math.Exp(y2);
|
||||
double q = 1.0 / p;
|
||||
double cosh = (p + q) * 0.5;
|
||||
if (Math.Abs(value._imaginary) <= 4.0)
|
||||
if (Math.Abs(value.m_imaginary) <= 4.0)
|
||||
{
|
||||
double sinh = (p - q) * 0.5;
|
||||
double D = Math.Cos(x2) + cosh;
|
||||
@@ -368,8 +372,8 @@ namespace System.Numerics
|
||||
public static Complex Tanh(Complex value)
|
||||
{
|
||||
// Use tanh(z) = -i tan(iz) to compute via tan(z).
|
||||
Complex tan = Tan(new Complex(-value._imaginary, value._real));
|
||||
return new Complex(tan._imaginary, -tan._real);
|
||||
Complex tan = Tan(new Complex(-value.m_imaginary, value.m_real));
|
||||
return new Complex(tan.m_imaginary, -tan.m_real);
|
||||
}
|
||||
|
||||
public static Complex Atan(Complex value)
|
||||
@@ -498,7 +502,7 @@ namespace System.Numerics
|
||||
|
||||
public static Complex Log(Complex value)
|
||||
{
|
||||
return new Complex(Math.Log(Abs(value)), Math.Atan2(value._imaginary, value._real));
|
||||
return new Complex(Math.Log(Abs(value)), Math.Atan2(value.m_imaginary, value.m_real));
|
||||
}
|
||||
|
||||
public static Complex Log(Complex value, double baseValue)
|
||||
@@ -514,9 +518,9 @@ namespace System.Numerics
|
||||
|
||||
public static Complex Exp(Complex value)
|
||||
{
|
||||
double expReal = Math.Exp(value._real);
|
||||
double cosImaginary = expReal * Math.Cos(value._imaginary);
|
||||
double sinImaginary = expReal * Math.Sin(value._imaginary);
|
||||
double expReal = Math.Exp(value.m_real);
|
||||
double cosImaginary = expReal * Math.Cos(value.m_imaginary);
|
||||
double sinImaginary = expReal * Math.Sin(value.m_imaginary);
|
||||
return new Complex(cosImaginary, sinImaginary);
|
||||
}
|
||||
|
||||
@@ -524,16 +528,16 @@ namespace System.Numerics
|
||||
public static Complex Sqrt(Complex value)
|
||||
{
|
||||
|
||||
if (value._imaginary == 0.0)
|
||||
if (value.m_imaginary == 0.0)
|
||||
{
|
||||
// Handle the trivial case quickly.
|
||||
if (value._real < 0.0)
|
||||
if (value.m_real < 0.0)
|
||||
{
|
||||
return new Complex(0.0, Math.Sqrt(-value._real));
|
||||
return new Complex(0.0, Math.Sqrt(-value.m_real));
|
||||
}
|
||||
else
|
||||
{
|
||||
return new Complex(Math.Sqrt(value._real), 0.0);
|
||||
return new Complex(Math.Sqrt(value.m_real), 0.0);
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -566,35 +570,35 @@ namespace System.Numerics
|
||||
// make the result representable. To avoid this, we re-scale (by exact powers of 2 for accuracy)
|
||||
// when we encounter very large components to avoid intermediate infinities.
|
||||
bool rescale = false;
|
||||
if ((Math.Abs(value._real) >= s_sqrtRescaleThreshold) || (Math.Abs(value._imaginary) >= s_sqrtRescaleThreshold))
|
||||
if ((Math.Abs(value.m_real) >= s_sqrtRescaleThreshold) || (Math.Abs(value.m_imaginary) >= s_sqrtRescaleThreshold))
|
||||
{
|
||||
if (double.IsInfinity(value._imaginary) && !double.IsNaN(value._real))
|
||||
if (double.IsInfinity(value.m_imaginary) && !double.IsNaN(value.m_real))
|
||||
{
|
||||
// We need to handle infinite imaginary parts specially because otherwise
|
||||
// our formulas below produce inf/inf = NaN. The NaN test is necessary
|
||||
// so that we return NaN rather than (+inf,inf) for (NaN,inf).
|
||||
return (new Complex(double.PositiveInfinity, value._imaginary));
|
||||
return (new Complex(double.PositiveInfinity, value.m_imaginary));
|
||||
}
|
||||
else
|
||||
{
|
||||
value._real *= 0.25;
|
||||
value._imaginary *= 0.25;
|
||||
value.m_real *= 0.25;
|
||||
value.m_imaginary *= 0.25;
|
||||
rescale = true;
|
||||
}
|
||||
}
|
||||
|
||||
// This is the core of the algorithm. Everything else is special case handling.
|
||||
double x, y;
|
||||
if (value._real >= 0.0)
|
||||
if (value.m_real >= 0.0)
|
||||
{
|
||||
x = Math.Sqrt((Hypot(value._real, value._imaginary) + value._real) * 0.5);
|
||||
y = value._imaginary / (2.0 * x);
|
||||
x = Math.Sqrt((Hypot(value.m_real, value.m_imaginary) + value.m_real) * 0.5);
|
||||
y = value.m_imaginary / (2.0 * x);
|
||||
}
|
||||
else
|
||||
{
|
||||
y = Math.Sqrt((Hypot(value._real, value._imaginary) - value._real) * 0.5);
|
||||
if (value._imaginary < 0.0) y = -y;
|
||||
x = value._imaginary / (2.0 * y);
|
||||
y = Math.Sqrt((Hypot(value.m_real, value.m_imaginary) - value.m_real) * 0.5);
|
||||
if (value.m_imaginary < 0.0) y = -y;
|
||||
x = value.m_imaginary / (2.0 * y);
|
||||
}
|
||||
|
||||
if (rescale)
|
||||
@@ -621,10 +625,10 @@ namespace System.Numerics
|
||||
return Zero;
|
||||
}
|
||||
|
||||
double valueReal = value._real;
|
||||
double valueImaginary = value._imaginary;
|
||||
double powerReal = power._real;
|
||||
double powerImaginary = power._imaginary;
|
||||
double valueReal = value.m_real;
|
||||
double valueImaginary = value.m_imaginary;
|
||||
double powerReal = power.m_real;
|
||||
double powerImaginary = power.m_imaginary;
|
||||
|
||||
double rho = Abs(value);
|
||||
double theta = Math.Atan2(valueImaginary, valueReal);
|
||||
@@ -642,8 +646,8 @@ namespace System.Numerics
|
||||
|
||||
private static Complex Scale(Complex value, double factor)
|
||||
{
|
||||
double realResult = factor * value._real;
|
||||
double imaginaryResuilt = factor * value._imaginary;
|
||||
double realResult = factor * value.m_real;
|
||||
double imaginaryResuilt = factor * value.m_imaginary;
|
||||
return new Complex(realResult, imaginaryResuilt);
|
||||
}
|
||||
|
||||
|
||||
@@ -35,15 +35,31 @@ namespace BigIntTools
|
||||
}
|
||||
}
|
||||
|
||||
private static readonly TypeInfo s_internalCalculator =
|
||||
typeof(BigInteger).GetTypeInfo()
|
||||
.Assembly
|
||||
.GetType("System.Numerics.BigIntegerCalculator")
|
||||
.GetTypeInfo();
|
||||
private static TypeInfo InternalCalculator
|
||||
{
|
||||
get
|
||||
{
|
||||
if (s_lazyInternalCalculator == null)
|
||||
{
|
||||
Type t = typeof(BigInteger).Assembly.GetType("System.Numerics.BigIntegerCalculator");
|
||||
if (t != null)
|
||||
{
|
||||
s_lazyInternalCalculator = t.GetTypeInfo();
|
||||
}
|
||||
}
|
||||
return s_lazyInternalCalculator;
|
||||
}
|
||||
}
|
||||
|
||||
private static volatile TypeInfo s_lazyInternalCalculator;
|
||||
|
||||
public static void RunWithFakeThreshold(string name, int value, Action action)
|
||||
{
|
||||
FieldInfo field = s_internalCalculator.GetDeclaredField(name);
|
||||
TypeInfo internalCalculator = InternalCalculator;
|
||||
if (internalCalculator == null)
|
||||
return; // Internal frame types are not reflectable on AoT platforms. Skip the test.
|
||||
|
||||
FieldInfo field = internalCalculator.GetDeclaredField(name);
|
||||
int lastValue = (int)field.GetValue(null);
|
||||
field.SetValue(null, value);
|
||||
try
|
||||
|
||||
@@ -363,11 +363,11 @@ namespace System.Numerics.Tests
|
||||
{
|
||||
IComparable comparable = new BigInteger();
|
||||
Assert.Equal(1, comparable.CompareTo(null));
|
||||
Assert.Throws<ArgumentException>(paramName, () => comparable.CompareTo(0)); // Obj is not a BigInteger
|
||||
AssertExtensions.Throws<ArgumentException>(paramName, () => comparable.CompareTo(0)); // Obj is not a BigInteger
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[SkipOnTargetFramework(TargetFrameworkMonikers.Netcoreapp | TargetFrameworkMonikers.Uap)]
|
||||
[SkipOnTargetFramework(~TargetFrameworkMonikers.NetFramework)] // Desktop misses Exception.ParamName fixed in .NETCore
|
||||
public static void IComparable_Invalid_net46()
|
||||
{
|
||||
IComparable_Invalid(null);
|
||||
|
||||
@@ -9,8 +9,6 @@ namespace System.Numerics.Tests
|
||||
{
|
||||
public static class MyBigIntImp
|
||||
{
|
||||
public static BigInteger outParam = 0;
|
||||
|
||||
public static BigInteger DoUnaryOperatorMine(BigInteger num1, string op)
|
||||
{
|
||||
List<byte> bytes1 = new List<byte>(num1.ToByteArray());
|
||||
@@ -91,10 +89,18 @@ namespace System.Numerics.Tests
|
||||
}
|
||||
|
||||
public static BigInteger DoBinaryOperatorMine(BigInteger num1, BigInteger num2, string op)
|
||||
{
|
||||
BigInteger num3;
|
||||
|
||||
return DoBinaryOperatorMine(num1, num2, op, out num3);
|
||||
}
|
||||
|
||||
public static BigInteger DoBinaryOperatorMine(BigInteger num1, BigInteger num2, string op, out BigInteger num3)
|
||||
{
|
||||
List<byte> bytes1 = new List<byte>(num1.ToByteArray());
|
||||
List<byte> bytes2 = new List<byte>(num2.ToByteArray());
|
||||
|
||||
num3 = 0;
|
||||
switch (op)
|
||||
{
|
||||
case "bMin":
|
||||
@@ -123,7 +129,7 @@ namespace System.Numerics.Tests
|
||||
BigInteger ret = new BigInteger(Divide(bytes1, bytes2).ToArray());
|
||||
bytes1 = new List<byte>(num1.ToByteArray());
|
||||
bytes2 = new List<byte>(num2.ToByteArray());
|
||||
outParam = new BigInteger(Remainder(bytes1, bytes2).ToArray());
|
||||
num3 = new BigInteger(Remainder(bytes1, bytes2).ToArray());
|
||||
return ret;
|
||||
case "bRemainder":
|
||||
case "b%":
|
||||
|
||||
@@ -29,6 +29,7 @@ namespace System.Numerics.Tests
|
||||
[InlineData(100000, 4096, 4096)]
|
||||
[InlineData(100000, 16384, 16384)]
|
||||
[InlineData(100000, 65536, 65536)]
|
||||
[ActiveIssue(18248)]
|
||||
public void Add(int count, int leftBits, int rightBits)
|
||||
{
|
||||
RunBenchmark(count, leftBits, rightBits, (l, r) => BigInteger.Add(l, r));
|
||||
@@ -42,6 +43,7 @@ namespace System.Numerics.Tests
|
||||
[InlineData(100000, 4096, 4096)]
|
||||
[InlineData(100000, 16384, 16384)]
|
||||
[InlineData(100000, 65536, 65536)]
|
||||
[ActiveIssue(18248)]
|
||||
public void Subtract(int count, int leftBits, int rightBits)
|
||||
{
|
||||
RunBenchmark(count, leftBits, rightBits, (l, r) => BigInteger.Subtract(l, r));
|
||||
@@ -55,6 +57,7 @@ namespace System.Numerics.Tests
|
||||
[InlineData(10000, 4096, 4096)]
|
||||
[InlineData(1000, 16384, 16384)]
|
||||
[InlineData(100, 65536, 65536)]
|
||||
[ActiveIssue(18248)]
|
||||
public void Multiply(int count, int leftBits, int rightBits)
|
||||
{
|
||||
RunBenchmark(count, leftBits, rightBits, (l, r) => BigInteger.Multiply(l, r));
|
||||
@@ -68,6 +71,7 @@ namespace System.Numerics.Tests
|
||||
[InlineData(10000, 4096)]
|
||||
[InlineData(1000, 16384)]
|
||||
[InlineData(100, 65536)]
|
||||
[ActiveIssue(18248)]
|
||||
public void Square(int count, int bits)
|
||||
{
|
||||
RunBenchmark(count, bits, v => BigInteger.Multiply(v, v));
|
||||
@@ -81,6 +85,7 @@ namespace System.Numerics.Tests
|
||||
[InlineData(10000, 4096, 2048)]
|
||||
[InlineData(1000, 16384, 8192)]
|
||||
[InlineData(100, 65536, 32768)]
|
||||
[ActiveIssue(18248)]
|
||||
public void Divide(int count, int leftBits, int rightBits)
|
||||
{
|
||||
RunBenchmark(count, leftBits, rightBits, (l, r) => BigInteger.Divide(l, r));
|
||||
@@ -94,6 +99,7 @@ namespace System.Numerics.Tests
|
||||
[InlineData(10000, 4096, 2048)]
|
||||
[InlineData(1000, 16384, 8192)]
|
||||
[InlineData(100, 65536, 32768)]
|
||||
[ActiveIssue(18248)]
|
||||
public void Remainder(int count, int leftBits, int rightBits)
|
||||
{
|
||||
RunBenchmark(count, leftBits, rightBits, (l, r) => BigInteger.Remainder(l, r));
|
||||
@@ -107,6 +113,7 @@ namespace System.Numerics.Tests
|
||||
[InlineData(10000, 4096, 4096)]
|
||||
[InlineData(1000, 16384, 16384)]
|
||||
[InlineData(100, 65536, 65536)]
|
||||
[ActiveIssue(18248)]
|
||||
public void GreatestCommonDivisor(int count, int leftBits, int rightBits)
|
||||
{
|
||||
RunBenchmark(count, leftBits, rightBits, (l, r) => BigInteger.GreatestCommonDivisor(l, r));
|
||||
@@ -119,6 +126,7 @@ namespace System.Numerics.Tests
|
||||
[InlineData(100, 1024, 1024, 1024)]
|
||||
[InlineData(10, 4096, 4096, 4096)]
|
||||
[InlineData(1, 16384, 16384, 16384)]
|
||||
[ActiveIssue(18248)]
|
||||
public void ModPow(int count, int leftBits, int rightBits, int otherBits)
|
||||
{
|
||||
RunBenchmark(count, leftBits, rightBits, otherBits, (l, r, o) => BigInteger.ModPow(l, r, o));
|
||||
|
||||
@@ -724,7 +724,7 @@ namespace System.Numerics.Tests
|
||||
|
||||
for (int j = 0; j < bigShiftLoopLimit; j++)
|
||||
{
|
||||
temp = temp << (int.MaxValue / 2);
|
||||
temp = temp << (int.MaxValue / 10);
|
||||
VerifyDoubleExplicitCastFromBigInteger(Double.PositiveInfinity, temp);
|
||||
VerifyDoubleExplicitCastFromBigInteger(Double.NegativeInfinity, -temp);
|
||||
}
|
||||
|
||||
@@ -60,7 +60,7 @@ namespace System.Numerics.Tests
|
||||
}
|
||||
}
|
||||
|
||||
[ConditionalFact(nameof(PlatformDetection) + "." + nameof(PlatformDetection.IsNotWindowsSubsystemForLinux))] // https://github.com/Microsoft/BashOnWindows/issues/513
|
||||
[Fact]
|
||||
public static void RunDivideOneLargeOneZeroBI()
|
||||
{
|
||||
byte[] tempByteArray1 = new byte[0];
|
||||
@@ -80,7 +80,7 @@ namespace System.Numerics.Tests
|
||||
}
|
||||
}
|
||||
|
||||
[ConditionalFact(nameof(PlatformDetection) + "." + nameof(PlatformDetection.IsNotWindowsSubsystemForLinux))] // https://github.com/Microsoft/BashOnWindows/issues/513
|
||||
[Fact]
|
||||
public static void RunDivideOneSmallOneZeroBI()
|
||||
{
|
||||
byte[] tempByteArray1 = new byte[0];
|
||||
|
||||
@@ -60,7 +60,7 @@ namespace System.Numerics.Tests
|
||||
}
|
||||
}
|
||||
|
||||
[ConditionalFact(nameof(PlatformDetection) + "." + nameof(PlatformDetection.IsNotWindowsSubsystemForLinux))] // https://github.com/Microsoft/BashOnWindows/issues/513
|
||||
[Fact]
|
||||
public static void RunDivRem_OneLargeOne0BI()
|
||||
{
|
||||
byte[] tempByteArray1 = new byte[0];
|
||||
@@ -80,7 +80,7 @@ namespace System.Numerics.Tests
|
||||
}
|
||||
}
|
||||
|
||||
[ConditionalFact(nameof(PlatformDetection) + "." + nameof(PlatformDetection.IsNotWindowsSubsystemForLinux))] // https://github.com/Microsoft/BashOnWindows/issues/513
|
||||
[Fact]
|
||||
public static void RunDivRem_OneSmallOne0BI()
|
||||
{
|
||||
byte[] tempByteArray1 = new byte[0];
|
||||
@@ -115,7 +115,7 @@ namespace System.Numerics.Tests
|
||||
VerifyDivRemString(Math.Pow(2, 33) + " 2 bDivRem");
|
||||
}
|
||||
|
||||
[ConditionalFact(nameof(PlatformDetection) + "." + nameof(PlatformDetection.IsNotWindowsSubsystemForLinux))] // https://github.com/Microsoft/BashOnWindows/issues/513
|
||||
[Fact]
|
||||
public static void RunDivRemTests()
|
||||
{
|
||||
byte[] tempByteArray1 = new byte[0];
|
||||
|
||||
@@ -159,11 +159,11 @@ namespace System.Numerics.Tests
|
||||
|
||||
for (int j = 0; j<bigShiftLoopLimit; j++)
|
||||
{
|
||||
temp = temp << (int.MaxValue / 2);
|
||||
temp = temp << (int.MaxValue / 10);
|
||||
double expected =
|
||||
(double)startShift +
|
||||
smallShift * (double)(i + 1) +
|
||||
(int.MaxValue / 2) * (double)(j + 1);
|
||||
(int.MaxValue / 10) * (double)(j + 1);
|
||||
Assert.True(ApproxEqual(BigInteger.Log(temp, logbase), expected));
|
||||
}
|
||||
|
||||
|
||||
@@ -33,7 +33,7 @@ namespace System.Numerics.Tests
|
||||
}
|
||||
}
|
||||
|
||||
[ConditionalFact(nameof(PlatformDetection) + "." + nameof(PlatformDetection.IsNotWindowsSubsystemForLinux))] // https://github.com/Microsoft/BashOnWindows/issues/513
|
||||
[Fact]
|
||||
public static void ModPowNegative()
|
||||
{
|
||||
byte[] tempByteArray1;
|
||||
|
||||
@@ -46,7 +46,7 @@ namespace System.Numerics.Tests
|
||||
}
|
||||
}
|
||||
|
||||
[ConditionalFact(nameof(PlatformDetection) + "." + nameof(PlatformDetection.IsNotWindowsSubsystemForLinux))] // https://github.com/Microsoft/BashOnWindows/issues/513
|
||||
[Fact]
|
||||
public static void RunDivideNegative()
|
||||
{
|
||||
byte[] tempByteArray1 = new byte[0];
|
||||
|
||||
@@ -47,7 +47,7 @@ namespace System.Numerics.Tests
|
||||
}
|
||||
}
|
||||
|
||||
[ConditionalFact(nameof(PlatformDetection) + "." + nameof(PlatformDetection.IsNotWindowsSubsystemForLinux))] // https://github.com/Microsoft/BashOnWindows/issues/513
|
||||
[Fact]
|
||||
public static void RunRemainderNegative()
|
||||
{
|
||||
byte[] tempByteArray1 = new byte[0];
|
||||
|
||||
@@ -12,7 +12,7 @@ namespace System.Numerics.Tests
|
||||
private static int s_samples = 10;
|
||||
private static Random s_random = new Random(100);
|
||||
|
||||
[ConditionalFact(nameof(PlatformDetection) + "." + nameof(PlatformDetection.IsNotWindowsSubsystemForLinux))] // https://github.com/Microsoft/BashOnWindows/issues/513
|
||||
[Fact]
|
||||
public static void RunZeroTests()
|
||||
{
|
||||
BigInteger bigInteger;
|
||||
|
||||
@@ -47,7 +47,7 @@ namespace System.Numerics.Tests
|
||||
}
|
||||
}
|
||||
|
||||
[ConditionalFact(nameof(PlatformDetection) + "." + nameof(PlatformDetection.IsNotWindowsSubsystemForLinux))] // https://github.com/Microsoft/BashOnWindows/issues/513
|
||||
[Fact]
|
||||
public static void RunRemainderNegative()
|
||||
{
|
||||
byte[] tempByteArray1 = new byte[0];
|
||||
|
||||
@@ -65,11 +65,11 @@ namespace System.Numerics.Tests
|
||||
|
||||
snnum1 = snCalc.Pop();
|
||||
snnum2 = snCalc.Pop();
|
||||
snCalc.Push(DoBinaryOperatorSN(snnum1, snnum2, op));
|
||||
snCalc.Push(DoBinaryOperatorSN(snnum1, snnum2, op, out _snOut));
|
||||
|
||||
mynum1 = myCalc.Pop();
|
||||
mynum2 = myCalc.Pop();
|
||||
myCalc.Push(MyBigIntImp.DoBinaryOperatorMine(mynum1, mynum2, op));
|
||||
myCalc.Push(MyBigIntImp.DoBinaryOperatorMine(mynum1, mynum2, op, out _myOut));
|
||||
|
||||
ret = true;
|
||||
}
|
||||
@@ -176,6 +176,14 @@ namespace System.Numerics.Tests
|
||||
|
||||
private BigInteger DoBinaryOperatorSN(BigInteger num1, BigInteger num2, string op)
|
||||
{
|
||||
BigInteger num3;
|
||||
|
||||
return DoBinaryOperatorSN(num1, num2, op, out num3);
|
||||
}
|
||||
|
||||
private BigInteger DoBinaryOperatorSN(BigInteger num1, BigInteger num2, string op, out BigInteger num3)
|
||||
{
|
||||
num3 = 0;
|
||||
switch (op)
|
||||
{
|
||||
case "bMin":
|
||||
@@ -210,10 +218,7 @@ namespace System.Numerics.Tests
|
||||
int arg2 = (int)num2;
|
||||
return BigInteger.Pow(num1, arg2);
|
||||
case "bDivRem":
|
||||
BigInteger num3;
|
||||
BigInteger ret = BigInteger.DivRem(num1, num2, out num3);
|
||||
SetSNOutCheck(num3);
|
||||
return ret;
|
||||
return BigInteger.DivRem(num1, num2, out num3);
|
||||
case "bRemainder":
|
||||
return BigInteger.Remainder(num1, num2);
|
||||
case "bDivide":
|
||||
@@ -239,18 +244,13 @@ namespace System.Numerics.Tests
|
||||
throw new ArgumentException(String.Format("Invalid operation found: {0}", op));
|
||||
}
|
||||
}
|
||||
|
||||
private void SetSNOutCheck(BigInteger value)
|
||||
{
|
||||
_snOut = value;
|
||||
}
|
||||
|
||||
public void VerifyOutParameter()
|
||||
{
|
||||
Assert.Equal(_snOut, MyBigIntImp.outParam);
|
||||
Assert.Equal(_snOut, _myOut);
|
||||
|
||||
_snOut = 0;
|
||||
MyBigIntImp.outParam = 0;
|
||||
_myOut = 0;
|
||||
}
|
||||
|
||||
private static String Print(byte[] bytes)
|
||||
|
||||
@@ -14,7 +14,7 @@ namespace System.Numerics.Tests
|
||||
{
|
||||
private static Random s_random = new Random(-55);
|
||||
private static bool Is64Bit => IntPtr.Size == 8;
|
||||
|
||||
|
||||
public static readonly double[] s_validDoubleValues = new double[]
|
||||
{
|
||||
double.MinValue,
|
||||
@@ -206,7 +206,7 @@ namespace System.Numerics.Tests
|
||||
var complex = new Complex(real, imaginary);
|
||||
VerifyRealImaginaryProperties(complex, real, imaginary);
|
||||
}
|
||||
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(Primitives_2_TestData))]
|
||||
[MemberData(nameof(Random_2_TestData))]
|
||||
@@ -333,8 +333,10 @@ namespace System.Numerics.Tests
|
||||
VerifyRealImaginaryProperties(result, expectedReal, expectedImaginary);
|
||||
}
|
||||
|
||||
public static IEnumerable<object[]> ACos_Legacy_TestData ()
|
||||
public static IEnumerable<object[]> ACos_Legacy_TestData()
|
||||
{
|
||||
// These tests validate legacy .NET Framework behavior.
|
||||
|
||||
// Boundary values
|
||||
yield return new object[] { double.MaxValue, 0, double.NaN, double.NaN };
|
||||
yield return new object[] { double.MinValue, 0, double.NaN, double.NaN };
|
||||
@@ -351,7 +353,7 @@ namespace System.Numerics.Tests
|
||||
}
|
||||
}
|
||||
|
||||
[Theory, MemberData("ACos_Legacy_TestData")]
|
||||
[Theory, MemberData(nameof(ACos_Legacy_TestData))]
|
||||
[SkipOnTargetFramework(~TargetFrameworkMonikers.NetFramework)]
|
||||
public static void ACos_Legacy(double real, double imaginary, double expectedReal, double expectedImaginary)
|
||||
{
|
||||
@@ -435,7 +437,7 @@ namespace System.Numerics.Tests
|
||||
yield return new object[] { 0.0, double.NaN, double.NaN, double.NaN };
|
||||
yield return new object[] { double.PositiveInfinity, double.NaN, double.NaN, double.NaN };
|
||||
yield return new object[] { double.NaN, 1.0, double.NaN, double.NaN };
|
||||
yield return new object[] { double.NaN, double.NegativeInfinity, double.NaN, double.NaN };
|
||||
yield return new object[] { double.NaN, double.NegativeInfinity, double.NaN, double.NaN };
|
||||
}
|
||||
|
||||
[ActiveIssue(15455)]
|
||||
@@ -450,6 +452,8 @@ namespace System.Numerics.Tests
|
||||
|
||||
public static IEnumerable<object[]> ASin_Legacy_TestData()
|
||||
{
|
||||
// These tests validate legacy .NET Framework behavior.
|
||||
|
||||
// Boundary values
|
||||
yield return new object[] { double.MaxValue, 0, double.NaN, double.NaN };
|
||||
yield return new object[] { double.MinValue, 0, double.NaN, double.NaN };
|
||||
@@ -466,7 +470,7 @@ namespace System.Numerics.Tests
|
||||
}
|
||||
}
|
||||
|
||||
[Theory, MemberData("ASin_Legacy_TestData")]
|
||||
[Theory, MemberData(nameof(ASin_Legacy_TestData))]
|
||||
[SkipOnTargetFramework(~TargetFrameworkMonikers.NetFramework)]
|
||||
public static void ASin_Legacy(double real, double imaginary, double expectedReal, double expectedImaginary)
|
||||
{
|
||||
@@ -517,7 +521,7 @@ namespace System.Numerics.Tests
|
||||
Complex result = Complex.Atan(complex);
|
||||
VerifyRealImaginaryProperties(result, expectedReal, expectedImaginary);
|
||||
}
|
||||
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(Primitives_2_TestData))]
|
||||
[MemberData(nameof(Boundaries_2_TestData))]
|
||||
@@ -547,7 +551,7 @@ namespace System.Numerics.Tests
|
||||
Cos_Advanced(real, imaginary, expected.Real, expected.Imaginary);
|
||||
}
|
||||
|
||||
public static IEnumerable<object[]> Cos_Advanced_TestData()
|
||||
public static IEnumerable<object[]> Cos_Advanced_TestData_Shared()
|
||||
{
|
||||
// Boundary values
|
||||
yield return new object[] { double.MaxValue, 0, Math.Cos(double.MaxValue), 0 };
|
||||
@@ -556,9 +560,6 @@ namespace System.Numerics.Tests
|
||||
yield return new object[] { 0, double.MaxValue, double.PositiveInfinity, double.NaN };
|
||||
yield return new object[] { 0, double.MinValue, double.PositiveInfinity, double.NaN };
|
||||
|
||||
yield return new object[] { double.MaxValue, double.MaxValue, Math.Cos(double.MaxValue) * double.PositiveInfinity, double.NegativeInfinity };
|
||||
yield return new object[] { double.MinValue, double.MinValue, double.NegativeInfinity, double.NegativeInfinity };
|
||||
|
||||
// Invalid values
|
||||
foreach (double invalidReal in s_invalidDoubleValues)
|
||||
{
|
||||
@@ -582,7 +583,16 @@ namespace System.Numerics.Tests
|
||||
}
|
||||
}
|
||||
|
||||
[ConditionalTheory(nameof(Is64Bit)), MemberData(nameof(Cos_Advanced_TestData))]
|
||||
public static IEnumerable<object[]> Cos_Advanced_TestData()
|
||||
{
|
||||
yield return new object[] { double.MaxValue, double.MaxValue, Math.Cos(double.MaxValue) * double.PositiveInfinity, Math.Cos(double.MaxValue) * double.PositiveInfinity };
|
||||
yield return new object[] { double.MinValue, double.MinValue, Math.Cos(double.MaxValue) * double.PositiveInfinity, Math.Cos(double.MaxValue) * double.PositiveInfinity };
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(Cos_Advanced_TestData_Shared))]
|
||||
[MemberData(nameof(Cos_Advanced_TestData))]
|
||||
[SkipOnTargetFramework(TargetFrameworkMonikers.NetFramework)]
|
||||
public static void Cos_Advanced(double real, double imaginary, double expectedReal, double expectedImaginary)
|
||||
{
|
||||
var complex = new Complex(real, imaginary);
|
||||
@@ -590,6 +600,26 @@ namespace System.Numerics.Tests
|
||||
VerifyRealImaginaryProperties(result, expectedReal, expectedImaginary);
|
||||
}
|
||||
|
||||
public static IEnumerable<object[]> Cos_Legacy_TestData()
|
||||
{
|
||||
// These tests validate legacy .NET Framework behavior.
|
||||
|
||||
yield return new object[] { double.MaxValue, double.MaxValue, double.PositiveInfinity, double.NegativeInfinity };
|
||||
yield return new object[] { double.MinValue, double.MinValue, double.NegativeInfinity, double.NegativeInfinity };
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(Cos_Advanced_TestData_Shared))]
|
||||
[MemberData(nameof(Cos_Legacy_TestData))]
|
||||
[SkipOnTargetFramework(~TargetFrameworkMonikers.NetFramework)]
|
||||
public static void Cos_Legacy(double real, double imaginary, double expectedReal, double expectedImaginary)
|
||||
{
|
||||
var complex = new Complex(real, imaginary);
|
||||
Complex result = Complex.Cos(complex);
|
||||
VerifyRealImaginaryProperties(result, expectedReal, expectedImaginary);
|
||||
}
|
||||
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(Primitives_2_TestData))]
|
||||
[MemberData(nameof(SmallRandom_2_TestData))]
|
||||
@@ -603,7 +633,7 @@ namespace System.Numerics.Tests
|
||||
Cosh_Advanced(real, imaginary, expected.Real, expected.Imaginary);
|
||||
}
|
||||
|
||||
public static IEnumerable<object[]> Cosh_Advanced_TestData()
|
||||
public static IEnumerable<object[]> Cosh_Advanced_TestData_Shared()
|
||||
{
|
||||
// Boundary values
|
||||
yield return new object[] { double.MaxValue, 0, double.PositiveInfinity, double.NaN };
|
||||
@@ -612,9 +642,6 @@ namespace System.Numerics.Tests
|
||||
yield return new object[] { 0, double.MaxValue, Math.Cos(double.MaxValue), 0 };
|
||||
yield return new object[] { 0, double.MinValue, Math.Cos(double.MinValue), 0 };
|
||||
|
||||
yield return new object[] { double.MaxValue, double.MaxValue, Math.Cos(double.MaxValue) * double.PositiveInfinity, double.PositiveInfinity };
|
||||
yield return new object[] { double.MinValue, double.MinValue, double.NegativeInfinity, double.PositiveInfinity };
|
||||
|
||||
// Invalid values
|
||||
foreach (double invalidReal in s_invalidDoubleValues)
|
||||
{
|
||||
@@ -634,7 +661,16 @@ namespace System.Numerics.Tests
|
||||
}
|
||||
}
|
||||
|
||||
[ConditionalTheory(nameof(Is64Bit)), MemberData(nameof(Cosh_Advanced_TestData))]
|
||||
public static IEnumerable<object[]> Cosh_Advanced_TestData()
|
||||
{
|
||||
yield return new object[] { double.MaxValue, double.MaxValue, Math.Cos(double.MaxValue) * double.PositiveInfinity, Math.Cos(double.MaxValue) * double.NegativeInfinity };
|
||||
yield return new object[] { double.MinValue, double.MinValue, Math.Cos(double.MaxValue) * double.PositiveInfinity, Math.Cos(double.MaxValue) * double.NegativeInfinity };
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(Cosh_Advanced_TestData_Shared))]
|
||||
[MemberData(nameof(Cosh_Advanced_TestData))]
|
||||
[SkipOnTargetFramework(TargetFrameworkMonikers.NetFramework)]
|
||||
public static void Cosh_Advanced(double real, double imaginary, double expectedReal, double expectedImaginary)
|
||||
{
|
||||
var complex = new Complex(real, imaginary);
|
||||
@@ -642,6 +678,25 @@ namespace System.Numerics.Tests
|
||||
VerifyRealImaginaryProperties(result, expectedReal, expectedImaginary);
|
||||
}
|
||||
|
||||
public static IEnumerable<object[]> Cosh_Legacy_TestData()
|
||||
{
|
||||
// These tests validate legacy .NET Framework behavior.
|
||||
|
||||
yield return new object[] { double.MaxValue, double.MaxValue, double.PositiveInfinity, double.PositiveInfinity };
|
||||
yield return new object[] { double.MinValue, double.MinValue, double.NegativeInfinity, double.PositiveInfinity };
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(Cosh_Advanced_TestData_Shared))]
|
||||
[MemberData(nameof(Cosh_Legacy_TestData))]
|
||||
[SkipOnTargetFramework(~TargetFrameworkMonikers.NetFramework)]
|
||||
public static void Cosh_Legacy(double real, double imaginary, double expectedReal, double expectedImaginary)
|
||||
{
|
||||
var complex = new Complex(real, imaginary);
|
||||
Complex result = Complex.Cosh(complex);
|
||||
VerifyRealImaginaryProperties(result, expectedReal, expectedImaginary);
|
||||
}
|
||||
|
||||
public static IEnumerable<object[]> Divide_TestData()
|
||||
{
|
||||
yield return new object[] { 0, 0, 10, 50 }; // 0 / x = 0
|
||||
@@ -830,12 +885,52 @@ namespace System.Numerics.Tests
|
||||
yield return new object[] { double.MinValue, double.MinValue };
|
||||
}
|
||||
|
||||
[ConditionalTheory(nameof(Is64Bit))]
|
||||
[Theory]
|
||||
[MemberData(nameof(Exp_TestData))]
|
||||
[MemberData(nameof(Primitives_2_TestData))]
|
||||
[MemberData(nameof(SmallRandom_2_TestData))]
|
||||
[SkipOnTargetFramework(TargetFrameworkMonikers.NetFramework)]
|
||||
public static void Exp(double real, double imaginary)
|
||||
{
|
||||
Complex expected;
|
||||
// Special case the complex {double.MaxValue, double.MaxValue)
|
||||
if (real == double.MaxValue && imaginary == double.MaxValue)
|
||||
{
|
||||
expected = new Complex(Math.Cos(double.MaxValue) * double.PositiveInfinity, Math.Cos(double.MaxValue) * double.NegativeInfinity);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Verify with e(x+y) = e(x)*e(y) if xy == yx
|
||||
var realComplex = new Complex(real, 0);
|
||||
var imaginaryComplex = new Complex(0, imaginary);
|
||||
|
||||
Complex ri = realComplex * imaginaryComplex;
|
||||
Complex ir = imaginaryComplex * realComplex;
|
||||
if (!ri.Equals(ir))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Complex realExponential = Complex.Exp(realComplex);
|
||||
Complex imaginaryExpontential = Complex.Exp(imaginaryComplex);
|
||||
expected = realExponential * imaginaryExpontential;
|
||||
}
|
||||
|
||||
var complex = new Complex(real, imaginary);
|
||||
Complex result = Complex.Exp(complex);
|
||||
VerifyRealImaginaryProperties(result, expected.Real, expected.Imaginary);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(Exp_TestData))]
|
||||
[MemberData(nameof(Primitives_2_TestData))]
|
||||
[MemberData(nameof(SmallRandom_2_TestData))]
|
||||
[SkipOnTargetFramework(~TargetFrameworkMonikers.NetFramework)]
|
||||
public static void Exp_Legacy(double real, double imaginary)
|
||||
{
|
||||
// This test validates legacy .NET Framework behavior.
|
||||
// The behavior of Math.Cos(double.MaxValue) is different and thus affects the expected results here.
|
||||
|
||||
Complex expected;
|
||||
// Special case the complex {double.MaxValue, double.MaxValue)
|
||||
if (real == double.MaxValue && imaginary == double.MaxValue)
|
||||
@@ -885,17 +980,17 @@ namespace System.Numerics.Tests
|
||||
yield return new object[] { magnitude, phase };
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
yield return new object[] { RandomPositiveDouble(), RandomPositivePhase() }; // First quadrant
|
||||
yield return new object[] { RandomNegativeDouble(), RandomPositivePhase() }; // Second quadrant
|
||||
yield return new object[] { RandomNegativeDouble(), RandomNegativePhase() }; // Third quadrant
|
||||
yield return new object[] { RandomPositiveDouble(), RandomNegativePhase() }; // Fourth quadrant
|
||||
}
|
||||
|
||||
[ActiveIssue("https://github.com/dotnet/coreclr/issues/9806")]
|
||||
[Theory]
|
||||
[MemberData(nameof(FromPolarCoordinates_TestData))]
|
||||
[MemberData(nameof(Invalid_2_TestData))]
|
||||
[SkipOnTargetFramework(TargetFrameworkMonikers.NetFramework)]
|
||||
public static void FromPolarCoordinates(double magnitude, double phase)
|
||||
{
|
||||
Complex complex = Complex.FromPolarCoordinates(magnitude, phase);
|
||||
@@ -913,6 +1008,56 @@ namespace System.Numerics.Tests
|
||||
phase = double.NaN;
|
||||
}
|
||||
|
||||
if (double.IsInfinity(complex.Imaginary) && double.IsInfinity(complex.Real))
|
||||
{
|
||||
if (double.IsNegativeInfinity(complex.Imaginary))
|
||||
{
|
||||
if (double.IsNegativeInfinity(complex.Real))
|
||||
{
|
||||
phase = -3 * Math.PI / 4;
|
||||
}
|
||||
else
|
||||
{
|
||||
phase = -Math.PI / 4;
|
||||
}
|
||||
}
|
||||
else if (double.IsNegativeInfinity(complex.Real))
|
||||
{
|
||||
phase = 3 * Math.PI / 4;
|
||||
}
|
||||
else
|
||||
{
|
||||
phase = Math.PI / 4;
|
||||
}
|
||||
}
|
||||
|
||||
VerifyMagnitudePhaseProperties(complex, magnitude, phase);
|
||||
|
||||
complex = new Complex(complex.Real, complex.Imaginary);
|
||||
VerifyMagnitudePhaseProperties(complex, magnitude, phase);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(FromPolarCoordinates_TestData))]
|
||||
[MemberData(nameof(Invalid_2_TestData))]
|
||||
[SkipOnTargetFramework(~TargetFrameworkMonikers.NetFramework)]
|
||||
public static void FromPolarCoordinates_Legacy(double magnitude, double phase)
|
||||
{
|
||||
Complex complex = Complex.FromPolarCoordinates(magnitude, phase);
|
||||
|
||||
// double.IsNaN(magnitude) is checked in the verification method.
|
||||
if (double.IsNaN(phase) || double.IsInfinity(phase))
|
||||
{
|
||||
magnitude = double.NaN;
|
||||
phase = double.NaN;
|
||||
}
|
||||
// Special check in Complex.Abs method
|
||||
else if (double.IsInfinity(magnitude))
|
||||
{
|
||||
magnitude = double.PositiveInfinity;
|
||||
phase = double.NaN;
|
||||
}
|
||||
|
||||
VerifyMagnitudePhaseProperties(complex, magnitude, phase);
|
||||
|
||||
complex = new Complex(complex.Real, complex.Imaginary);
|
||||
@@ -1073,7 +1218,7 @@ namespace System.Numerics.Tests
|
||||
result = Complex.Multiply(left, right);
|
||||
VerifyRealImaginaryProperties(result, expectedReal, expectedImaginary);
|
||||
}
|
||||
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(Valid_2_TestData))]
|
||||
[MemberData(nameof(Random_2_TestData))]
|
||||
@@ -1088,7 +1233,7 @@ namespace System.Numerics.Tests
|
||||
result = Complex.Negate(complex);
|
||||
VerifyRealImaginaryProperties(result, -complex.Real, -complex.Imaginary);
|
||||
}
|
||||
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(Boundaries_2_TestData))]
|
||||
[MemberData(nameof(Primitives_2_TestData))]
|
||||
@@ -1141,7 +1286,7 @@ namespace System.Numerics.Tests
|
||||
VerifyPow_Complex_Complex(real, imaginary, 1, 0);
|
||||
VerifyPow_Complex_Complex(real, imaginary, 0, 1);
|
||||
VerifyPow_Complex_Complex(real, imaginary, 0, -1);
|
||||
|
||||
|
||||
VerifyPow_Complex_Complex(real, imaginary, SmallRandomPositiveDouble(), SmallRandomPositiveDouble()); // First quadrant
|
||||
VerifyPow_Complex_Complex(real, imaginary, SmallRandomNegativeDouble(), SmallRandomPositiveDouble()); // Second quadrant
|
||||
VerifyPow_Complex_Complex(real, imaginary, SmallRandomNegativeDouble(), SmallRandomNegativeDouble()); // Third quadrant
|
||||
@@ -1169,8 +1314,8 @@ namespace System.Numerics.Tests
|
||||
}
|
||||
VerifyRealImaginaryProperties(result, expectedReal, expectedImaginary);
|
||||
}
|
||||
|
||||
[ConditionalTheory(nameof(Is64Bit))]
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(Boundaries_2_TestData))]
|
||||
[MemberData(nameof(Primitives_2_TestData))]
|
||||
[MemberData(nameof(SmallRandom_2_TestData))]
|
||||
@@ -1208,6 +1353,13 @@ namespace System.Numerics.Tests
|
||||
}
|
||||
|
||||
public static IEnumerable<object[]> Sin_Advanced_TestData()
|
||||
{
|
||||
yield return new object[] { double.MaxValue, double.MaxValue, Math.Cos(double.MaxValue) * double.NegativeInfinity, Math.Cos(double.MaxValue) * double.PositiveInfinity };
|
||||
yield return new object[] { double.MinValue, double.MinValue, Math.Cos(double.MaxValue) * double.PositiveInfinity, Math.Cos(double.MaxValue) * double.NegativeInfinity };
|
||||
}
|
||||
|
||||
// Sin() test data for values which are shared across runtimes
|
||||
public static IEnumerable<object[]> Sin_Advanced_TestData_Shared()
|
||||
{
|
||||
yield return new object[] { double.MaxValue, 0, Math.Sin(double.MaxValue), 0 };
|
||||
yield return new object[] { double.MinValue, 0, Math.Sin(double.MinValue), 0 };
|
||||
@@ -1215,9 +1367,6 @@ namespace System.Numerics.Tests
|
||||
yield return new object[] { 0, double.MaxValue, double.NaN, double.PositiveInfinity };
|
||||
yield return new object[] { 0, double.MinValue, double.NaN, double.NegativeInfinity };
|
||||
|
||||
yield return new object[] { double.MaxValue, double.MaxValue, double.PositiveInfinity, Math.Cos(double.MaxValue) * double.PositiveInfinity };
|
||||
yield return new object[] { double.MinValue, double.MinValue, double.NegativeInfinity, double.PositiveInfinity };
|
||||
|
||||
foreach (double invalidReal in s_invalidDoubleValues)
|
||||
{
|
||||
yield return new object[] { invalidReal, 1, double.NaN, double.NaN }; // Invalid real
|
||||
@@ -1234,9 +1383,13 @@ namespace System.Numerics.Tests
|
||||
yield return new object[] { invalidReal, invalidImaginary, double.NaN, double.NaN }; // Invalid real, invalid imaginary
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
[ConditionalTheory(nameof(Is64Bit)), MemberData(nameof(Sin_Advanced_TestData))]
|
||||
[Theory]
|
||||
[MemberData(nameof(Sin_Advanced_TestData_Shared))]
|
||||
[MemberData(nameof(Sin_Advanced_TestData))]
|
||||
[SkipOnTargetFramework(TargetFrameworkMonikers.NetFramework)]
|
||||
public static void Sin_Advanced(double real, double imaginary, double expectedReal, double expectedImaginary)
|
||||
{
|
||||
var complex = new Complex(real, imaginary);
|
||||
@@ -1244,6 +1397,25 @@ namespace System.Numerics.Tests
|
||||
VerifyRealImaginaryProperties(result, expectedReal, expectedImaginary);
|
||||
}
|
||||
|
||||
public static IEnumerable<object[]> Sin_Legacy_TestData()
|
||||
{
|
||||
// These tests validate legacy .NET Framework behavior.
|
||||
|
||||
yield return new object[] { double.MaxValue, double.MaxValue, double.PositiveInfinity, double.PositiveInfinity};
|
||||
yield return new object[] { double.MinValue, double.MinValue, double.NegativeInfinity, double.PositiveInfinity };
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(Sin_Advanced_TestData_Shared))]
|
||||
[MemberData(nameof(Sin_Legacy_TestData))]
|
||||
[SkipOnTargetFramework(~TargetFrameworkMonikers.NetFramework)]
|
||||
public static void Sin_Legacy(double real, double imaginary, double expectedReal, double expectedImaginary)
|
||||
{
|
||||
var complex = new Complex(real, imaginary);
|
||||
Complex result = Complex.Sin(complex);
|
||||
VerifyRealImaginaryProperties(result, expectedReal, expectedImaginary);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(Primitives_2_TestData))]
|
||||
[MemberData(nameof(SmallRandom_2_TestData))]
|
||||
@@ -1257,7 +1429,7 @@ namespace System.Numerics.Tests
|
||||
Sinh_Advanced(real, imaginary, expectedComplex.Real, expectedComplex.Imaginary);
|
||||
}
|
||||
|
||||
public static IEnumerable<object[]> Sinh_Advanced_TestData()
|
||||
public static IEnumerable<object[]> Sinh_Advanced_TestData_Shared()
|
||||
{
|
||||
// Boundary values
|
||||
yield return new object[] { double.MaxValue, 0, double.PositiveInfinity, double.NaN };
|
||||
@@ -1266,9 +1438,6 @@ namespace System.Numerics.Tests
|
||||
yield return new object[] { 0, double.MaxValue, 0, Math.Sin(double.MaxValue) };
|
||||
yield return new object[] { 0, double.MinValue, 0, Math.Sin(double.MinValue) };
|
||||
|
||||
yield return new object[] { double.MaxValue, double.MaxValue, Math.Cos(double.MaxValue) * double.PositiveInfinity, double.PositiveInfinity };
|
||||
yield return new object[] { double.MinValue, double.MinValue, double.PositiveInfinity, double.NegativeInfinity };
|
||||
|
||||
// Invalid values
|
||||
foreach (double invalidReal in s_invalidDoubleValues)
|
||||
{
|
||||
@@ -1288,7 +1457,16 @@ namespace System.Numerics.Tests
|
||||
}
|
||||
}
|
||||
|
||||
[ConditionalTheory(nameof(Is64Bit)), MemberData(nameof(Sinh_Advanced_TestData))]
|
||||
public static IEnumerable<object[]> Sinh_Advanced_TestData()
|
||||
{
|
||||
yield return new object[] { double.MaxValue, double.MaxValue, Math.Cos(double.MaxValue) * double.PositiveInfinity, Math.Cos(double.MaxValue) * double.NegativeInfinity };
|
||||
yield return new object[] { double.MinValue, double.MinValue, Math.Cos(double.MaxValue) * double.NegativeInfinity, Math.Cos(double.MaxValue) * double.PositiveInfinity };
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(Sinh_Advanced_TestData_Shared))]
|
||||
[MemberData(nameof(Sinh_Advanced_TestData))]
|
||||
[SkipOnTargetFramework(TargetFrameworkMonikers.NetFramework)]
|
||||
public static void Sinh_Advanced(double real, double imaginary, double expectedReal, double expectedImaginary)
|
||||
{
|
||||
var complex = new Complex(real, imaginary);
|
||||
@@ -1296,6 +1474,26 @@ namespace System.Numerics.Tests
|
||||
VerifyRealImaginaryProperties(result, expectedReal, expectedImaginary);
|
||||
}
|
||||
|
||||
public static IEnumerable<object[]> Sinh_Legacy_TestData()
|
||||
{
|
||||
// These tests validate legacy .NET Framework behavior.
|
||||
|
||||
yield return new object[] { double.MaxValue, double.MaxValue, double.PositiveInfinity, double.PositiveInfinity };
|
||||
yield return new object[] { double.MinValue, double.MinValue, double.PositiveInfinity, double.NegativeInfinity };
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(Sinh_Advanced_TestData_Shared))]
|
||||
[MemberData(nameof(Sinh_Legacy_TestData))]
|
||||
[SkipOnTargetFramework(~TargetFrameworkMonikers.NetFramework)]
|
||||
public static void Sinh_Legacy(double real, double imaginary, double expectedReal, double expectedImaginary)
|
||||
{
|
||||
var complex = new Complex(real, imaginary);
|
||||
Complex result = Complex.Sinh(complex);
|
||||
VerifyRealImaginaryProperties(result, expectedReal, expectedImaginary);
|
||||
}
|
||||
|
||||
|
||||
public static IEnumerable<object[]> Subtract_TestData()
|
||||
{
|
||||
yield return new object[] { RandomPositiveDouble(), RandomPositiveDouble(), 0, 0 }; // x - 0 = x
|
||||
@@ -1442,7 +1640,7 @@ namespace System.Numerics.Tests
|
||||
|
||||
public static IEnumerable<object[]> Tan_Legacy_TestData()
|
||||
{
|
||||
// These tests validate legacy .NET behavior.
|
||||
// These tests validate legacy .NET Framework behavior.
|
||||
|
||||
yield return new object[] { double.MaxValue, 0, Math.Sin(double.MaxValue) / Math.Cos(double.MaxValue), 0 };
|
||||
yield return new object[] { double.MinValue, 0, Math.Sin(double.MinValue) / Math.Cos(double.MinValue), 0 };
|
||||
|
||||
@@ -53,9 +53,12 @@
|
||||
<Compile Include="BigInteger\stackcalculator.cs" />
|
||||
<Compile Include="BigInteger\ToByteArray.cs" />
|
||||
<Compile Include="ComplexTests.cs" />
|
||||
<Compile Include="$(CommonTestPath)\System\AssertExtensions.cs">
|
||||
<Link>Common\System\AssertExtensions.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="$(CommonTestPath)\System\PlatformDetection.cs">
|
||||
<Link>Common\System\PlatformDetection.cs</Link>
|
||||
</Compile>
|
||||
</ItemGroup>
|
||||
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
|
||||
</Project>
|
||||
</Project>
|
||||
|
||||
Reference in New Issue
Block a user