microsoft/qdk

Public

mirrored from https://github.com/microsoft/qdkAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
v1.19.0

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

source/pip/tests-integration/resources/adaptive_ri/input/ArithmeticOps.qs

34lines · modecode

1namespace Test {
2
3 import Std.Intrinsic.*;
4 import Std.Measurement.*;
5
6 // Demonstrates use of arithmetic operations on integers at runtime.
7 // Expected output: (5, 25, 0, 243)
8 @EntryPoint()
9 operation Main() : (Int, Int, Int, Int) {
10 mutable count = 0;
11 mutable countPos = 0;
12 mutable countNeg = 10;
13 mutable countMul = 1;
14 use qs = Qubit[5];
15 for q in qs {
16 X(q);
17 }
18 for r in MeasureEachZ(qs) {
19 if r == One {
20 // Note that addition of a 1 will get optimized into a zext on the bool.
21 set count += 1;
22
23 set countPos += 5;
24
25 // Note that subtraction of 2 turns into add of -2... problem for providers without negative numbers?
26 set countNeg -= 2;
27
28 set countMul *= 3;
29 }
30 }
31 ResetAll(qs);
32 return (count, countPos, countNeg, countMul);
33 }
34}
35