Skip to content

Commit

Permalink
Make Parser CI less sensitive to roundoff errors (#4321)
Browse files Browse the repository at this point in the history
Replace `1-cos(x)` with `2*sin(x/2)**2` to reduce roundoff errors for
small x's.
  • Loading branch information
WeiqunZhang authored Feb 25, 2025
1 parent f3e4bec commit 06b4a5b
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions Tests/Parser/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -318,14 +318,14 @@ int main (int argc, char* argv[])
{-149.e-6}, {1.e-6}, 1000,
1.e-12, 1.e-15);

nerror += test1("if(z<lramp, 0.5*(1-cos(pi*z/lramp))*dens, dens)",
nerror += test1("if(z<lramp, sin(pi/2*z/lramp)**2*dens, dens)",
{{"lramp",8.e-3},{"pi",3.14},{"dens",1.e23}},
{"z"},
[=] (Real z) -> Real {
Real lramp=8.e-3, pi=3.14, dens=1.e23;
if (z < lramp) {
//return 0.5*(1-std::cos(pi*z/lramp))*dens;
return 0.5*dens-0.5*dens*std::cos(pi*z/lramp);
auto x = std::sin(pi/2*z/lramp);
return x*x*dens;
} else {
return dens;
}
Expand Down

0 comments on commit 06b4a5b

Please sign in to comment.