Skip to content

Complex Numbers for Elixir, wrapping not only floats but _any_ kind of numeric data type.

License

Notifications You must be signed in to change notification settings

Qqwy/elixir_complex_num

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

32 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ComplexNum

hex.pm version

ComplexNum allows you to work with Complex Numbers in Elixir.

Cartesian vs. Polar

There are two kinds of representaions for Complex Numbers:

  • Cartesian, of the form a + bi. (Storing the real and imaginary parts of the complex number)
  • Polar, of the form r * e^(i*phi). (storing the magnitude and the angle of 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

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

The package can be installed as:

  1. Add complex_num to your list of dependencies in mix.exs:
```elixir
def deps do
  [{:complex_num, "~> 1.0.0"}]
end
```
  1. Ensure complex_num is started before your application:
```elixir
def application do
  [applications: [:complex_num]]
end
```

Changelog

  • 1.1.0 Support for Numbers v5.0.0.
  • 1.0.0 Stable release.

About

Complex Numbers for Elixir, wrapping not only floats but _any_ kind of numeric data type.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •  

Languages