1
0
mirror of https://github.com/oliverbooth/X10D synced 2024-11-09 22:55:42 +00:00

Fix incorrect return values for ComplexSqrt

This commit is contained in:
Oliver Booth 2022-04-21 12:44:40 +01:00
parent b8dd5cc8bf
commit 8008a4a9ef
No known key found for this signature in database
GPG Key ID: 32A00B35503AF634
2 changed files with 18 additions and 0 deletions

View File

@ -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);
}

View File

@ -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);
}