complex_num v1.0.0 ComplexNum.Cartesian
A simple Complex Number in the form of a + b*i
.
a
and b
are allowed to be any type that implements the Numeric
behaviour.
This means Integer and Float, as well as custom-built data types like Decimal, Ratio, ???.
Do note that certain kinds of operations (especially the conversion of Cartesian <-> Polar) require the calculation of square roots.
Computers are not able to calculate any square root with infinite precision in finite time.
This is exactly the reason that e.g. Decimal and Ratio do not support sqrt
.
Therefore, the only way to manage this, is to explicitly convert a (high- or infinite-precision) data type that does not support square roots
to a data type that does support it (like Floats), in which case precision will be lost.
Summary
Functions
The absolute value of a Cartesian Complex Number is a real part containing the magnitude of the number, and an imaginary part of 0
Adds two numbers together
Divides the rhs by the lhs
Calculates the magnitude of the Cartesian Complex Number. As this is done using Pythagoras, i.e. c = sqrt(aa + bb), this is a lossy operation where (aa+bb) is converted to a float
Returns the square of the magnitude of the Cartesian Complex Number. Because it is not necessary to calculate a square root, this is a precise operation
Unary minus. Should return the negation of the number
Multiplies the two numbers together
Creates a new Cartesian Complex Number
Power function, x^n
This i the same as 1 / ca
Subtracts the rhs number from the lhs number
Functions
The absolute value of a Cartesian Complex Number is a real part containing the magnitude of the number, and an imaginary part of 0.
This is a lossy operation, as calculating the magnitude of a Cartesian Complex number is a lossy operation.
Adds two numbers together.
Callback implementation for Numeric.add/2
.
Divides the rhs by the lhs.
To be clear, this division operation is supposed to keep precision.
Callback implementation for Numeric.div/2
.
Calculates the magnitude of the Cartesian Complex Number. As this is done using Pythagoras, i.e. c = sqrt(aa + bb), this is a lossy operation where (aa+bb) is converted to a float.
Returns the square of the magnitude of the Cartesian Complex Number. Because it is not necessary to calculate a square root, this is a precise operation.
Unary minus. Should return the negation of the number.
Callback implementation for Numeric.minus/1
.
Multiplies the two numbers together.
Callback implementation for Numeric.mult/2
.
Creates a new Cartesian Complex Number.
real
and imaginary
can be Integer, Float or any custom struct that implements the Numeric behaviour. (defined by The Numbers package)
If a custom Numeric type is used, the other argument is converted to that type automatically.
Power function, x^n.
When this optional function is not provided, Number
will use the ‘Exponentiation by Squaring’
algorithm to calculate the result (which uses log(n) repeated multiplications).
Add it to your data type if it is possible to compute a power using a faster algorithm.
Callback implementation for Numeric.pow/2
.
Subtracts the rhs number from the lhs number.
Callback implementation for Numeric.sub/2
.