When a public function accepts a float value, and this value is to be kept within a specific range, I usually do:
void setParameter(float p)
{
if (p < 0) p = 0;
if (p > 1.f) p = 1.f;
// ...do something with 'p'
}
Is there a better, faster, more elegant way to keep a float value in range?