Added complex conjugate
This commit is contained in:
parent
a295866ce8
commit
defbd10c19
1 changed files with 32 additions and 26 deletions
|
|
@ -171,6 +171,12 @@ proc abs*(z: Complex): float =
|
|||
result = y * sqrt(1.0 + temp * temp)
|
||||
|
||||
|
||||
proc conjugate*(z: Complex): Complex =
|
||||
## Conjugate of complex number `z`.
|
||||
result.re = z.re
|
||||
result.im = -z.im
|
||||
|
||||
|
||||
proc sqrt*(z: Complex): Complex =
|
||||
## Square root for a complex number `z`.
|
||||
var x, y, w, r: float
|
||||
|
|
@ -315,6 +321,7 @@ when isMainModule:
|
|||
assert( oo+(-1.0) == i )
|
||||
assert( (-1.0)+oo == i )
|
||||
assert( abs(oo) == sqrt(2.0) )
|
||||
assert( conjugate(a) == (1.0, -2.0) )
|
||||
assert( sqrt(m1) == i )
|
||||
assert( exp(ipi) =~ m1 )
|
||||
|
||||
|
|
@ -340,4 +347,3 @@ when isMainModule:
|
|||
assert( cosh(a) =~ (-0.642148124715520, 1.068607421382778) )
|
||||
assert( sinh(a) =~ (-0.489056259041294, 1.403119250622040) )
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue