Is there a way to do this more efficiently?
Code:
inline void Clip( double &x, double a, double b ) // makes sure x is between a and b
{
 if (x<a) x = a;
 else if (x>b) x = b;
}
Note that this involves lotsa fnstsw and conditional jumps, which suck.

I personally (msvc8@core2duo) gain almost 50% speed increase if I do this:
Code:
inline void Clip( double &x, double a, double b ) // makes sure x is between a and b
{
 x = b-x;
 x = (x+fabs(x))*0.5; // this essentially does "if (x<0) x=0;"
 x = b-x-a;
 x = (x+fabs(x))*0.5;
 x += a;
}
No status word crap, and no checks anymore.

Any other tricks to make this faster?