Source
Edit
This module implements complex numbers and basic mathematical operations on them.
Complex numbers are currently generic over 64-bit or 32-bit floats.
Example:
import std / complex
from std / math import almostEqual , sqrt
let
z1 = complex ( 1.0 , 2.0 )
z2 = complex ( 3.0 , - 4.0 )
assert almostEqual ( z1 + z2 , complex ( 4.0 , - 2.0 ) )
assert almostEqual ( z1 - z2 , complex ( - 2.0 , 6.0 ) )
assert almostEqual ( z1 * z2 , complex ( 11.0 , 2.0 ) )
assert almostEqual ( z1 / z2 , complex ( - 0.2 , 0.4 ) )
assert almostEqual ( abs ( z1 ) , sqrt ( 5.0 ) )
assert almostEqual ( conjugate ( z1 ) , complex ( 1.0 , - 2.0 ) )
let ( r , phi ) = z1 . polar
assert almostEqual ( rect ( r , phi ) , z1 )
A complex number, consisting of a real and an imaginary part.
Source
Edit
Alias for a complex number using 32-bit floats.
Source
Edit
Alias for a complex number using 64-bit floats.
Source
Edit
Returns z 's string representation as "(re, im)" .
Example:
doAssert $ complex ( 1.0 , 2.0 ) == "(1.0, 2.0)"
Source
Edit
Multiplies a complex number with a real number.
Source
Edit
Multiplies a real number with a complex number.
Source
Edit
Adds a complex number to a real number.
Source
Edit
Adds a real number to a complex number.
Source
Edit
Subtracts a real number from a complex number.
Source
Edit
Subtracts a complex number from a real number.
Source
Edit
Divides a complex number by a real number.
Source
Edit
Divides a real number by a complex number.
Source
Edit
Compares two complex numbers for equality.
Source
Edit
Returns the absolute value of z , that is the distance from (0, 0) to z .
Source
Edit
Returns the squared absolute value of z , that is the squared distance from (0, 0) to z . This is more efficient than abs ( z ) ^ 2 .
Source
Edit
Checks if two complex values are almost equal, using the machine epsilon .
Two complex values are considered almost equal if their real and imaginary components are almost equal.
unitsInLastPlace is the max number of units in the last place difference tolerated when comparing two numbers. The larger the value, the more error is allowed. A 0 value means that two numbers must be exactly the same to be considered equal.
The machine epsilon has to be scaled to the magnitude of the values used and multiplied by the desired precision in ULPs unless the difference is subnormal.
Source
Edit
Returns the inverse hyperbolic cosine of z .
Source
Edit
Returns the inverse hyperbolic cotangent of z .
Source
Edit
Returns the inverse hyperbolic cosecant of z .
Source
Edit
Returns the inverse hyperbolic secant of z .
Source
Edit
Returns the inverse hyperbolic sine of z .
Source
Edit
Returns the inverse hyperbolic tangent of z .
Source
Edit
Returns a Complex [ T ] with real part re and imaginary part im .
Source
Edit
Returns a Complex32 with real part re and imaginary part im .
Source
Edit
Returns a Complex64 with real part re and imaginary part im .
Source
Edit
Returns the complex conjugate of z (complex ( z . re , - z . im ) ).
Source
Edit
Returns the hyperbolic cotangent of z .
Source
Edit
Computes the exponential function (e ^ z ).
Source
Edit
Returns the multiplicative inverse of z (1 / z ).
Source
Edit
Returns the logarithm base 2 of z .
See also:
Source
Edit
Returns the logarithm base 10 of z .
See also:
Source
Edit
Returns the phase (or argument) of z , that is the angle in polar representation.result = arctan2 ( z . im , z . re )
Source
Edit
Returns z in polar coordinates.result . r = abs ( z ) result . phi = phase ( z )
See also:
Source
Edit
The complex number x raised to the power of the real number y .
Source
Edit
Returns the complex number with polar coordinates r and phi .result . re = r * cos ( phi ) result . im = r * sin ( phi )
See also:
Source
Edit
Returns the phase of z as a unit complex number, or 0 if z is 0.
Source
Edit
Returns arg as an imaginary number (complex32 ( 0 , arg ) ).
Source
Edit
Returns arg as an imaginary number (complex64 ( 0 , arg ) ).
Source
Edit
Returns the imaginary unit (complex32 ( 0 , 1 ) ).
Source
Edit
Returns the imaginary unit (complex64 ( 0 , 1 ) ).
Source
Edit