Reduce amount of compare operations and add comments
authorAndrii Kurdiumov <kant2002@gmail.com>
Sun, 9 Sep 2018 16:50:53 +0000 (22:50 +0600)
committerTanner Gooding <tagoo@outlook.com>
Tue, 11 Sep 2018 14:27:21 +0000 (07:27 -0700)
Commit migrated from https://github.com/dotnet/corefx/commit/d84177294fec054ff5f1a02780114a5a87eab4e5

src/libraries/System.Runtime.Numerics/src/System/Numerics/Complex.cs

index 802597c..67d45ba 100644 (file)
@@ -193,18 +193,21 @@ namespace System.Numerics
 
         public static Complex operator /(Complex left, double right)
         {
+            // IEEE prohibit optimizations which are value changing
+            // so we make sure that behaviour for the simplified version exactly match
+            // full version.
             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))
             {
+                if (!double.IsFinite(left.m_imaginary))
+                {
+                    return new Complex(double.NaN, double.NaN);
+                }
+
                 return new Complex(left.m_real / right, double.NaN);
             }
 
@@ -213,6 +216,7 @@ namespace System.Numerics
                 return new Complex(double.NaN, left.m_imaginary / right);
             }
 
+            // Here the actual optimized version of code.
             return new Complex(left.m_real / right, left.m_imaginary / right);
         }