Arithmetic/Complex: Difference between revisions

Content deleted Content added
Franck (talk | contribs)
Blek (talk | contribs)
Line 3,497:
</lang>
=={{header|PowerShell}}==
===Implementation===
{{works with|PowerShell|5}}
<lang PowerShell>
class Complex {
Line 3,519:
[Complex]inverse() {return $this.conjugate().mul(1/$this.abs2())}
[String]show() {
if(0 -lege $this.y) {
return "$($this.x)+$($this.y)i"
} else {
Line 3,525:
}
}
static [String]show([Complex]$other) {return $other.show()}
return $other.show()
}
}
$m = [complex]::new(3, 4)
Line 3,536 ⟶ 3,538:
"1/`$m: $([complex]::show($m.inverse()))"
"conjugate `$m: $([complex]::show($m.conjugate()))"
</lang>
<b>Output:</b>
<pre>
$m: 3+4i
$n: 7+6i
$m + $n: 10+10i
$m * $n: -3+46i
negate $m: -3-4i
1/$m: 0.12-0.16i
conjugate $m: 3-4i
</pre>
=={{works withheader|PowerShell|5}}==
===Library===
function show([System.Numerics.Complex]$c) {
if(0 -ge $c.Imginary) {
return "$($c.Real)+$($c.Imaginary)i"
} else {
return "$($c.Real)$($c.Imaginary)i"
}
}
$m = [System.Numerics.Complex]::new(3, 4)
$n = [System.Numerics.Complex]::new(7, 6)
"`$m: $(show $m)"
"`$n: $(show $n)"
"`$m + `$n: $(show ([System.Numerics.Complex]::Add($m,$n)))"
"`$m * `$n: $(show ([System.Numerics.Complex]::Multiply($m,$n)))"
"negate `$m: $(show ([System.Numerics.Complex]::negate($m)))"
"1/`$m: $(show ([System.Numerics.Complex]::Reciprocal($m)))"
"conjugate `$m: $(show ([System.Numerics.Complex]::Conjugate($m)))"
</lang>
<b>Output:</b>