Browse Source

BUG: Trigonometry: fix imaginary part sign of complex hyperbolic cotangent #539

v3
Christoph Ruegg 9 years ago
parent
commit
1daa68fbd3
  1. 4
      src/Numerics/Trigonometry.cs
  2. 20
      src/UnitTests/TrigonometryTest.cs

4
src/Numerics/Trigonometry.cs

@ -572,7 +572,7 @@ namespace MathNet.Numerics
var denom = (sini * sini) + (sinhr * sinhr);
return new Complex(sinhr * Cosh(value.Real) / denom, sini * Cos(value.Imaginary) / denom);
return new Complex(sinhr * Cosh(value.Real) / denom, -sini * Cos(value.Imaginary) / denom);
}
/// <summary>
@ -763,4 +763,4 @@ namespace MathNet.Numerics
return (inv + (inv.Square() + 1).SquareRoot()).Ln();
}
}
}
}

20
src/UnitTests/TrigonometryTest.cs

@ -612,7 +612,10 @@ namespace MathNet.Numerics.UnitTests
[TestCase(-1.19209289550780998537e-7, 0.0, -1.1920928955078128e-7, 0.0)]
[TestCase(8.388608e6, 1.19209289550780998537e-7, double.PositiveInfinity, double.PositiveInfinity)]
[TestCase(-8.388608e6, -1.19209289550780998537e-7, double.NegativeInfinity, double.NegativeInfinity)]
[TestCase(0.5, 0.5, 0.45730415318424922, 0.54061268571315335)]
[TestCase(0.5, -0.5, 0.45730415318424922, -0.54061268571315335)]
[TestCase(-0.5, 0.5, -0.45730415318424922, 0.54061268571315335)]
[TestCase(-0.5, -0.5, -0.45730415318424922, -0.54061268571315335)]
public void CanComputeComplexHyperbolicSine(double real, double imag, double expectedReal, double expectedImag)
{
var actual = new Complex(real, imag).Sinh();
@ -634,7 +637,10 @@ namespace MathNet.Numerics.UnitTests
[TestCase(-1.19209289550780998537e-7, 0.0, 1.0000000000000071, 0.0)]
[TestCase(8.388608e6, 1.19209289550780998537e-7, double.PositiveInfinity, double.PositiveInfinity)]
[TestCase(-8.388608e6, -1.19209289550780998537e-7, double.PositiveInfinity, double.PositiveInfinity)]
[TestCase(0.5, 0.5, 0.9895848833999199, 0.24982639750046154)]
[TestCase(0.5, -0.5, 0.9895848833999199, -0.24982639750046154)]
[TestCase(-0.5, 0.5, 0.9895848833999199, -0.24982639750046154)]
[TestCase(-0.5, -0.5, 0.9895848833999199, 0.24982639750046154)]
public void CanComputeComplexHyperbolicCosine(double real, double imag, double expectedReal, double expectedImag)
{
var actual = new Complex(real, imag).Cosh();
@ -656,7 +662,10 @@ namespace MathNet.Numerics.UnitTests
[TestCase(-1.19209289550780998537e-7, 0.0, -1.1920928955078043e-7, 0.0)]
[TestCase(8.388608e6, 1.19209289550780998537e-7, 1.0, 0.0)]
[TestCase(-8.388608e6, -1.19209289550780998537e-7, -1.0, 0.0)]
[TestCase(0.5, 0.5, 0.56408314126749848, 0.40389645531602575)]
[TestCase(0.5, -0.5, 0.56408314126749848, -0.40389645531602575)]
[TestCase(-0.5, 0.5, -0.56408314126749848, 0.40389645531602575)]
[TestCase(-0.5, -0.5, -0.56408314126749848, -0.40389645531602575)]
public void CanComputeComplexHyperbolicTangent(double real, double imag, double expectedReal, double expectedImag)
{
var actual = new Complex(real, imag).Tanh();
@ -678,7 +687,10 @@ namespace MathNet.Numerics.UnitTests
[TestCase(-1.19209289550780998537e-7, 0.0, -8388608.0000000574, 0.0)]
[TestCase(8.388608e6, 1.19209289550780998537e-7, 1.0, 0.0)]
[TestCase(-8.388608e6, -1.19209289550780998537e-7, -1.0, 0.0)]
[TestCase(0.5, -0.5, 1.1719451445243514, -0.8391395790248311)]
[TestCase(0.5, 0.5, 1.1719451445243514, -0.8391395790248311)]
[TestCase(0.5, -0.5, 1.1719451445243514, 0.8391395790248311)]
[TestCase(-0.5, 0.5, -1.1719451445243514, -0.8391395790248311)]
[TestCase(-0.5, -0.5, -1.1719451445243514, 0.8391395790248311)]
public void CanComputeComplexHyperbolicCotangent(double real, double imag, double expectedReal, double expectedImag)
{
var actual = new Complex(real, imag).Coth();
@ -700,7 +712,10 @@ namespace MathNet.Numerics.UnitTests
[TestCase(-1.19209289550780998537e-7, 0.0, 0.99999999999999289, 0.0)]
[TestCase(8.388608e6, 1.19209289550780998537e-7, 0.0, 0.0)]
[TestCase(-8.388608e6, -1.19209289550780998537e-7, -0.0, 0.0)]
[TestCase(0.5, 0.5, 0.94997886761549463, -0.23982763093808804)]
[TestCase(0.5, -0.5, 0.94997886761549463, 0.23982763093808804)]
[TestCase(-0.5, 0.5, 0.94997886761549463, 0.23982763093808804)]
[TestCase(-0.5, -0.5, 0.94997886761549463, -0.23982763093808804)]
public void CanComputeComplexHyperbolicSecant(double real, double imag, double expectedReal, double expectedImag)
{
var actual = new Complex(real, imag).Sech();
@ -722,7 +737,10 @@ namespace MathNet.Numerics.UnitTests
[TestCase(-1.19209289550780998537e-7, 0.0, -8388607.9999999978, 0.0)]
[TestCase(8.388608e6, 1.19209289550780998537e-7, 0.0, 0.0)]
[TestCase(-8.388608e6, -1.19209289550780998537e-7, 0.0, 0.0)]
[TestCase(0.5, 0.5, 0.91207426403881078, -1.0782296946540223)]
[TestCase(0.5, -0.5, 0.91207426403881078, 1.0782296946540223)]
[TestCase(-0.5, 0.5, -0.91207426403881078, -1.0782296946540223)]
[TestCase(-0.5, -0.5, -0.91207426403881078, 1.0782296946540223)]
public void CanComputeComplexHyperbolicCosecant(double real, double imag, double expectedReal, double expectedImag)
{
var actual = new Complex(real, imag).Csch();

Loading…
Cancel
Save