Skip to content
Snippets Groups Projects
Commit a49b41a7 authored by Wuttke, Joachim's avatar Wuttke, Joachim
Browse files

Extra precautions to prevent rounding error or excessive precision in

tack values.
parent 8d10a0e1
No related branches found
No related tags found
No related merge requests found
......@@ -362,10 +362,21 @@ void CAxis::calc_lintacks(vector<double>& Tacks, int& ntpt, double& dtack) const
dtack = .25 * pow(10., ir);
ntpt = 5;
}
// Sets tack vector, taking extra precaution to avoid rounding errors.
Tacks.clear();
for (double d = dtack * (floor(inf/dtack)-1); d <= dtack * (ceil(sup/dtack)+1); d += dtack)
double dlow = dtack * (floor(inf/dtack)-1);
double dhig = dtack * (ceil(sup/dtack)+1);
double drange = dhig-dlow;
int nTacks = drange/dtack + 1.5;
if (nTacks<2)
throw "BUG: calc_lintacks -> nTacks<2";
for (int i=0; i<nTacks; ++i) {
double d = (i*dhig + (nTacks-1-i)*dlow)/(nTacks-1);
if (std::abs(d)<1e-15*drange)
d = 0;
if (inf-1e-4*range <= d && d <= sup+1e-4*range)
Tacks.push_back(d);
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment