Skip to content

Commit

Permalink
Complex API additions
Browse files Browse the repository at this point in the history
  • Loading branch information
VoidXH committed Oct 16, 2023
1 parent b51f28e commit a403eb4
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
5 changes: 5 additions & 0 deletions Cavern/Utilities/Complex.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ public float Magnitude {
/// </summary>
public float Phase => MathF.Atan2(Imaginary, Real);

/// <summary>
/// Squared magnitude of the complex number.
/// </summary>
public float SqrMagnitude => Real * Real + Imaginary * Imaginary;

/// <summary>
/// Complex number from a scalar.
/// </summary>
Expand Down
15 changes: 15 additions & 0 deletions Cavern/Utilities/ComplexArray.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,21 @@ namespace Cavern.Utilities {
/// Operations on complex arrays.
/// </summary>
public static class ComplexArray {
/// <summary>
/// Add the <paramref name="other"/> array's each element to the same indexes in the <paramref name="source"/>.
/// </summary>
public static unsafe void Add(this Complex[] source, Complex[] other) {
fixed (Complex* pSource = source)
fixed (Complex* pOther = other) {
Complex* lhs = pSource,
rhs = pOther,
end = pSource + source.Length;
while (lhs != end) {
*lhs++ += *rhs++;
}
}
}

/// <summary>
/// Convert all elements in the <paramref name="source"/> to their conjugates.
/// </summary>
Expand Down

0 comments on commit a403eb4

Please sign in to comment.