Note: i - U + {0 | -1 | 1} could be a negative number. In C++ the result of x%y is implementation-defined for negative values of x. You should make sure that your program gives back values that match your expectations.
1 2 3 4 5 6 7 8 9
void move(std::vector<double> &q, const std::vector<double> &p, int U){
q.clear();
for (size_t i = 0; i < p.size(); i++){
double s = pExact * p[(i - U) % p.size()];
s += pOvershoot * p[(i - U - 1) % p.size()];
s += pUndeshoot * p[(i - U + 1) % p.size()];
q.push_back(s);
}
}
> In C++ the result of x%y is implementation-defined for negative values of x.
In C++ the result of x%y used to be implementation-defined for negative values of x.
Now, the IS mandates that the result must have the same sign as the dividend.
if the quotient a/b is representable in the type of the result, (a/b)*b + a%b is equal to a.
@helios,
thank you so much for this code. However, I'm still not getting the expected results. I've altered the function to return a vector instead of passing a vector that holds the result.