From 9382d19f00c17d8ea0ee06e3f65a0c777ff4a4bf Mon Sep 17 00:00:00 2001 From: MaLiN2223 Date: Sat, 23 Jan 2016 18:23:50 +0100 Subject: [PATCH] Magnitude of Complex(inf,inf) == inf --- src/Numerics/Complex32.cs | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/Numerics/Complex32.cs b/src/Numerics/Complex32.cs index 2024bb60..6ccd0de3 100644 --- a/src/Numerics/Complex32.cs +++ b/src/Numerics/Complex32.cs @@ -188,6 +188,8 @@ namespace MathNet.Numerics { float a = Math.Abs(_real); float b = Math.Abs(_imag); + if (float.IsPositiveInfinity(a) && float.IsPositiveInfinity(b)) + return float.PositiveInfinity; if (a > b) { double tmp = b / a; @@ -201,8 +203,8 @@ namespace MathNet.Numerics else { double tmp = a / b; - return b*(float)Math.Sqrt(1.0f + tmp*tmp); - } + return b * (float)Math.Sqrt(1.0f + tmp * tmp); + } } } @@ -504,9 +506,9 @@ namespace MathNet.Numerics /// public Tuple CubicRoots() { - float r = (float)Math.Pow(Magnitude, 1d/3d); - float theta = Phase/3; - const float shift = (float)Constants.Pi2/3; + float r = (float)Math.Pow(Magnitude, 1d / 3d); + float theta = Phase / 3; + const float shift = (float)Constants.Pi2 / 3; return new Tuple( FromPolarCoordinates(r, theta), FromPolarCoordinates(r, theta + shift), @@ -676,7 +678,7 @@ namespace MathNet.Numerics float r = d / c; float t = 1 / (c + d * r); float e, f; - if (r!=0.0f) // one can use r >= float.Epsilon || r <= float.Epsilon instead + if (r != 0.0f) // one can use r >= float.Epsilon || r <= float.Epsilon instead { e = (a + b * r) * t; f = (b - a * r) * t;