diff --git a/X10D/src/DoubleExtensions/DoubleExtensions.cs b/X10D/src/DoubleExtensions/DoubleExtensions.cs index 0fd1898..abc949b 100644 --- a/X10D/src/DoubleExtensions/DoubleExtensions.cs +++ b/X10D/src/DoubleExtensions/DoubleExtensions.cs @@ -19,6 +19,15 @@ public static class DoubleExtensions [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] public static Complex ComplexSqrt(this double value) { + switch (value) + { + case double.PositiveInfinity: + case double.NegativeInfinity: + return Complex.Infinity; + case double.NaN: + return Complex.NaN; + } + double absoluteSqrt = Math.Abs(value).Sqrt(); return new Complex(absoluteSqrt, value >= 0 ? 0 : 1); } diff --git a/X10D/src/SingleExtensions/SingleExtensions.cs b/X10D/src/SingleExtensions/SingleExtensions.cs index 87d5c23..9a98695 100644 --- a/X10D/src/SingleExtensions/SingleExtensions.cs +++ b/X10D/src/SingleExtensions/SingleExtensions.cs @@ -19,6 +19,15 @@ public static class SingleExtensions [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] public static Complex ComplexSqrt(this float value) { + switch (value) + { + case float.PositiveInfinity: + case float.NegativeInfinity: + return Complex.Infinity; + case float.NaN: + return Complex.NaN; + } + float absoluteSqrt = MathF.Abs(value).Sqrt(); return new Complex(absoluteSqrt, value >= 0 ? 0 : 1); }