float clamp(float invalue)
{
static const float epsilon_ = 0.0001f; // Ideally share this globally and use it instead of magic numbers
if(abs(invalue) < epsilon_)
return 0.0f;
return invalue;
}
But that is NOT smart. You should never do equality checks on floating point numbers, so using an epsilon comparison is the right thing to do anyways... and I already posted the code for that above.
floats are not precision data types, what about double or int ?
Never say Never, Because Never comes too soon. - ryan20fun
Disclaimer: Each post of mine is intended as an attempt of helping and/or bringing some meaningfull insight to the topic at hand. Due to my nature, my good intentions will not always be plainly visible. I apologise in advance and assure you I mean no harm and do not intend to insult anyone.