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

Add angle function for stdlib_math: Return the angle of the complex argument. #489

Closed
zoziha opened this issue Aug 19, 2021 · 6 comments · Fixed by #498
Closed

Add angle function for stdlib_math: Return the angle of the complex argument. #489

zoziha opened this issue Aug 19, 2021 · 6 comments · Fixed by #498
Labels
idea Proposition of an idea and opening an issue to discuss it topic: mathematics linear algebra, sparse matrices, special functions, FFT, random numbers, statistics, ...

Comments

@zoziha
Copy link
Contributor

zoziha commented Aug 19, 2021

Description

angle computes the phase angle of complex scalar in the interval [-π,π]. The angles in theta are such that z = abs(z)*exp((0.0, theta)).

theta = [[stdlib_math(module):angle(interface) (z)  !! z: `complex` type

Inspired by forlab/angle(MIT license), has been implemented in this branch (add_angle and add_arg) (PR will be made later.)

Prior Art

  1. forlab/angle
  2. matlab/angle
  3. numpy/angle
@zoziha zoziha added the idea Proposition of an idea and opening an issue to discuss it label Aug 19, 2021
@arjenmarkus
Copy link
Member

arjenmarkus commented Aug 19, 2021 via email

@nshaffer
Copy link
Contributor

Linking a related issue on math utility functions where this was mentioned: #150

There I suggested the name "phase", but "angle" is OK too. Arjen's suggestion of "arg" works as well if we are not concerned about that name clashing with general programming usage.

Many compilers include trigonometric functions that work with degrees instead of radians, usually named "sind", "atand", etc. These are extensions, but they on the workplan for the next standard (202x), in addition to "pi" trig functions that work with angles in radians in multiples of pi. Let's keep that in mind, so that when these are standardized, we can consider "argd" and "argpi" functions as well. That is, I suggest we not follow numpy's example with the optional "deg" argument.

I do not have the time to implement this right now, but I would be happy to review it when a PR is ready.

@milancurcic
Copy link
Member

milancurcic commented Aug 19, 2021

I don't work with complex numbers often, though this seems useful. I like phase, angle, and arg about equally.

@arjenmarkus
Copy link
Member

arjenmarkus commented Aug 20, 2021 via email

@zoziha

This comment has been minimized.

@zoziha
Copy link
Contributor Author

zoziha commented Aug 26, 2021

Hello, I implemented the arg/argd/argpi functions under this branch : add_arg, referring to the Fortran202X feature.
image
(see 19-203r1.txt and 19-204r1.txt)

I have introduced three precision PI constants in stdlib_math (see PI constant definition). I don't know if it is appropriate to write this way.

#:for k1 in REAL_KINDS
    real(kind=${k1}$), parameter :: PI_${k1}$ = 4.0_${k1}$*atan(1.0_${k1}$)
#:endfor

If there are no major problems, I will submit a PR later.

@awvwgk awvwgk added the topic: mathematics linear algebra, sparse matrices, special functions, FFT, random numbers, statistics, ... label Sep 18, 2021
@zoziha zoziha linked a pull request Sep 21, 2021 that will close this issue
2 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
idea Proposition of an idea and opening an issue to discuss it topic: mathematics linear algebra, sparse matrices, special functions, FFT, random numbers, statistics, ...
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants