Implement complex sgn (#20087)
Co-authored-by: Clay Sweetser <Varriount@users.noreply.github.com>
This commit is contained in:
parent
04642335c1
commit
cc81866da1
1 changed files with 7 additions and 0 deletions
|
|
@ -82,6 +82,13 @@ func abs2*[T](z: Complex[T]): T =
|
||||||
## This is more efficient than `abs(z) ^ 2`.
|
## This is more efficient than `abs(z) ^ 2`.
|
||||||
result = z.re * z.re + z.im * z.im
|
result = z.re * z.re + z.im * z.im
|
||||||
|
|
||||||
|
func sgn*[T](z: Complex[T]): Complex[T] =
|
||||||
|
## Returns the phase of `z` as a unit complex number,
|
||||||
|
## or 0 if `z` is 0.
|
||||||
|
let a = abs(z)
|
||||||
|
if a != 0:
|
||||||
|
result = z / a
|
||||||
|
|
||||||
func conjugate*[T](z: Complex[T]): Complex[T] =
|
func conjugate*[T](z: Complex[T]): Complex[T] =
|
||||||
## Returns the complex conjugate of `z` (`complex(z.re, -z.im)`).
|
## Returns the complex conjugate of `z` (`complex(z.re, -z.im)`).
|
||||||
result.re = z.re
|
result.re = z.re
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue