..but if you do that, make sure you don't do something like this:
Code: Select all
// just something
static inline internalClip(double x)
{
return (0.5*x)*(3 - x*x);
}
// this will almost certainly perform badly
double badBranchClip(double x)
{
if(x > 1) x = 1;
if(x < -1) x = -1;
return internalClip(x);
}
Code: Select all
// this is likely to perform better, especially
// if you'd do more math with the unclipped x
double betterClip(double x)
{
if(x > 1) return internalClip(1);
if(x < -1) return internalClip(-1);
return internalClip(x);
}
I'm not sure how large the difference is on modern CPUs, but a couple of years back it was pretty obvious.