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

Function bind_nonnegative_data

Extensions/QAlg/ArithmeticUnit/ArithmeticUnit.cpp:414–440  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

412}
413
414QCircuit bind_nonnegative_data(size_t value, QVec& qvec)
415{
416 if (value == 0) return QCircuit();
417 size_t qnum = std::floor(std::log(value) / std::log(2) + 1);
418 if (qvec.size() < qnum)
419 {
420 QCERR_AND_THROW_ERRSTR(
421 run_fail,
422 "Qubit register is not big enough to store data!");
423 }
424
425 QCircuit circuit;
426 int cnt = 0;
427 while (value)
428 {
429 auto v = value % 2;
430 if (v == 1)
431 {
432 circuit << X(qvec[cnt]);
433 }
434
435 value = value / 2;
436 cnt++;
437 }
438
439 return circuit;
440}
441
442QCircuit constModAdd(QVec &qvec, int base, int module_Num, QVec &qvec1, QVec &qvec2)
443{

Callers 1

constModAddFunction · 0.70

Calls 5

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

Tested by

no test coverage detected