ziglang / zig

General-purpose programming language and toolchain for maintaining robust, optimal, and reusable software.
https://ziglang.org
MIT License
35.12k stars 2.56k forks source link

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

Open chrboesch opened 1 week ago

chrboesch commented 1 week ago

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.

Atomk commented 1 week ago

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 commented 1 week ago

@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 commented 1 week ago

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 commented 6 days ago

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