MCPcopy Create free account
hub / github.com/OriginQ/QPanda-2 / bind_data

Function bind_data

QAlg/ArithmeticUnit/ArithmeticUnit.cpp:381–412  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

379}
380
381QCircuit bind_data(int value, QVec& qvec)
382{
383 bool sign_flag = value < 0 ? true,value=-value : false;
384 size_t qnum = std::floor(std::log(value) / std::log(2)+1);
385 if (qvec.size() < qnum+1)
386 {
387 QCERR_AND_THROW_ERRSTR(
388 run_fail,
389 "Qubit register is not big enough to store data!");
390 }
391
392 QCircuit circuit;
393 int cnt = 0;
394 while (value)
395 {
396 auto v = value % 2;
397 if (v == 1)
398 {
399 circuit << X(qvec[cnt]);
400 }
401
402 value = value / 2;
403 cnt++;
404 }
405
406 if (sign_flag)
407 {
408 circuit << X(qvec[qvec.size() - 1]);
409 }
410
411 return circuit;
412}
413
414QCircuit bind_nonnegative_data(size_t value, QVec& qvec)
415{

Callers 15

test_bind_dataFunction · 0.50
test_QAdderFunction · 0.50
test_QAdderWithCarryFunction · 0.50
test_QAddFunction · 0.50
test_QComplementFunction · 0.50
test_QSubFunction · 0.50
test_QMultiplierFunction · 0.50
test_QMulFunction · 0.50
test_QDividerFunction · 0.50
test_QDivFunction · 0.50
test_QDivWithAccuracyFunction · 0.50

Calls 4

XClass · 0.85
floorFunction · 0.50
logFunction · 0.50
sizeMethod · 0.45

Tested by 14

test_bind_dataFunction · 0.40
test_QAdderFunction · 0.40
test_QAdderWithCarryFunction · 0.40
test_QAddFunction · 0.40
test_QComplementFunction · 0.40
test_QSubFunction · 0.40
test_QMultiplierFunction · 0.40
test_QMulFunction · 0.40
test_QDividerFunction · 0.40
test_QDivFunction · 0.40
test_QDivWithAccuracyFunction · 0.40