microsoft/qdk
Publicmirrored fromhttps://github.com/microsoft/qdkAvailable
katas/content/complex_arithmetic/polar_multiplication/Solution.qs
16lines · modecode
| 1 | namespace Kata { |
| 2 | open Microsoft.Quantum.Math; |
| 3 | |
| 4 | function ComplexPolarMult(x : ComplexPolar, y: ComplexPolar) : ComplexPolar { |
| 5 | let (r1, theta1) = x!; |
| 6 | let (r2, theta2) = y!; |
| 7 | mutable theta3 = theta1 + theta2; |
| 8 | if theta3 > PI() { |
| 9 | set theta3 -= 2.0 * PI(); |
| 10 | } |
| 11 | if theta3 < -PI() { |
| 12 | set theta3 += 2.0 * PI(); |
| 13 | } |
| 14 | return ComplexPolar(r1 * r2, theta3); |
| 15 | } |
| 16 | } |
| 17 | |