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