1
0
mirror of https://github.com/oliverbooth/X10D synced 2024-11-26 12:18:48 +00:00

Improve accuracy of ComplexSqrt

This commit is contained in:
Oliver Booth 2022-04-21 12:26:13 +01:00
parent e7e8d75fba
commit 70b3e9eff3
No known key found for this signature in database
GPG Key ID: 32A00B35503AF634
2 changed files with 4 additions and 2 deletions

View File

@ -19,7 +19,8 @@ public static class DoubleExtensions
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
public static Complex ComplexSqrt(this double value) public static Complex ComplexSqrt(this double value)
{ {
return Complex.Sqrt(value); double absoluteSqrt = Math.Abs(value).Sqrt();
return new Complex(absoluteSqrt, value >= 0 ? 0 : 1);
} }
/// <summary> /// <summary>

View File

@ -19,7 +19,8 @@ public static class SingleExtensions
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
public static Complex ComplexSqrt(this float value) public static Complex ComplexSqrt(this float value)
{ {
return Complex.Sqrt(value); float absoluteSqrt = MathF.Abs(value).Sqrt();
return new Complex(absoluteSqrt, value >= 0 ? 0 : 1);
} }
/// <summary> /// <summary>