builtins.complex and its operators/methods.
Use toNimComplex and pycomplex to convert between PyComplex and Complex
Example:
import src/pylib/builtins/complex assert complex(1, 3) == complex("1.0+3.0J") # complex only stores floats, not int, # just as Python's assert not (type(complex(1, 2).real) is int)
Types
PyComplex = PyTComplex[float]
- Source Edit
PyTComplex[T] = distinct Complex[T]
- generics version of PyComplex Source Edit
Procs
func `$`(z: PyTComplex): string
- Source Edit
func `**=`[T](self: var PyTComplex[T]; x: ComplexPowSecondParamType[T])
- Source Edit
func abs[T](z: PyTComplex[T]): T
- builtins.abs for complex Source Edit
func complex[T: SomeFloat](real: T = 0.0; imag: T = 0.0): PyTComplex[T]
- Source Edit
func conjugate[T](z: PyTComplex[T]): PyTComplex[T]
- complex.conjugate() Source Edit
func repr(z: PyTComplex): string
-
Returns bj/(a+bj)/(a-bj) for complex(a, b)
Example:
assert repr(complex(0.0, 3.0)) == "3j" # not "(0+3j)", as in Python assert repr(complex(-0.0, 3.0)) == "(-0+3j)" # not "3j", as in Python assert repr(complex(1.0, 2.0)) == "(1+2j)" # '.0' is removed as Python's
Source Edit
Templates
template `*`(a, b: PyTComplex): PyTComplex
- Source Edit
template `*`[I: SomeInteger; T](a: I; z: PyTComplex[T]): PyTComplex[T]
- Source Edit
template `*`[I: SomeInteger; T](z: PyTComplex[T]; a: I): PyTComplex[T]
- Source Edit
template `*`[T: SomeFloat](a: T; z: PyTComplex[T]): PyTComplex[T]
- Source Edit
template `*`[T: SomeFloat](z: PyTComplex[T]; a: T): PyTComplex[T]
- Source Edit
template `**`[T](self: PyTComplex[T]; x: ComplexPowSecondParamType[T]): PyTComplex[ T]
- Source Edit
template `**`[T](self: PyTComplex[T]; x: int): PyTComplex[T]
- Source Edit
template `**`[T](self: PyTComplex[T]; x: PyComplex): PyTComplex[T]
- Source Edit
template `*=`(a, b: PyTComplex): untyped
- Source Edit
template `+`(a, b: PyTComplex): PyTComplex
- Source Edit
template `+`[I: SomeInteger; T](a: I; z: PyTComplex[T]): PyTComplex[T]
- Source Edit
template `+`[I: SomeInteger; T](z: PyTComplex[T]; a: I): PyTComplex[T]
- Source Edit
template `+`[T: SomeFloat](a: T; z: PyTComplex[T]): PyTComplex[T]
- Source Edit
template `+`[T: SomeFloat](z: PyTComplex[T]; a: T): PyTComplex[T]
- Source Edit
template `+=`(a, b: PyTComplex): untyped
- Source Edit
template `-`(a, b: PyTComplex): PyTComplex
- Source Edit
template `-`[I: SomeInteger; T](a: I; z: PyTComplex[T]): PyTComplex[T]
- Source Edit
template `-`[I: SomeInteger; T](z: PyTComplex[T]; a: I): PyTComplex[T]
- Source Edit
template `-`[T: SomeFloat](a: T; z: PyTComplex[T]): PyTComplex[T]
- Source Edit
template `-`[T: SomeFloat](z: PyTComplex[T]; a: T): PyTComplex[T]
- Source Edit
template `-=`(a, b: PyTComplex): untyped
- Source Edit
template `/`(a, b: PyTComplex): PyTComplex
- Source Edit
template `/`[I: SomeInteger; T](a: I; z: PyTComplex[T]): PyTComplex[T]
- Source Edit
template `/`[I: SomeInteger; T](z: PyTComplex[T]; a: I): PyTComplex[T]
- Source Edit
template `/`[T: SomeFloat](a: T; z: PyTComplex[T]): PyTComplex[T]
- Source Edit
template `/`[T: SomeFloat](z: PyTComplex[T]; a: T): PyTComplex[T]
- Source Edit
template `/=`(a, b: PyTComplex): untyped
- Source Edit
template `==`(a, b: PyTComplex): untyped
- Source Edit
template imag[T](z: PyTComplex[T]): T
- Source Edit
template imag=[T](z: PyTComplex[T]; _: T) {. error: "AttributeError: readonly attribute".}
- Source Edit
template pow[T](self: PyTComplex[T]; x: ComplexPowSecondParamType[T]; _: NoneType): PyTComplex[T]
- Source Edit
template pow[T](self: PyTComplex[T]; x: int): PyTComplex[T]
- Source Edit
template pow[T](self: PyTComplex[T]; x: PyTComplex[T]): PyTComplex[T]
- Source Edit
template pow[T](self: PyTComplex[T]; x: static Natural): PyTComplex[T]
- Source Edit
template pow[T](self: PyTComplex[T]; x: T): PyTComplex[T]
- Source Edit
template pycomplex[T](re: T; im = T(0)): PyTComplex[T]
- alias of complex. Useful when import both std/complex and pylib Source Edit
template pycomplex[T](z: Complex[T]): PyTComplex[T]
- Convert Nim's Complex in std/complex to PyTComplex Source Edit
template real[T](z: PyTComplex[T]): T
- Source Edit
template real=[T](z: PyTComplex[T]; _: T) {. error: "AttributeError: readonly attribute".}
- Source Edit
template toNimComplex[T](z: PyTComplex[T]): Complex[T]
- Source Edit