microsoft/qdk
Publicmirrored fromhttps://github.com/microsoft/qdkAvailable
library/fixed_point/src/Comparison.qs
29lines · modecode
| 1 | // Copyright (c) Microsoft Corporation. All rights reserved. |
| 2 | // Licensed under the MIT License. |
| 3 | |
| 4 | import Types.FixedPoint; |
| 5 | import Facts.AssertFormatsAreIdenticalFxP; |
| 6 | import Signed.Comparison.CompareGTSI; |
| 7 | |
| 8 | /// # Summary |
| 9 | /// Compares two fixed-point numbers stored in quantum registers, and |
| 10 | /// controls a flip on the result. |
| 11 | /// |
| 12 | /// # Input |
| 13 | /// ## fp1 |
| 14 | /// First fixed-point number to be compared. |
| 15 | /// ## fp2 |
| 16 | /// Second fixed-point number to be compared. |
| 17 | /// ## result |
| 18 | /// Result of the comparison. Will be flipped if `fp1 > fp2`. |
| 19 | /// |
| 20 | /// # Remarks |
| 21 | /// The current implementation requires the two fixed-point numbers |
| 22 | /// to have the same point position and the same number of qubits. |
| 23 | operation CompareGreaterThanFxP(fp1 : FixedPoint, fp2 : FixedPoint, result : Qubit) : Unit is Adj + Ctl { |
| 24 | AssertFormatsAreIdenticalFxP([fp1, fp2]); |
| 25 | |
| 26 | CompareGTSI((fp1::Register), (fp2::Register), result); |
| 27 | } |
| 28 | |
| 29 | export CompareGreaterThanFxP; |