Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

std.math.complex: Added a missing complex function. #21998

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

chrboesch
Copy link
Contributor

A required function in signal processing which, if you don't know exactly what it does, is reproduced as it is in the test. This then leads to inaccuracies, which is not necessary or should not be the case.

@chrboesch chrboesch changed the title Added a missing complex function. std.math.complex: Added a missing complex function. Nov 16, 2024
@@ -115,6 +115,11 @@ pub fn Complex(comptime T: type) type {
pub fn magnitude(self: Self) T {
return @sqrt(self.re * self.re + self.im * self.im);
}

/// Returns the quared magnitude of a complex number.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A typo: quared should be squared

@Atomk
Copy link
Contributor

Atomk commented Nov 16, 2024

sqrtmag sounds like "square root of magnitude". I suggest to rename the function to sqrmag (remove the t), for reference in Unity it's called sqrMagnitude

@smups
Copy link

smups commented Nov 18, 2024

@Atomk from wikipedia:

(...) This allows to define the absolute value (or modulus or magnitude) of z to be the square root

$$ |z|=\sqrt{x^2+y^2} $$

It incorrect usage of terminology (and therefore confusing) to call the magnitude the square root of the magnitude. Unity is just wrong. c++'s std::complex has the correct definition.

@chrboesch
Copy link
Contributor Author

It incorrect usage of terminology (and therefore confusing) to call the magnitude the square root of the magnitude.

You're right. This is the magnitude of a complex number: $$|z| = \sqrt{a^2 + b^2}$$

And to get rid of the root you square it. That is called "magnitude squared": $|z|^2 = a^2 + b^2$.

See University of Houston (https://www.math.uh.edu/~dblecher/4389complex_numbers.pdf)
That is exactly what this function does. You square the magnitude. That's why 'sqrmag' fits well for this function, in my view.

@daurnimator
Copy link
Contributor

daurnimator commented Nov 20, 2024

You square the magnitude. That's why 'sqrmag' fits well for this function, in my view.

  • Square is often shortened to sq
  • Following on from the above, SQuare-Root is often shortened to sqr (e.g. in VBA) or sqrt (e.g. in python
  • sqrmag to me reads as "SQuare-Root Magnitude"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants