diff --git a/src/Numerics/Complex32.cs b/src/Numerics/Complex32.cs index db32e73a..3940d721 100644 --- a/src/Numerics/Complex32.cs +++ b/src/Numerics/Complex32.cs @@ -169,8 +169,9 @@ namespace MathNet.Numerics /// The phase or argument of this Complex32 public float Phase { + // NOTE: the special case for negative real numbers fixes negative-zero value behavior. Do not remove. [TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")] - get { return (float)Math.Atan2(_imag, _real); } + get { return _imag == 0f && _real < 0f ? (float)Constants.Pi : (float)Math.Atan2(_imag, _real); } } /// diff --git a/src/Numerics/Complex64.cs b/src/Numerics/Complex64.cs index 9303eb3a..49f7f391 100644 --- a/src/Numerics/Complex64.cs +++ b/src/Numerics/Complex64.cs @@ -162,8 +162,9 @@ namespace MathNet.Numerics /// The phase or argument of this Complex public double Phase { + // NOTE: the special case for negative real numbers fixes negative-zero value behavior. Do not remove. [TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")] - get { return Math.Atan2(_imag, _real); } + get { return _imag == 0d && _real < 0d ? Constants.Pi : Math.Atan2(_imag, _real); } } /// diff --git a/src/UnitTests/LinearAlgebraTests/Complex/Factorization/QRTests.cs b/src/UnitTests/LinearAlgebraTests/Complex/Factorization/QRTests.cs index 1cb4c23b..eb579144 100644 --- a/src/UnitTests/LinearAlgebraTests/Complex/Factorization/QRTests.cs +++ b/src/UnitTests/LinearAlgebraTests/Complex/Factorization/QRTests.cs @@ -707,7 +707,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Factorization for (var i = 0; i < vectorX.Count; i++) { - AssertHelpers.AlmostEqual(test[i], vectorX[i], 9); + AssertHelpers.AlmostEqualAbsolute(test[i], vectorX[i], 9); } // Make sure A didn't change.