microsoft/qdk
Publicmirrored fromhttps://github.com/microsoft/qdkAvailable
katas/content/complex_arithmetic/complex_division/Solution.qs
12lines · modecode
| 1 | namespace Kata { |
| 2 | open Microsoft.Quantum.Math; |
| 3 | |
| 4 | function ComplexDiv(x : Complex, y: Complex) : Complex { |
| 5 | let (a, b) = x!; |
| 6 | let (c, d) = y!; |
| 7 | let denominator = c * c + d * d; |
| 8 | let real = (a * c + b * d) / denominator; |
| 9 | let imag = (- a * d + b * c) / denominator; |
| 10 | return Complex(real, imag); |
| 11 | } |
| 12 | } |