Qqwy/elixir_complex_num
{ "createdAt": "2016-12-13T12:16:40Z", "defaultBranch": "master", "description": "Complex Numbers for Elixir, wrapping not only floats but _any_ kind of numeric data type.", "fullName": "Qqwy/elixir_complex_num", "homepage": "https://hex.pm/packages/complex_num", "language": "Elixir", "name": "elixir_complex_num", "pushedAt": "2023-04-26T22:57:45Z", "stargazersCount": 11, "topics": [], "updatedAt": "2022-12-07T21:47:03Z", "url": "https://github.com/Qqwy/elixir_complex_num"}ComplexNum
Section titled “ComplexNum”ComplexNum allows you to work with Complex Numbers in Elixir.
Cartesian vs. Polar
Section titled “Cartesian vs. Polar”There are two kinds of representaions for Complex Numbers:
- Cartesian, of the form
a + bi. (Storing therealandimaginaryparts of the complex number) - Polar, of the form
r * e^(i*phi). (storing themagnitudeand theangleof the complex number)
Polar form is very useful to perform fast multiplications, division and integer powers with.
Also, it obviously allows for O(1) precise computation of the magnitude and the angle.
Cartesian form on the other hand, allows besides multiplication and division, precise addition and subtraction.
Also, it obviously allows for O(1) precise computation of the real and imaginary parts.
Conversions between these two representations is possible, but lossy: This involves trigonometry and square roots, which means that precision is lost. (CompexNum converts the internal data types to floats and back to perform these oprations.)
Internal data types
Section titled “Internal data types”ComplexNum uses the Numbers library,
which means that the real/imaginary (resp. magnitude/angle) can be of any
data type that implements Numbers’ Numeric behaviour. This means that
Integers, Floats, arbitrary precision decimals defined by the Decimals package,
rationals defined by the Ratio package, etc. can be used.
ComplexNum itself also follows the Numeric behaviour, which means that it can be used inside any container that uses Numbers. (Including inside ComplexNum itself, but who would do such a thing?)
Installation
Section titled “Installation”The package can be installed as:
- Add
complex_numto your list of dependencies inmix.exs:
```elixirdef deps do [{:complex_num, "~> 1.0.0"}]end```2. Ensure complex_num is started before your application:
```elixirdef application do [applications: [:complex_num]]end```Changelog
Section titled “Changelog”- 1.1.0 Support for Numbers v5.0.0.
- 1.0.0 Stable release.