microsoft/qdk
Publicmirrored fromhttps://github.com/microsoft/qdkAvailable
library/fixed_point/src/Measurement.qs
22lines · modecode
| 1 | // Copyright (c) Microsoft Corporation. All rights reserved. |
| 2 | // Licensed under the MIT License. |
| 3 | |
| 4 | import Types.FixedPoint; |
| 5 | import Convert.BoolArrayAsFixedPoint; |
| 6 | import Std.Arrays.ForEach; |
| 7 | import Std.Convert.ResultArrayAsBoolArray; |
| 8 | |
| 9 | |
| 10 | /// # Summary |
| 11 | /// Measure a fixed-point number, returns its value as Double, and resets |
| 12 | /// all the register to zero. |
| 13 | /// |
| 14 | /// # Input |
| 15 | /// ## fp |
| 16 | /// Fixed-point number to measure. |
| 17 | @Config(FloatingPointComputations) |
| 18 | operation MeasureFxP(fp : FixedPoint) : Double { |
| 19 | let measurements = MResetEachZ(fp::Register); |
| 20 | let bits = ResultArrayAsBoolArray(measurements); |
| 21 | return BoolArrayAsFixedPoint(fp::IntegerBits, bits); |
| 22 | } |
| 23 | |