diff --git a/quest/src/cpu/cpu_subroutines.cpp b/quest/src/cpu/cpu_subroutines.cpp index 59df946e9..61ad96f4c 100644 --- a/quest/src/cpu/cpu_subroutines.cpp +++ b/quest/src/cpu/cpu_subroutines.cpp @@ -41,6 +41,7 @@ #include #include +#include using std::vector; @@ -607,7 +608,8 @@ void cpu_statevec_anyCtrlAnyTargDenseMatr_sub(Qureg qureg, ConstList64 ctrls, Co // i = nth local index where ctrls are active and targs form value k qindex i = setBits(i0, targs.data(), numTargBits, k); // loop may be unrolled - amps[i] = getCpuQcomp(0, 0); + cpu_qcomp sum = getCpuQcomp(0, 0); + cpu_qcomp compensation = getCpuQcomp(0, 0); // loop may be unrolled for (qindex j=0; j= std::abs(term.re)) + compensation.re += (sum.re - tRe) + term.re; + else + compensation.re += (term.re - tRe) + sum.re; + sum.re = tRe; + + qreal tIm = sum.im + term.im; + if (std::abs(sum.im) >= std::abs(term.im)) + compensation.im += (sum.im - tIm) + term.im; + else + compensation.im += (term.im - tIm) + sum.im; + sum.im = tIm; } + + amps[i] = sum + compensation; } } }